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

map<pair<int, int>, ll> mem;
int N, M;

ll val(int i, int j) {
    cout << i << " " << j << "\n";
    if (i < 0 || i >= N || j < 0 || j >= M) {
        return 1000000000000000001;
    }
    if (mem.count({i, j})) {
        return mem[{i, j}];
    }
    return mem[{i, j}] = value(i + 1, j + 1);
}

pair<int, int> find_locmin_point(int n, int m) {
    N = n;
    M = m;
    mem.clear();
    int i = 0, j = 0;
    while (true) {
        vector<pair<int, int>> cs = {{i - 1, j}, {i, j - 1}, {i + 1, j}, {i, j + 1}};
        pair<int, int> bs = {-1, -1};
        bool ok = true;
        for (auto [i2, j2] : cs) {
            if (val(i2, j2) < val(i, j)) {
                ok = false;
                if (val(i2, j2) < val(bs.first, bs.second)) {
                    bs = {i2, j2};
                }
            }
        }
        if (ok) {
            return {i, j};
        }
        i = bs.first;
        j = bs.second;
    }
}
