#include "locmin.h"
#include <bits/stdc++.h>

using namespace std;

#define fr(n) for(int i = 0; i<n; i++)
#define x first
#define y second
#define srt(v) sort(v.begin(), v.end())

pair<int,int> find_locmin_point(int n, int m) {
    
    vector<vector<int>> g(n, vector<int> (m, -1));
    int i = n/2, j = m-1;
    g[0][0] = value(i+1,j+1);
    while(true){
        if(i>0 && g[i-1][j]==-1){
            g[i-1][j] = value(i, j+1);
            if(g[i-1][j]<g[i][j]){
                i--;
                continue;
            }
        }
        else if(j>0 && g[i][j-1]==-1){
            g[i][j-1] = value(i+1, j);
            if(g[i][j-1]<g[i][j]){
                j--;
                continue;
            }
        }
        else if(j<m-1 && g[i][j+1]==-1){
            g[i][j+1] = value(i+1, j+2);
            if(g[i][j+1]<g[i][j]){
                j++;
                continue;
            }
        }
        else if(i<n-1 && g[i+1][j]==-1){
            g[i+1][j] = value(i+2, j+1);
            if(g[i+1][j]<g[i][j]){
                i++;
                continue;
            }
        }
        else
            return {i+1, j+1};
    }
}