#include <bits/stdc++.h>
#include "locmin.h"
using namespace std;
map<pair<int, int>, int> f;

int q_value(int i, int j) {
    if(f.find({i, j}) == f.end()) {
        f[{i, j}] = value(i, j);
    }
    return f[{i, j}];
}

std::pair <int, int> find_locmin_point(int n, int m) {
    assert(n == 1);
    int st = 2, dr = m - 1, ans = m;
    if(m == 1) {
        return {1, 1};
    }
    int v1 = q_value(1, 1), v2 = q_value(1, 2);
    if(v1 < v2) {
        return {1, 1};
    } else if(m == 2) {
        return {1, 2};
    }
    while(st <= dr) {
        int mid = (st + dr) / 2;
        int v_mid = q_value(1, mid);
        int v_midp1 = q_value(1, mid + 1);
        // std::cout << "? " << mid << '\n';
        if(v_mid < v_midp1) {
            ans = mid;
            dr = mid - 1;
        } else  {
            st = mid + 1;
        }
    }
    return {1, ans};
}

