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

using namespace std;

int dirx[4] = {-1, 1, 0, 0};
int diry[4] = {0, 0, -1, 1};


std::pair <int, int> find_locmin_point(int N, int M) {
    int l = 1, c = M / 2;
    auto v = value(l, c);
    while(1) {
		 int d = -1;
		 for(int i = 0; i < 4; i++) {
			 if(l + dirx[i] <= 0 || l + dirx[i] > N || c + diry[i] < 1 || c + diry[i] > M) continue;
			 auto T = value(l + dirx[i], c + diry[i]);
			 if(T < v) {
				 d = i;
				 l += dirx[i];
				 c += diry[i];
				 v = T;
				 break;
			 }
		 }
		 if(d == -1) return make_pair(l, c);
	 }
}
