#include using namespace std; int command; int turn; int hand[4]; void trick() { int start_card; if (turn == 0) cin >> start_card; else { for (int i = 1; i <= 4; i++) if (hand[i]) { cout << hand[i] << '\n'; start_card = hand[i]; hand[i] = 0; cout.flush(); break; } } bool cut = true; while (cut) { cut = false; if (turn == 0) { for (int i = 1; i <= 4; i++) if (hand[i] == start_card || hand[i] == 7) { cout << hand[i] << '\n'; cout.flush(); hand[i] = 0; cut = true; break; } if (!cut) { bool played = false; for (int i = 1; i <= 4; i++) if (hand[i] && hand[i] != 10 && hand[i] != 14) { cout << hand[i] << '\n'; cout.flush(); hand[i] = 0; played = true; break; } if (!played) { for (int i = 1; i <= 4; i++) if (hand[i]) { cout << hand[i] << '\n'; cout.flush(); hand[i] = 0; break; } } } else { cin >> command; if (command < 7) { cut = false; } else command = 0; } } else { cin >> command; if (command != start_card && command != 7) break; else { for (int i = 1; i <= 4; i++) if (hand[i] == start_card || hand[i] == 7) { cout << hand[i] << '\n'; cout.flush(); hand[i] = 0; cut = true; break; } } if (!cut) { cout << 0 << '\n'; cout.flush(); } command = 0; } } } void game() { cin >> hand[1] >> hand[2] >> hand[3] >> hand[4]; turn = 0; while (1) { trick(); if (command == 0) cin >> command; if (command == 2 || command == 3) { int n; cin >> n; while (n--) { for (int i = 1; i <= 4; i++) if (hand[i] == 0) cin >> hand[i]; } if (command == 2) turn = 0; else turn = 1; } if (command == 4) { cin >> command >> command; break; } } } int main() { for (int i = 1; i <= 1000; i++) { game(); } return 0; }