#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()
vector<int> p={1,1,2,1,3};
ll mx = 3;
std::vector<int> getVisionPattern1d()
{
    return p;
}

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()
{
    vector<vector<int>> q;
    vector<int> em(p.size(),1);
    for(ll i = 0; i < p.size(); ++i){
        for(ll _ = 1; _ < mx; ++_){
            q.pb(em);
        }
        vll shif(p.size());
        for(ll j = 0; j < p.size(); ++j){
            shif[j] = p[(i+j)%p.size()];
        }
        q.pb(shif);
    }
    reverse(all(q));
    return q;
}

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    if(v.size()==3){
        for(ll i = 0; i < 3; ++i){
            for(ll j = 0; j < 3; ++j){
                if(v[i][j]!=1)return {i,j};
            }
        }
        return {0,1};
    }
    else if(v.size()<mx*2+1){
        return {v.size()/2, getMove1d(v[v.size()/2])};
    }
    else{
        ll o = getMove1d(v[mx]);
        if(o==0){
            if(v[0][1]==2)return {0,1};
            return {mx*2,1};
        }
        else{
            if(v[0][mx*2-1]==2)return {0,mx*2-1};
            return {mx*2,mx*2-1};
        }
    }

}
