#include using namespace std; #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) bool is_chitoi(int count[9]) { rep(i, 9) if (count[i] != 0 && count[i] != 2) return false; return true; } bool is_tenpai(int count[9], bool head = false, int mentsu = 0) { if (head && mentsu == 4) return true; if (!head && mentsu == 0 && is_chitoi(count)) return true; bool ok = false; rep(i, 9) { if (count[i] >= 2 && !head) { count[i] -= 2; if (is_tenpai(count, true, mentsu)) ok = true; count[i] += 2; } if (count[i] >= 3) { count[i] -= 3; if (is_tenpai(count, head, mentsu+1)) ok = true; count[i] += 3; } if (i+2 < 9 && count[i] > 0 && count[i+1] > 0 && count[i+2] > 0) { --count[i]; --count[i+1]; --count[i+2]; if (is_tenpai(count, head, mentsu+1)) ok = true; ++count[i]; ++count[i+1]; ++count[i+2]; } if (ok) return true; } return false; } int main() { string S; cin >> S; int count[9]; rep(i, 9) count[i] = 0; rep(i, 13) { ++count[S[i] - '0' - 1]; } rep(i, 9) { if (count[i] == 4) continue; ++count[i]; if (is_tenpai(count)) { cout << i+1 << endl; } --count[i]; } return 0; }