#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "vision.h"

#define all(x) (x).begin(),(x).end()

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
// #define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int, int>;
using tii = tuple<int, int, int>;

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

int getMove1d(std::vector<int> v)
{
	if(sz(v) == 3) {
		int i = 0;
		while(i < 3 && v[i] == 1) i++;
		if(i == 3) return 0;
		return i;
	}
	if(sz(v) == 5) {
		int i = 0;
		while(v[i] != 3) i++;
		return i;
	}
	if(sz(v) == 7) {
		int i = 0;
		while(v[i] != 2) i++;
		if(i < 3) return 6;
		else return 0;
	}
   return 0;
}

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

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
	int n = sz(v);
	if(sz(v) == 3) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(v[i][j] > 1) return {i, j};
			}
		}
		return {0, 0};
	}
	if(sz(v) == 5) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(v[i][j] == 4) return {i, j};
			}
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(v[i][j] == 3) return {i, j};
			}
		}
	}
	if(sz(v) == 7) {
		int dx = 1, dy = 1;
		if(v[3][3 + 2 * dy] != 1) dy *= -1;
		if(v[3 + 2 * dx][3] != 1) dx *= -1;
		return {3 + 3 * dx, 3 + 3 * dy};
	}
    return {0, 0};
}
