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

typedef pair<int, int> pii;

vector<int> getVisionPattern1d()
{
    return {1};
}

int getMove1d(vector<int> v)
{
    return 0;
}

vector<vector<int>> getVisionPattern2d()
{
    return {
        {2, 1, 1},
        {1, 1, 2},
        {2, 1, 1}
    };
}

pii getMove2d(vector<vector<int>> v)
{
    int n = v.size();
    assert(n % 2);
    int offset = 0;
    if (n > 3) {
        offset = n / 2 - 1;
        vector<vector<int>> nv;
        for (int i = n / 2 - 1; i <= n / 2 + 1; i++) {
            vector<int> cur;
            for (int j = n / 2 - 1; j <= n / 2 + 1; j++)
                cur.push_back(v[i][j]);
            nv.push_back(cur);
        }
        v = nv, n = 3;
    }
    if (v[1][1] == 1) {
        if (v[1][0] == 2)
            return {1 + offset, 0 + offset};
        if (v[1][2] == 2)
            return {1 + offset, 2 + offset};
        assert(false);
    }
    if (v[1][1] == 2) {
        vector<pii> pos = {{0, 0}, {0, 2}, {2, 0}, {2, 2}};
        int cnt = 0;
        for (auto [i, j] : pos)
            cnt += v[i][j] == 2;
        if (cnt == 1) {
            for (auto [i, j] : pos) {
                if (v[i][j] == 2)
                    return {i + offset, 2 - j + offset};
            }
        }
        if (cnt == 2) {
            for (auto [i, j] : pos) {
                if (v[i][j] == 2)
                    return {i + offset, j + offset};
            }
        }
        assert(false);
    }
    assert(false);
}
