#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <iterator>
#include <cassert>
#include <queue>
#include "vision.h"
using namespace std;

#define dbg(x) cerr << #x << ' '; print(x); cerr << endl;
void print(int x) { cerr << x; }
void print(long long x) { cerr << x; }
void print(char x) { cerr << x; }
void print(string x) { cerr << x; }
void print(double x) { cerr << x; }
template <class T> void print(vector <T> x) { cerr << "[ "; for (T i : x) { print(i); cerr << ' '; } cerr << ']'; }
template <class T> void print(set <T> x) { cerr << "[ "; for (T i : x) { print(i); cerr << ' '; } cerr << ']'; }
template <class T> void print(multiset <T> x) { cerr << "[ "; for (T i : x) { print(i); cerr << ' '; } cerr << ']'; }
template <class T, class V> void print(pair <T, V> x) { cerr << "{"; print(x.first); cerr << ' '; print(x.second); cerr << "}"; }

#define ll long long
#define OK cerr << "OK\n"
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define PII pair <int, int>
#define MP make_pair
#define inf 1e9 + 5
#define inf64 1e18 + 5;

vector<int> getVisionPattern1d() {
	return { 3, 1, 1, 1, 2, 1 };
}
int getMove1d(vector<int> v) {
	//dbg(v);
	int piv = v.size() / 2;
	if (v[piv] == 1) {
		if (v[0] == 3) return 0;
		if (v[2] == 3) return 2;
		if (v[0] == 2) return 0;
		if (v[2] == 2) return 2;
		return 0;
	}
	if (v[piv] == 2) {
		if (v[4] == 3) return 4;
		else return 0;
	}
	if (v[piv] == 3) {
		if (v[5] != 2) return 6;
		else return 0;
	}
	assert(1);
	return 0;
}

int dx[4] = { -1, 1, -1, 1 };
int dy[4] = { -1, 1, 1, -1 };

vector<vector<int>> getVisionPattern2d() {
	return {
		{1, 3, 2},
		{3, 2, 1},
		{2, 1, 3},
	};
}
pair<int, int> getMove2d(vector<vector<int>> v) {
	int piv = v.size() / 2;
	if (v[piv][piv] == 1) {
		for (int i = 0; i < 4; i++) {
			if (v[piv + dx[i]][piv + dy[i]] == 2) return { piv + dx[i], piv + dy[i] };
		}
	}
	if (v[piv][piv] == 2) {
		for (int i = 0; i < 4; i++) {
			if (v[piv + dx[i]][piv + dy[i]] == 3) return { piv + dx[i], piv + dy[i] };
		}
	}
	if (v[piv][piv] == 3) {
		for (int i = 0; i < 4; i++) {
			if (v[piv + dx[i]][piv + dy[i]] == 1) return { piv + dx[i], piv + dy[i] };
		}
	}
	assert(1);
	return { -1, -1 };
}
