#include using namespace std; bool mentsu(vector &hand, int remaining) { if (remaining == 0) return true; for (int i = 0; i < 9; i++) { if (hand.at(i) < 3) continue; hand.at(i) -= 3; if (mentsu(hand, remaining - 1)) { hand.at(i) += 3; return true; } hand.at(i) += 3; } for (int i = 0; i < 7; i++) { if (hand.at(i) == 0 || hand.at(i + 1) == 0 || hand.at(i + 2) == 0) continue; hand.at(i)--; hand.at(i + 1)--; hand.at(i + 2)--; if (mentsu(hand, remaining - 1)) { hand.at(i)++; hand.at(i + 1)++; hand.at(i + 2)++; return true; } hand.at(i)++; hand.at(i + 1)++; hand.at(i + 2)++; } return false; } bool isagari(vector &hand) { bool seven_pairs = true; for (int i = 0; i < 9; i++) { if (hand.at(i) != 0 && hand.at(i) != 2) { seven_pairs = false; break; } } if (seven_pairs) return true; for (int i = 0; i < 9; i++) { if (hand.at(i) < 2) continue; hand.at(i) -= 2; if (mentsu(hand, 4)) { hand.at(i) += 2; return true; } hand.at(i) += 2; } return false; } int main() { string s; cin >> s; sort(s.begin(), s.end()); vector hand(9); for (int i = 0; i < 13; i++) hand.at(s.at(i) - '1')++; for (int i = 0; i < 9; i++) { if (hand.at(i) == 4) continue; hand.at(i)++; if (isagari(hand)) cout << i + 1 << endl; hand.at(i)--; } }