#include<iostream>
#include<random>
#include<climits>
#define MAXNN 510
#include "locmin.h"
using namespace std;
long long table[MAXNN];
pair <int, int> find_locmin_point(int n, int m)
{
    int l=1,r=m;
    while(r-l>1)
    {
        int mid=(l+r)>>1;
        //cout<<l<<" "<<r<<" "<<mid<<"\n";
        long long curr;
        if(table[mid])curr=table[mid];
        else {curr=value(1,mid);table[mid]=curr;}

        long long left=LLONG_MAX,right=LLONG_MAX;
        if(mid>l)
        {
            if(table[mid-1])left=table[mid-1];
            else {left=value(1,mid-1);table[mid-1]=left;}
        }
        if(mid<r)
        {
            if(table[mid+1])right=table[mid+1];
            else {right=value(1,mid+1);table[mid+1]=right;}
        }
        //cout<<left<<" "<<curr<<" "<<right<<"\n";

        if(left<=curr && left<=right)r=mid;
        else if(right<=left && right<=curr)l=mid;
        else
        {
            if(left!=LLONG_MAX)r=mid;
            else l=mid;
        }
    }
    if(table[l]<table[r])return {1,l};

    return {1,r};
}