#include <bits/stdc++.h>

using namespace std;
using ll = int;
using vll = vector<ll>;
using vvl = vector<vll>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vvp = vector<vpl>;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(),v.end()

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

int getMove1d(std::vector<int> v)
{
    if(v.size()==5){
        if(v[4]==3)return 4;
        return 0;
    }
    else if(v.size()==7){
        if(v[6]==2)return 6;
        return 0;
    }
    else{
        ll o = 0,b;
        if(v[0]>v[2]){reverse(all(v));o=1;}
        if(v[2]==2)b=2;
        else if(v[0]==2)b=2;
        else b=0;
        if(o)return 2-b;
        return b;
    }
}

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

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    if(v.size()==7){
        return {3,getMove1d(v[3])};
    }
    else if(v.size()==3){
        return {1,getMove1d(v[1])};
    }
    else{
        ll o = getMove1d(v[2]);
        if(o==0){
            if(v[0][1]==3)return {0,1};
            return {4,1};
        }
        else{
            if(v[0][3]==3)return {0,3};
            return {4,3};
        }
    }

}