#include using namespace std; int main(){ vector org(9); for (int i=0; i<13; i++){ char x; cin >> x; org[x-'1']++; } auto inner_hantei_1 = [&]() -> bool { vector cop = org; for (int d=0; d<9; d++){ if (cop[d] < 0) return false; cop[d] %= 3; if (cop[d] > 0 && d >= 8){ return false; } cop[d+1] -= cop[d]; cop[d+2] -= cop[d]; cop[d] = 0; } return true; }; auto hantei_1 = [&]() -> bool { bool mode = 0; for (int d=0; d<9; d++){ if (org[d] >= 2){ org[d] -= 2; if (inner_hantei_1()) mode = 1; org[d] += 2; if (mode) break; } } return mode; }; auto hantei_2 = [&]() -> bool { int cnt = 0; for (int i=0; i<9; i++){ if (org[i] == 2){ cnt++; } } return cnt == 7; }; auto hantei = [&]() -> bool { return hantei_1() || hantei_2(); }; for (int st=0; st<9; st++){ if (org[st] == 4) continue; org[st]++; if (hantei()){ cout << st+1 << '\n'; } org[st]--; } }