#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

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


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

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


map<vector<int>, int> z;
vector<vector<int>> matrix = {{3, 1, 1}, {1, 1, 4}, {1, 2, 5}};
vector<vector<int>> getVisionPattern2d()
{
    z.clear();
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            vector<int> all;
            for (auto &[dx, dy] : vector<pair<int, int>>{{-1, -1}, {-1, 1}, {1, -1}, {1, 1}}) {
                int x = j + dx;
                int y = j + dy;
                x = (x % 3 + 3) % 3;
                y = (y % 3 + 3) % 3;
                all.push_back(matrix[x][y]);
            }
            int f = all.back();
            //sort(all.begin(), all.end());
            sort(all.begin(), all.end());
            z[all] = f;
        }
    }
    return matrix;
}

pair<int, int> getMove2d(vector<vector<int>> v) {
    int n = v.size() / 2;
    vector<int> all;
    for (auto &[dx, dy] : vector<pair<int, int>>{{-1, -1}, {-1, 1}, {1, -1}, {1, 1}}) {
        int x = n + dx;
        int y = n + dy;
        all.push_back(v[x][y]);
    }
    sort(all.begin(), all.end());
    int to = z[all];
    for (auto &[dx, dy] : vector<pair<int, int>>{{-1, -1}, {-1, 1}, {1, -1}, {1, 1}}) {
        int x = n + dx;
        int y = n + dy;
        if (v[x][y] == to) {
            return {x, y};
        }
        //all.push_back(v[x][y]);
    }
}