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
#include <bits/stdc++.h>
#define un unsigned
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define per(i, a, b) for(ll i = a; i >= b; i--)
#define all(v) begin(v), end(v)
#define st first
#define nd second
using namespace std;
using ll = long long;
using bigi = __int128;
using pii = pair<ll, ll>;
const ll N = 1e6 + 5;
int kolo[N];
int main(){
    
    string s;
    cin >> s;
    int n, t;
    cin >>  n >> t;
    srand(482193705 * n + t * 927304118);
    while(t--){
        rep(i, 0, n){
            kolo[i] = rand() % 2;
        }
        string kol;
        cin >> kol;
        if(s == "Algosia"){
            rep(i, 0, n){
                if(!kolo[i]) continue;
                if(kol[i] == '0') kol[i] = '1';
                else kol[i] = '0';
            }
        }
        string odp;
        rep(i, 0, kol.size()){
            int roz = 0;
            if(kol[i] == '1'){
                cout << 'K';
            }
            else{
                cout << 'P';
            }
            cout << endl;
            char c;
            cin >> c;
            if(c == 'K'){
                odp.push_back('1');
                if(kol[i] == '0'){
                    roz++;
                }
            }
            else{
                odp.push_back('0');
                if(kol[i] == '1'){
                    roz--;
                }
            }
            if(roz > 0){
                cout << 'K' << endl;
                cin >> c;
            }
            if(roz < 0){
                cout << 'P' << endl;
                cin >> c;
            }
        }
        if(s == "Bajtek"){
            rep(i, 0, n){
                if(!kolo[i]) continue;
                if(odp[i] == '0') odp[i] = '1';
                else odp[i] = '0';
            }
        }
        cout << "! " << odp << '\n';
    }
}