#include <bits/stdc++.h>
#include "locmin.h"
#define int long long

using namespace std;

bool found;
int n,m;
bool visited[505][505];
int val[505][505];
pair<signed,signed> dapair;

bool inmat(int l, int c)
{
    if (l>0 && l<=n && c>0 && c<=m)
        return 1;
    else
        return 0;
}

void dfs(int l, int c)
{
    if (found)
        return;
    int mi,ls,cs,res;
    mi=1e18+1;
    if (inmat(l-1,c))
    {
        if (!val[l-1][c])
        {
            res=value(l-1,c);
            val[l-1][c]=res;
        }
        res=val[l-1][c];
        if (res<mi)
        {
            mi=res;
            ls=l;
            cs=c;
        }
    }
    if (inmat(l+1,c))
    {
        if (!val[l+1][c])
        {
            res=value(l+1,c);
            val[l+1][c]=res;
        }
        res=val[l+1][c];
        if (res<mi)
        {
            mi=res;
            ls=l;
            cs=c;
        }
    }
    if (inmat(l,c-1))
    {
        if (!val[l][c-1])
        {
            res=value(l,c-1);
            val[l][c-1]=res;
        }
        res=val[l][c-1];
        if (res<mi)
        {
            mi=res;
            ls=l;
            cs=c;
        }
    }
    if (inmat(l,c+1))
    {
        if (!val[l][c+1])
        {
            res=value(l,c+1);
            val[l][c+1]=res;
        }
        res=val[l][c+1];
        if (res<mi)
        {
            mi=res;
            ls=l;
            cs=c;
        }
    }
    if (val[l][c]<mi)
    {
        dapair={l,c};
        found=true;
        return;
    }
    else
    {
        dfs(ls,cs);
    }
}

pair<signed, signed> find_locmin_point(signed N, signed M)
{
    int l,c;
    n=N;
    m=M;
    l=n/2;
    c=m/2;
    val[l][c]=value(l,c);
    found=false;
    dfs(l,c);
    return dapair;
}
