#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using i64 = int64_t; using i32 = int32_t; template void init_n(vector& v, size_t n, U x) { v = vector(n, x); } template void init_n(vector& v, size_t n) { init_n(v, n, T()); } template void read_n(vector& v, size_t n, size_t o = 0) { v = vector(n+o); for (size_t i=o; i> v[i]; } template void read_n(T a[], size_t n, size_t o = 0) { for (size_t i=o; i> a[i]; } template T gabs(const T& x) { return max(x, -x); } #define abs gabs string add(i32 k, string s) { if (k < 9) { for (i64 i = 0; i < 3; ++i) s.push_back(k + '1'); } else { for (i64 i = 0; i < 3; ++i) s.push_back(k - 9 + '1' + i); } return s; } bool valid(const string& s) { i32 cnt[9]; fill(begin(cnt), end(cnt), 0); for (char c : s) cnt[c - '1']++; for (i32 i = 0; i < 9; ++i) if (cnt[i] > 4) return false; return true; } string s; bool ok[9]; int main() { cin >> s; sort(begin(s), end(s)); for (i64 b = 0; b < 9; ++b) { string y = s; y.push_back(b + '1'); sort(begin(y), end(y)); if (!valid(y)) continue; for (i64 i = 0; i < 16; ++i) { string t = add(i, string()); for (i64 j = i; j < 16; ++j) { string u = add(j, t); for (i64 k = j; k < 16; ++k) { string v = add(k, u); for (i64 l = k; l < 16; ++l) { string w = add(l, v); for (i64 a = 0; a < 9; ++a) { string x = w; x.push_back(a + '1'); x.push_back(a + '1'); sort(begin(x), end(x)); if (valid(x) && x == y) ok[b] = true; } } } } } bool f = true; for (i64 i = 0; i < 7; ++i) { if (y[2 * i] != y[2 * i + 1]) f = false; } if (f) ok[b] = true; } for (i32 i = 0; i < 9; ++i) if (ok[i]) cout << char(i + '1') << '\n'; return 0; }