#include <vector>

int mat1[1001][1001];

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])
                {
                    vek.pop_back();
                    vek.pop_back();
                    vek.push_back(i);
                    vek.push_back(j);
                    return vek;
                }
    }
    return vek;
}