#include using namespace std; int command; int turn; int hand[5]; void printError() { cerr << "HAND: "; for (int i = 1; i <= 4; i++) cerr << hand[i] << ' '; cerr << '\n'; cerr.flush(); } 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(); //printError(); 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; //printError(); 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; //printError(); break; } if (!played) { for (int i = 1; i <= 4; i++) if (hand[i]) { cout << hand[i] << '\n'; cout.flush(); hand[i] = 0; //printError(); break; } } } else { cin >> command; if (command < 7) { cut = false; break; } else command = 0; } } else { cin >> command; if (command < 7) break; if (command != start_card && command != 7) { cout << 0 << '\n'; cout.flush(); command = 0; 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; //printError(); break; } command = 0; } if (!cut) { cout << 0 << '\n'; cout.flush(); //printError(); } 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) { //printError(); int n; cin >> n; while (n--) { int x; cin >> x; for (int i = 1; i <= 4; i++) if (hand[i] == 0) { hand[i] = x; break; } } if (command == 2) turn = 0; else turn = 1; command = 0; //printError(); } if (command == 4) { //printError(); cin >> command >> command; command = 0; break; } } } int main() { for (int i = 1; i <= 1000; i++) { game(); } return 0; }