#include using namespace std; typedef long long ll; // a: 手牌 b: 山 int a[9]{}; string S; void init() { fill(a, a + 9, 0); for (int i = 0; i < 13; i++) { a[S[i] - '1']++; } } bool check_titoitu() { int cnt = 0; for (int i = 0; i < 9; i++) { if (a[i] == 2) cnt++; } return cnt == 7 ? true : false; } bool flag = false; void dfs(int n) { if (flag) return; if (n == 5) { flag = true; return; } if (n == 0) { for (int i = 0; i < 9; i++) { if (a[i] >= 2) { a[i] -= 2; dfs(n + 1); a[i] += 2; } } } if (n == 0) return; for (int i = 0; i < 9; i++) { if (a[i] >= 3) { a[i] -= 3; dfs(n + 1); a[i] += 3; } } for (int i = 0; i + 2 < 9; i++) { if (a[i] > 0 && a[i + 1] > 0 && a[i + 2] > 0) { a[i]--; a[i + 1]--; a[i + 2]--; dfs(n + 1); a[i]++; a[i + 1]++; a[i + 2]++; } } } int main() { cin >> S; set s; for (int i = 0; i < 9; i++) { init(); if (a[i] != 4) { a[i]++; if (check_titoitu()) s.insert(i + 1); dfs(0); if (flag) { s.insert(i + 1); } flag = false; a[i]--; } } for (int i : s) { cout << i << "\n"; } return 0; }