1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#include <iostream>
#include <string>

using namespace std;

static int outcome(char a, char b) {
	if (a == b) return 0;
	if ((a == 'P' && b == 'K') || (a == 'K' && b == 'N') || (a == 'N' && b == 'P')) {
		return 1;
	}
	return -1;
}

static char bit_to_move(char bit) {
	return (bit == '0' ? 'P' : 'K');
}

static char move_to_bit(char mv) {
	return (mv == 'P' ? '0' : '1');
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	string who;
	if (!(cin >> who)) return 0;

	int a, b;
	if (!(cin >> a >> b)) return 0;

	const bool isAlgosia = (who == "Algosia");

	string firstMine;
	if (!(cin >> firstMine)) return 0;

	int n = static_cast<int>(firstMine.size());
	int t = (a == n ? b : (b == n ? a : b));

	for (int tc = 0; tc < t; ++tc) {
		string mine;
		if (tc == 0) {
			mine = firstMine;
		} else {
			if (!(cin >> mine)) return 0;
		}

		string other;
		other.reserve(n);

		int s = 0;

		for (int i = 0; i < n; ++i) {
			{
				char myMove;
				if (isAlgosia) {
					myMove = bit_to_move(mine[i]);
				} else {
					if (s == -1) myMove = 'K';
					else if (s == 1) myMove = 'P';
					else myMove = 'N';
				}

				cout << myMove << '\n';
				cout.flush();

				char oppMove;
				if (!(cin >> oppMove)) return 0;

				if (!isAlgosia) {
					other.push_back(move_to_bit(oppMove));
				}

				s += outcome(isAlgosia ? myMove : oppMove, isAlgosia ? oppMove : myMove);
			}

			{
				char myMove;
				if (!isAlgosia) {
					myMove = bit_to_move(mine[i]);
				} else {
					if (s == 1) myMove = 'K';
					else if (s == -1) myMove = 'P';
					else myMove = 'N';
				}

				cout << myMove << '\n';
				cout.flush();

				char oppMove;
				if (!(cin >> oppMove)) return 0;

				if (isAlgosia) {
					other.push_back(move_to_bit(oppMove));
				}

				s += outcome(isAlgosia ? myMove : oppMove, isAlgosia ? oppMove : myMove);
			}
		}

		cout << "! " << other << '\n';
		cout.flush();
	}

	return 0;
}