#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// int main() { string S; cin >> S; vector cnt(10); for (char c : S) ++cnt[c - '0']; FOR(t, 1, 10) { if (cnt[t] == 4) continue; ++cnt[t]; bool ok = false; { bool cur = true; REP(i, 10) cur &= cnt[i] == 0 || cnt[i] == 2; ok |= cur; } auto dfs = [&](auto self, int c) -> bool { if (c == 5) return true; if (c == 0) { FOR(i, 1, 10) { if (cnt[i] < 2) continue; cnt[i] -= 2; if (self(self, c + 1)) return true; cnt[i] += 2; } return false; } FOR(i, 1, 10) { if (cnt[i] >= 3) { cnt[i] -= 3; if (self(self, c + 1)) return true; cnt[i] += 3; } if (i + 2 < 10) { bool ng = false; REP(j, 3) if (--cnt[i + j] < 0) ng = true; if (!ng && self(self, c + 1)) return true; REP(j, 3) ++cnt[i + j]; } } return false; }; auto sv = cnt; ok |= dfs(dfs, 0); cnt = sv; if (ok) printf("%d\n", t); --cnt[t]; } }