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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <cstdio>
#include <cstdlib>
#include <vector>
using std::vector;

bool wygr(char x, char y) {
  if (x == 'K' && y == 'N') return true;
  if (x == 'P' && y == 'K') return true;
  if (x == 'N' && y == 'P') return true;
  return false;
}

const int M = 5013;

int r[M], rr[M];

char imie[23], s[M], ss[M], buf[13];

int n;

void go() {
  int r = 0, i = 0, j = 0, wynik = 0, wi = 0, wwi = 0;
  while (i < n || j < n) {
    if (wynik == 0) {
      char moj;
      if (wi) {
        if (s[i] == '0') { // 01
          moj = 'K';
        } else if (s[i+1] == '0') { // 10
          moj = 'P';
        } else { // 11
          moj = 'N';
        }
        i += 2;
        wi = 0;
      } else {
        if(i == n || s[i] == '1') { // 1 lub .
          moj = 'K';
          if (i < n) i++;
        }
        else if (i+1 == n || s[i+1] == '1') { // 01 lub 0.
          moj = 'P';
          i++;
          if (i < n) i++;
        } else { // 00
          moj = 'N';
          i += 2;
        }
      }
      printf("%c\n", moj);
      fflush(stdout);
      scanf("%s", buf);
      if (moj != buf[0]) {
        if (wygr(moj, buf[0])) wynik++;
        else wynik--;
      }
      if (wwi) {
        if (buf[0] == 'K') {
          ss[j++] = '0';
          ss[j++] = '1';
        } else if (buf[0] == 'P') {
          ss[j++] = '1';
          ss[j++] = '0';
        } else {
          ss[j++] = '1';
          ss[j++] = '1';
        }
        wwi = 0;
      } else {
        if (buf[0] == 'K') {
          if (j < n) ss[j++] = '1';
        } else if(buf[0] == 'P') {
          ss[j++] = '0';
          if (j < n) ss[j++] = '1';
        } else {
          ss[j++] = '0';
          ss[j++] = '0';
        }
      }
    } else {
      if (i < j || (i==j && imie[0]=='A')) {
        // Piszę
        if (s[i] == '1' || (i+1 < n && s[i+1] == '1')) {
          char moj = 'P';
          if (wynik > 0) moj = 'N';
          printf("%c\n", moj);
          fflush(stdout);
          wynik = 0;
          if (i+1 == n) i++;
          else wi = 1;
        } else {
          printf("K\n");
          fflush(stdout);
          i++;
          if (i<n) i++;
        }
        scanf("%s", buf);
      } else {
        // Czytam
        printf("K\n");
        fflush(stdout);
        scanf("%s", buf);
        if ('K' != buf[0]) {
          wynik = 0;
          if (j+1 == n) ss[j++] = '1';
          else wwi = 1;
        } else {
          ss[j++] = '0';
          if(j<n) ss[j++] = '0';
        }
      }
    }
  }
}

int main() {
  int t;
  scanf("%s %d %d", &imie, &n, &t);
  srand(57);
  if (imie[0] == 'A') {
    for (int i = 0; i < n; i++) r[i] = rand()%2;
    for (int i = 0; i < n; i++) rr[i] = rand()%2;
  } else {
    for (int i = 0; i < n; i++) rr[i] = rand()%2;
    for (int i = 0; i < n; i++) r[i] = rand()%2;
  }
  for (int i = 0; i < t; i++) {
    scanf("%s", s);
    for (int i = 0; i < n; i++) if(r[i]) s[i] = '0'+'1'-s[i];
    go();
    ss[n] = 0;
    for (int i = 0; i < n; i++) if(rr[i]) ss[i] = '0'+'1'-ss[i];
    printf("! %s\n",ss);
    fflush(stdout);
  }
  return 0;
}