#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; using ld = long double; int main(){ cin.tie(0); ios::sync_with_stdio(0); string s; cin >> s; vector cnt(10, 0); for(char c : s) cnt[c - '0']++; auto f = [](vector cnt) { // 1 for(int A = 1; A <= 9; A++) { if(cnt[A] >= 2) { vector a = cnt; a[A] -= 2; int k = 0; for(int B : {1, 9, 2, 8, 3, 7, 4, 6, 5}) { if(a[B] >= 3) a[B] -= 3, k++; if(a[B] > 0) { if(a[B + 1] >= a[B] && a[B + 2] >= a[B]) { a[B + 1] -= a[B]; a[B + 2] -= a[B]; k += a[B]; a[B] = 0; } else if(a[B - 2] >= a[B] && a[B - 1] >= a[B]) { a[B - 2] -= a[B]; a[B - 1] -= a[B]; k += a[B]; a[B] = 0; } else break; } } if(k == 4) return true; } } // 2 int k = 0; for(int i = 1; i <= 9; i++) if(cnt[i] == 2) k++; if(k == 7) return true; return false; }; for(int x = 1; x <= 9; x++) { if(cnt[x] < 4) { cnt[x]++; if(f(cnt)) cout << x << "\n"; cnt[x]--; } } }