#include <bits/stdc++.h>
#include "vision.h"
using namespace std;

#define pb push_back
using ll = long long;
// #define int ll
using pi = array<int, 2>;
using ti = array<int, 3>;

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

int getMove1d(vector<int> v) {
    int n = v.size();
    if (v[n / 2] != 3) {
      int mx = 0;
      for (int i = 0; i < n; ++i) {
        if (v[i] > v[mx]) {
          mx = i;
        }
      }
      return mx;
    }
    
    for (int i = 0; i < n - 2; ++i) {
      if (v[i] == 2 && v[i + 1] == 1 && v[i + 2] == 3) {
        return n - 1;
      }
      if (v[i] == 3 && v[i + 1] == 1 && v[i + 2] == 2) {
        return 0;
      }
    }
    assert(false);
}

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

pair<int, int> getMove2d(vector<vector<int>> v) {
  int n = v.size();
  
  if (v[n / 2][n / 2] != 3) {
    pi mx{0, 0};
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (v[i][j] > v[mx[0]][mx[1]]) {
          mx = {i, j};
        }
      }
    }
    return {mx[0], mx[1]};
  }
  
  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j < n - 1; ++j) {
      int cnt = (v[i][j] == 2) + (v[i + 1][j] == 2) + (v[i][j + 1] == 2) + (v[i + 1][j + 1] == 2);
      if (cnt == 3) {
        int missing = 0;
        if (v[i][j] == 1) missing = 0;
        else if (v[i + 1][j] == 1) missing = 1;
        else if (v[i][j + 1] == 1) missing = 2;
        else missing = 3;
        
        if (missing == 0) {
          return {n - 1, n - 1};
        } else if (missing == 1) {
          return {0, n - 1};
        } else if (missing == 2) {
          return {n - 1, 0};
        } else {
          return {0, 0};
        }
      }
    }
  }
  assert(false);
}
