#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

pair<int, int> getMove2d(vector<vector<int>> v) {
    int n = (int)v[0].size();
    int p = n / 2;

    if (p == 1) {
        if (v[p - 1][p] >= v[p + 1][p]) return make_pair(p - 1, p);
        return make_pair(p + 1, p);
    } else if (p == 2 || p == 4) {
        if (v[p][p - 1] == 3) return make_pair(p, p - 1);
        if (v[p][p + 1] == 3) return make_pair(p, p + 1);
        if (v[p - 1][p] == 3) return make_pair(p - 1, p);
        if (v[p + 1][p] != 3) while (true) {};
        return make_pair(p + 1, p);
    } else {
        int dx = 1, dy = 1;
        if (v[p + 1][p] == 2) dx = -dx;
        if (v[p][p - 1] == 4) dy = -dy;
        return make_pair(p + dx * 2, p + dy * 2);
    }

    while (true) {}
}

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

int getMove1d(vector<int> v) {
    int n = (int)v.size() / 2;

    if (n == 1) {
        int a = v[n - 1], b = v[n + 1];
        if (min(a, b) == 1 && max(a, b) == 3) return (a == 1 ? n - 1 : n + 1);
        else if (min(a, b) == 1 && max(a, b) == 2) return (a == 2 ? n - 1 : n + 1);
        else return (a == 3 ? n - 1 : n + 1);
    } else if (n == 2) {
        for (int i = 0; i < (int)v.size(); i++) if (v[i] == 3) return i;
    } else {
        if (v[n - 2] == 2) return n + 1;
        return n - 1;
    }
}