#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

vector<vi> getVisionPattern2d(void) {
    return {
        {1, 1, 1, 2},
        {1, 2, 1, 1},
        {1, 1, 3, 1},
        {1, 1, 1, 1}
    };
}

pii getMove2d(vector<vi> v) {
    int n = v.size();
    vector<pii> adj = {{n/2, n/2 + 1}, {n/2, n/2 - 1}, {n/2 + 1, n/2}, {n/2 - 1, n/2},
    {n/2 + 1, n/2 - 1}, {n/2 - 1, n/2 + 1}, {n/2 + 1, n/2 + 1}, {n/2 - 1, n/2 - 1}};
    if (v[n / 2][n / 2] == 1) {
        for (auto [a, b] : adj)
            if (v[a][b] == 2 || v[a][b] == 3) return {a, b};
    } else if (v[n / 2][n / 2] == 2) {
        for (auto [a,b] : adj)
            if (v[a][b] == 3) return {a,b};
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j)
                if (v[i][j] == 3) return {i, j};
        }
    } else {
        for (auto [a,b] : adj)
            if (v[a][b] == 2) return {3*a - n + 1, 3*b - n + 1};
    }
    return {0, 0};
}

vi getVisionPattern1d(void) {
    return {1, 1, 2, 3};
}

int getMove1d(vi v) {
    int n = v.size();
    if (v[n / 2] == 1) {
        if (v[n / 2 + 1] == 2) return n / 2 + 1;
        else if (v[n / 2 - 1] == 2) return n / 2 - 1;
        else if (v[n / 2 + 1] == 1) return n / 2 + 1;
        else return n / 2 - 1;
    } else if (v[n / 2] == 2) {
        if (v[n / 2 + 1] == 3) return n / 2 + 1;
        else return n / 2 - 1;
    } else {
        if (v[n / 2 + 1] == 1) return n / 2 + 1;
        else return n / 2 - 1;
    }
}