#define MAX_QUERIES 1500

#include "manager.h"
#include <cstdio>
#include <cstdlib>
#include <csignal>
#include <cstring>
using namespace std;
const int PROCESSES=1;

const int MAXN = 1024;

int n;
char s[MAXN], t[MAXN];

void exit_status(int code, int score)
{
    fprintf(stdout, "%d\n", score);
    if (code == 0) fprintf(stdout, "Wrong answer\n");
    if (code == 1) fprintf(stdout, "Invalid question\n");
    if (code == 2) fprintf(stdout, "Question limit exceeded\n");
    if (code == 3) fprintf(stdout, "Correct answer\n");
    if (code == 4) fprintf(stdout, "Violation of the protocol for communication\n");
    exit(0);
}

int main(int argc, char ** argv)
{
    signal(SIGPIPE, SIG_IGN);
    fd_to_stream(argv+1,2*PROCESSES);

    cin >> n ;
    cin >> s ;
    out(0) << n << endl ;

    int cnt = 0;
    while (true)
    {
        int ask;
        if (!(in(0) >> ask )) exit_status(4, 0);
        if (ask < 0 or ask > 1) exit_status(1, 0);

        if (ask == 0)
        {
            if (!(in(0) >> t )) exit_status(4, 0);
            if (strcmp(s, t) == 0) exit_status(3, 1);
            else exit_status(0, 0);
            break;
        }

        cnt++;
        if (cnt > MAX_QUERIES) exit_status(2, 0);

        int len = 0, match = 0;
        if (!(in(0) >> len )) exit_status(4, 0);
        if (len != n) exit_status(1, 0);

        if (!(in(0) >> t )) exit_status(4, 0);
        if ((int)strlen(t) != len) exit_status(1, 0);
        for (int j = 0; j < len; ++ j)
        {
            if (t[j] < '0' or t[j] > '1') exit_status(1, 0);
            if (s[j] == t[j]) match++;
        }

        int m = 0;
        if (match == n / 2) m = 1;
        if (match == n) m = 2;

        out(0) << m << endl ;
    }

    return 0;
}
