#include <bits/stdc++.h>
#include "code.h"

using namespace std;

int Pitaj(int i,int j);
int a[1005][1005];
set <int> ii[1005];
set <int> jj[1005];

vector <int> Nadji(int N,int K)
{
    vector <int> ans;
    for(int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= N; j++)
        {
            a[i][j]=Pitaj(i,j);
            ii[i].insert(a[i][j]);
            jj[j].insert(a[i][j]);
        }
    }
    for(int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= N; j++)
        {
            auto it = ii[i].end();
            it--;
            auto it2 = it;
            it2--;
            if(*it != a[i][j])continue;
            if(*it==*it2)continue;
            it=jj[j].begin();
            it2=it;
            it2++;
            if(*it != a[i][j])continue;
            if(*it == *it2)continue;
            ans.push_back(i);
            ans.push_back(j);
            return ans;
        }
    }
    ans.push_back(0);
    ans.push_back(0);
    return ans;
}