#include <iostream>
#include <vector>
using namespace std;

int mat1[3001][3001];
int Pitaj(int i, int j);

std::vector<int> Nadji(int n, int k)
{
    vector<int> vek = {0, 0};
    if(n*n >= k)
    {
        int minKol[n+1], maksRed[n+1];
        for(int i = 1; i <= n; i++) minKol[i] = 1e9+1, maksRed[i] = 0;
        bool uniqMin[n+1], uniqMax[n+1];
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                mat1[i][j] = Pitaj(i, j);
                if(mat1[i][j] > maksRed[i]) maksRed[i] = mat1[i][j], uniqMax[i] = true;
                else if(mat1[i][j] == maksRed[i]) uniqMax[i] = false;
                if(mat1[i][j] < minKol[j]) minKol[j] = mat1[i][j], uniqMin[j] = true;
                else if(mat1[i][j] == minKol[j]) uniqMin[j] = false;
            }
        }

        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                if(mat1[i][j] == maksRed[i] && uniqMax[i] && mat1[i][j] == minKol[j] && uniqMin[j])
                    return {i, j};
    }
    else if(n <= 3000)
    {
        for(int i = 1; i <= n; i++) mat1[1][i] = Pitaj(1, i), mat1[2][i] = Pitaj(2, i), k -= 2;
        for(int i = 2; i <= n; i++) mat1[i][1] = Pitaj(i, 1), mat1[i][2] = Pitaj(i, 2), k -= 2;
        int maks1 = 0, maks2 = 0, min1 = 1e9, min2 = 1e9;
        bool umax1 = true, umax2 = true, umin1 = true, umin2 = true;
        for(int i = 1; i <= n; i++)
        {
            if(mat1[1][i] > maks1) maks1 = mat1[1][i], umax1 = true;
            else if(mat1[1][i] == maks1) umax1 = false;
            if(mat1[2][i] > maks2) maks2 = mat1[2][i], umax2 = true;
            else if(mat1[2][i] == maks2) umax2 = false;
            if(mat1[i][1] < min1) min1 = mat1[i][1], umin1 = true;
            else if(mat1[i][1] == min1) umin1 = false;
            if(mat1[i][2] < min2) min2 = mat1[i][1], umin2 = true;
            else if(mat1[i][2] == min2) umin2 = false;
        }
        if(umax1 && maks1 == mat1[1][1] && umin1 && min1 == mat1[1][1]) return {1, 1};
        if(umax1 && maks1 == mat1[1][2] && umin2 && min2 == mat1[1][2]) return {1, 2};
        if(umax2 && maks2 == mat1[2][1] && umin1 && min1 == mat1[2][1]) return {2, 1};
        if(umax2 && maks2 == mat1[2][2] && umin2 && min2 == mat1[2][2]) return {2, 2};
        for(int i = 3; i <= n; i++)
        {
            for(int j = 3; j <= n; j++)
            {
                if(mat1[i][1] < mat1[1][j] && mat1[i][1] < mat1[2][j] && mat1[i][2] < mat1[1][j] && mat1[i][2] < mat1[2][j])
                {
                    if(k != 0)
                    {
                        int val = Pitaj(i, j);
                        k--;
                        if(val > mat1[i][1] && val > mat1[i][2] && val < mat1[1][j] && val < mat1[2][j])
                        {
                            return {i, j};
                        }
                    }
                    else return {i, j};
                }
            }
        }
    }
    return vek;
}