
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> arr) {
vector<int> answer;
vector<int> count;
for (int i = 0; i < arr.size(); ++i)
{
if (2 == arr[i])
{
count.push_back(i);
}
}
if (0 == count.size())
{
answer.push_back(-1);
}
else if (1 == count.size())
{
answer.push_back(2);
}
else // 2개 이상
{
sort(count.begin(), count.end());
for (int i = count[0]; i <= count[count.size()-1]; ++i)
{
answer.push_back(arr[i]);
}
}
return answer;
}