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

const long long INF = 1000000000000000007;
long long n, m;

pair<int, int> find_locmin_point(int N, int M)
{
    n = N;
    m = M;
    long long l1 = 1, r1 = n, l2 = 1, r2 = m, mid1, mid2;
    while(r1 > l1 || r2 > l2)
    {
        if(r1 > l1)
        {
            mid1 = (r1-l1)/2+l1;
            mid2 = (r1-l1)/2+1+l1;
            long long mini1 = INF, mini2 = INF;
            for(long long i = l2; i <= r2; i++)
            {
                mini1 = min(mini1, value(mid1, i));
                mini2 = min(mini2, value(mid2, i));
            }
            if(mini1 < mini2) r1 = mid1;
            else l1 = mid2;
        }
        if(r2 > l2)
        {
            mid1 = (r2-l2)/2+l2;
            mid2 = (r2-l2)/2+1+l2;
            long long mini1 = INF, mini2 = INF;
            for(long long i = l1; i <= r1; i++)
            {
                mini1 = min(mini1, value(i, mid1));
                mini2 = min(mini2, value(i, mid2));
            }
            if(mini1 < mini2) r2 = mid1;
            else l2 = mid2;
        }
    }
    return {l1, l2};
}
