#include <bits/stdc++.h>
#include "vision.h"
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
#define int long long

using namespace std;

vector<int> a[200];

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

signed getMove1d(std::vector<signed> v)
{
    if (v.size()==3)///e 1
    {
        int power=1;
        if (v[power-1]==2 && v[power+1]==1)
            return power+1;
        if (v[power-1]==1 && v[power+1]==2)
            return power-1;
        if (v[power-1]==1 && v[power+1]==3)
            return power+1;
        if (v[power-1]==3 && v[power+1]==1)
            return power-1;
    }
    if (v.size()==5)///e 2
    {
        int power=2;
        if (v[power-1]==1)
            return power-1;
        if (v[power+1]==1)
            return power+1;
    }
    if (v.size()==7)///e 3
    {
        int power=3;
        if (v[power-1]==2)
            return power-1;
        if (v[power+1]==2)
            return power+1;
    }
}

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

std::pair<signed, signed> getMove2d(std::vector<std::vector<signed>> v)
{
    int cnt;
    signed power;
    cnt=-1;
    for (auto x : v)
    {
        cnt++;
        for (auto y : x)
        {
            a[cnt].push_back(y);
        }
    }
    if (cnt==2)///e 1
    {
        power=1;
        if (a[power+1][power]==2)
        return {power+1,power};
        if (a[power][power+1]==2)
        return {power,power+1};


        if (a[power-1][power]==2)
        return {power-1,power};
        if (a[power][power-1]==2)
        return {power,power-1};
        assert(0);
    }
    if (cnt==4)///e 2
    {
        power=2;
        if (a[power+1][power]==3)
        return {power+1,power};
        if (a[power][power+1]==3)
        return {power,power+1};


        if (a[power-1][power]==3)
        return {power-1,power};
        if (a[power][power-1]==3)
        return {power,power-1};
        assert(0);
    }
    if (cnt==6)///e 3
    {
        power=3;
        if (a[power+1][power]==4)
        return {power+1,power};
        if (a[power][power+1]==4)
        return {power,power+1};


        if (a[power-1][power]==4)
        return {power-1,power};
        if (a[power][power-1]==4)
        return {power,power-1};
        assert(0);
    }

    if (cnt==8)///e 4
    {
        power=4;
        if (a[power+1][power]==1)
        return {power+1,power};
        if (a[power][power+1]==1)
        return {power,power+1};


        if (a[power-1][power]==1)
        return {power-1,power};
        if (a[power][power-1]==1)
        return {power,power-1};
        assert(0);
    }
    int i;
    for (i=0;i<=cnt;i++)
         a[i].clear();
}
