#include "locmin.h"
#include<iostream>
#include<map>
#include<random>
using namespace std;

map<pair<long long, long long>, long long> mp;
int N, M;

long long get(long long x, long long y) {
    if (x < 0 || y < 0 || x >= N || y >= M) {
        return 1e18;
    }
    if (mp.find({x, y}) != mp.end()) {
        return mp[{x, y}];
    }
    // cout << "! " << x << " " << y + << endl;
    return mp[{x, y}] = value(x + 1, y + 1);
}
long long get2(long long a) {
    return get(0, a) < get(0, a + 1);
}
mt19937 rnd(10);

pair <int, int> find_locmin_point(int N2, int M2) {
    N = N2;
    M = M2;
    if (get2(0)) {
        return {1, 1};
    }
    if (!get2(N - 2)) {
        return {1, N}
    }
    long long L = 0, R = n - 2;
    while (R - L > 1) {
        long long mid = (L + R) / 2;
        if (get2(mid)) {
            R = mid;
        } else {
            L = mid;
        }
    }
    return {1, L + 2};
}
