#include <bits/stdc++.h>
#include "locmin.h"
using namespace std;
const int PC = 4;
const int MAX = 500;
long long mr[MAX + 2][MAX + 2];
int dl[] = {-1, 0, 0, 1};
int dc[] = {0, -1, 1, 0};
long long getValue(int l, int c) {
    if (mr[l][c] == 0) {
        mr[l][c] = value(l, c);
    }
    return mr[l][c];
}
std::pair <int, int> find_locmin_point(int n, int m) {
    int l, c, i, rez, l2, c2;
    long long x, y;
    l = rand() % n + 1;
    c = m / 2 + 1;
    rez = 1;
    while (rez > 0) {
        x = getValue(l, c);
        i = rez = 0;
        while (i < PC && rez == 0) {
            l2 = l + dl[i];
            c2 = c + dc[i];
            if (l2 > 0 && l2 <= n && c2 > 0 && c2 <= m) {

                y = getValue(l2, c2);
                if (y < x) {
                    rez = 1;
                    l = l2;
                    c = c2;
                    x = y;
                }
            }
            i++;
        }
    }
    return {l, c};
}
