codeparrot/codecomplex huggingface dataset:
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start(); 
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	
	int N;
	int M;
	boolean[][] used;
	Queue<Integer> queue;
	
	int[] dx = { -1, 0, 1, 0 };
	int[] dy = { 0, -1, 0, 1 };
	int ans = -1;
	
	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter("output.txt");
		
		N = nextInt();
		M = nextInt();
		used = new boolean [N][M];
		queue = new ArrayDeque<Integer> (N * M);
		for (int K = nextInt(); K --> 0; )
			addState(nextInt() - 1, nextInt() - 1);
		while (!queue.isEmpty()) {
			int cv = queue.poll();
			int cx = cv / M;
			int cy = cv % M;
			for (int d = 0; d < dx.length; d++) {
				int nx = cx + dx[d];
				int ny = cy + dy[d];
				if (0 <= nx && nx < N && 0 <= ny && ny < M && !used[nx][ny])
					addState(nx, ny);
			}
		}
		out.println((1 + ans / M) + " " + (1 + ans % M));
		out.close();
	}
	
	void addState(int x, int y) {
		used[x][y] = true;
		queue.add(ans = code(x, y));
	}

	int code(int x, int y) {
		return x * M + y;
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		
		return st.nextToken();
	}
	
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			
			if (s == null) {
				return true;
			}
			
			st = new StringTokenizer(s);
		}
		
		return false;
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
// package Practice1.CF35;

import java.io.*;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class CF035C {
    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(new File("input.txt")/*System.in*/);
        int n = s.nextInt();
        int m = s.nextInt();
        int k = s.nextInt();
//        pair[] arr = new pair[n];
        Queue<pair> q = new LinkedList<>();
        PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
        boolean[][] visited = new boolean[n][m];
        for (int i = 0; i < k; i++) {
            int x = s.nextInt() - 1;
            int y  = s.nextInt() - 1;
            visited[x][y] = true;
            pair p = new pair(x,y);
//            arr[i] = p;
            q.add(p);
        }

        q.add(null);
        int[] dx = {0,0,1,-1};
        int[] dy = {1,-1,0,0};
        int ansX = q.peek().x;
        int ansY = q.peek().y;
        while(true){
            if(q.peek() == null){
                q.poll();
                q.add(null);
            }
            pair p = q.poll();
            if(p == null){
                break;
            }
            for (int i = 0; i < 4; i++) {
                if(isValid(p.x + dx[i],p.y+dy[i],n,m) && !visited[p.x + dx[i]][p.y+dy[i]]){
                    q.add(new pair(p.x + dx[i],p.y+dy[i]));
                    ansX = p.x + dx[i];
                    ansY = p.y + dy[i];
                    visited[ansX][ansY] = true;
                }
            }
        }
        out.println((ansX+1) + " " + (ansY+1));
        out.close();

    }

    public static boolean isValid(int x, int y,int n, int m){
        return x >= 0 && x < n && y >= 0 && y < m;
    }

    private static class pair{
        int x;
        int y;

        public pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;
public class j
{
public static void main(String a[])throws IOException
{
BufferedReader b = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
int l=0,x2=0,x=0,y1=0,y=0,max=-1,min=100000,x1=0,n=0,j=0,k=0,p=0,m=0,i=0;
String s;
s=b.readLine();
StringTokenizer c=new StringTokenizer(s);
n=Integer.parseInt(c.nextToken());
m=Integer.parseInt(c.nextToken());
k=Integer.parseInt(b.readLine());
int e[][]=new int[k][2];
s=b.readLine();
StringTokenizer z=new StringTokenizer(s);
for(i=0;i<k;i++)
{
e[i][0]=Integer.parseInt(z.nextToken());
e[i][1]=Integer.parseInt(z.nextToken());
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
for(l=0;l<k;l++)
{
p=(int)Math.abs(e[l][0]-i)+(int)Math.abs(e[l][1]-j);
if(p<min)
{
min=p;
x1=i;
y1=j;
}
}
if(min>max)
{
max=min;
x=x1;
y=y1;
}
min=100000;
}
}
out.print(x+" "+y);
out.close();
}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic

import java.awt.Point;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;

public class C {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new FileReader(new File("input.txt")));
        PrintWriter out = new PrintWriter(new File("output.txt"));
        int n = in.nextInt();
        int m = in.nextInt();
        int[][] T = new int[n][m];
        int k = in.nextInt();
        int[] X = new int[k];
        int[] Y = new int[k];
        for (int i = 0; i < k; i++) {
            X[i] = in.nextInt() - 1;
            Y[i] = in.nextInt() - 1;
        }
        int max = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                int min = Integer.MAX_VALUE;
                for (int ii = 0; ii < k; ii++)
                    min = Math.min(min,
                            Math.abs(i - X[ii]) + Math.abs(j - Y[ii]));
                max = Math.max(max, T[i][j] = min);
            }
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (T[i][j] == max) {
                    out.println((i + 1) + " " + (j + 1));
                    out.flush();
                    return;
                }

    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

public class ProblemC {
	
	static int[] dx = {1, 0, 0, -1};
	static int[] dy = {0, 1, -1, 0};
	
	
	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new FileReader("input.txt"));
		PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
//		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter out = new PrintWriter(System.out);
		
		String[] nm = s.readLine().split(" ");
		int n = Integer.valueOf(nm[0]);
		int m = Integer.valueOf(nm[1]);
		int k = Integer.valueOf(s.readLine());
		
		int[][] dp = new int[n][m];
		for (int i = 0 ; i < n ; i++) {
			Arrays.fill(dp[i], Integer.MAX_VALUE);
		}
		String[] st = s.readLine().split(" ");
		int[][] trees = new int[k][2];
		for (int l = 0 ; l < k ; l++) {
			trees[l][0] = Integer.valueOf(st[l*2])-1;
			trees[l][1] = Integer.valueOf(st[l*2+1])-1;
		}
		
		int maxtime = -1;
		int max_x = -1;
		int max_y = -1;
		for (int i = 0 ; i < n ; i++) {
			for (int j = 0 ; j < m ; j++) {
				int minDist = n+m;
				for (int l = 0 ; l < k ; l++) {
					minDist = Math.min(minDist, Math.abs(i - trees[l][0]) + Math.abs(j - trees[l][1]));
				}
				if (maxtime < minDist) {
					maxtime = minDist;
					max_x = i+1;
					max_y = j+1;
				}
			}
		}
		
		
		
		out.println(max_x + " " + max_y);
		out.flush();
	}


	public static void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String [] args) throws IOException{
		Scanner in = new Scanner(new FileInputStream("input.txt"));
		//Scanner in = new Scanner(System.in);
		File file = new File("output.txt");
		FileOutputStream fos = new FileOutputStream(file);
		if (!file.exists()) {
		     file.createNewFile();
		}
		
		int N = in.nextInt();
		int M = in.nextInt();
		int K = in.nextInt();
		int [][] fireTime = new int[N][M];
		for (int i=0; i<K; i++){
			int x = in.nextInt()-1;
			int y = in.nextInt()-1;
			fireTime[x][y] = -1;
			
			for (int j=1; j<=x+y; j++){
				for (int p=0; p<=j; p++){
					if (x-j+p >= 0 && y-p >=0 && (fireTime[x-j+p][y-p] == 0 || fireTime[x-j+p][y-p] > j)){
						fireTime[x-j+p][y-p] = j;
					}
				}
			}
			
			for (int j=1; j<=x+M-1-y; j++){
				for (int p=0; p<=j; p++){
					if (x-j+p >= 0 && y+p < M && (fireTime[x-j+p][y+p] == 0 || fireTime[x-j+p][y+p] > j)){
						fireTime[x-j+p][y+p] = j;
					}
				}
			}
			
			for (int j=1; j<=N-1-x+y; j++){
				for (int p=0; p<j; p++){
					if (x+j-p < N && y-p >= 0 && (fireTime[x+j-p][y-p] == 0 || fireTime[x+j-p][y-p] > j)){
						fireTime[x+j-p][y-p] = j;
					}
				}
			}
			
			for (int j=1; j<=N-1-x+M-1-y; j++){
				for (int p=0; p<=j; p++){
					//System.out.println(j+" "+p);
					if (x+j-p < N && y+p < M && (fireTime[x+j-p][y+p] == 0 || fireTime[x+j-p][y+p] > j)){
						//System.out.println(j);
						fireTime[x+j-p][y+p] = j;
					}
				}
			}
		}
		
		int max = -1;
		int tx = 1;
		int ty = 1;
		for (int i=0; i<N; i++){
			for (int j=0; j<M; j++){
				//System.out.print(fireTime[i][j]+" ");
				if (fireTime[i][j] > max){
					max = fireTime[i][j];
					tx = i+1;
					ty = j+1;
				}
			}
			//System.out.println();
		}
		//System.out.println(tx+" "+ty);
		String output = tx+" "+ty;
		
		byte[] bA = output.getBytes();
		fos.write(bA);
		fos.flush();
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic

import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;


public class C35 
{

	public static int mod = 1000000007;
	public static long INF = (1L << 60);

	static int n,m;
	static class Pair
	{
		int x,y;
		Pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}
	}
	static boolean[][] burned;
	static int[] dx={-1,0,1,0};
	static int[] dy={0,-1,0,1};
	static boolean isvalid(int x,int y)
	{
		return x>=0&&x<n&&y>=0&&y<m;
	}
	public static void main(String[] args) throws IOException
	{
		Scanner in = new Scanner("input.txt");
		PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
		n=in.nextInt();
		m=in.nextInt();
		burned=new boolean[n][m];
		int k=in.nextInt();
		Queue<Pair> queue=new LinkedList<>();
		Pair prev=null;
		for(int i=0;i<k;i++)
		{
			int x=in.nextInt();
			int y=in.nextInt();
			burned[x-1][y-1]=true;
			queue.add(prev=new Pair(x-1, y-1));
		}
		while(!queue.isEmpty())
		{
			Queue<Pair> tempqueue=new LinkedList<>();
		for(Pair p : queue)
		{
			int x=p.x;
			int y=p.y;
			prev=p;
			for(int i=0;i<4;i++)
			{
				if(isvalid(x+dx[i], y+dy[i])&&!burned[x+dx[i]][y+dy[i]])
				{
					tempqueue.add(new Pair(x+dx[i], y+dy[i]));
					burned[x+dx[i]][y+dy[i]]=true;
				}
			}
		}
		queue=tempqueue;
		}
		out.printf("%d %d\n",(prev.x+1),(prev.y+1));
		out.close();

	}
	
	public static long pow(long x, long n) 
	{
		long res = 1;
		for (long p = x; n > 0; n >>= 1, p = (p * p)) 
		{
			if ((n & 1) != 0) 
			{
				res = (res * p);
			}
		}
		return res;
	}
	
	public static long pow(long x, long n, long mod) 
	{
		long res = 1;
		for (long p = x; n > 0; n >>= 1, p = (p * p) % mod) 
		{
			if ((n & 1) != 0) 
			{
				res = (res * p % mod);
			}
		}
		return res;
	}

	public static long gcd(long n1, long n2)
	{
		long r;
		while (n2 != 0) 
		{
			r = n1 % n2;
			n1 = n2;
			n2 = r;
		}
		return n1;
	}

	public static long lcm(long n1, long n2) 
	{
		long answer = (n1 * n2) / (gcd(n1, n2));
		return answer;
	}

	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
		
		public Scanner(String s) throws FileNotFoundException {	br = new BufferedReader(new FileReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException { return Double.parseDouble(next()); }

		public boolean ready() throws IOException {return br.ready();} 
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;


public class R035CRetry {
    public void debug(Object... objects) { System.err.println(Arrays.deepToString(objects)); }
    public static final int INF = 987654321;
    public static final long LINF = 987654321987654321L;
    public static final double EPS = 1e-9;
    
    Scanner scanner;
    PrintWriter out;
    boolean[][] bss;
    
    public R035CRetry() {
        try {
            this.scanner = new Scanner(new File("input.txt"));
            this.out = new PrintWriter("output.txt");
        } catch(FileNotFoundException ex) { ex.printStackTrace(); }
    }
    
    class Point implements Comparable<Point> {
        int x, y, count;
        Point(int x, int y) { this.x = x; this.y = y; }
        public int hashCode() { return x * 17 + y; }
        public boolean equals(Object o) {
            if(!(o instanceof Point)) return false;
            Point that = (Point)o;
            return this.x == that.x && this.y == that.y;
        }
        public int compareTo(Point that) { return this.count - that.count; }
        public String toString()  { return "(" + x + ", " + y + ":" + count + ")"; }
    }

    
    int[] dx = new int[] {  0, 0, -1, 1 };
    int[] dy= new int[] { -1, 1,  0, 0 };
    int n, m;
    
    Queue<Point> q;
    
    Point bfs() {
        int max = -INF;
        Point p = null;
        while(!q.isEmpty()) {
            Point cur = q.remove();
            if(max < cur.count) { max = cur.count; p = cur; } 
            for(int i=0; i<dx.length; i++) {
                int nx = cur.x + dx[i];
                int ny = cur.y + dy[i];
                if(nx < 0 || nx >= n) { continue; }
                if(ny < 0 || ny >= m) { continue; }
                Point np = new Point(nx, ny);
                if(bss[nx][ny] ) { continue; } 
                np.count = cur.count+1;
                bss[nx][ny] = true;
                q.add(np);
            }
        }
        return p;
    }
    
    private void solve() {
        this.n = scanner.nextInt();
        this.m = scanner.nextInt();
        this.bss = new boolean[n][m];
        int k = scanner.nextInt();
        q = new LinkedList<Point>();
        for(int i=0; i<k; i++) {
            int x = scanner.nextInt() - 1;
            int y = scanner.nextInt() - 1;
            Point init = new Point(x, y);
            init.count = 1;
            q.add(init);
            bss[x][y] = true;
        }
        Point p = bfs();
        out.println((p.x+1) + " " + (p.y+1));
    }
    
    private void finish() { this.out.close(); }
    
    public static void main(String[] args) { 
        R035CRetry obj = new R035CRetry();
        obj.solve();
        obj.finish();
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.LinkedList;

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader("input.txt"));
        PrintWriter out = new PrintWriter("output.txt");

        String[] raw = in.readLine().split(" ");
        int n = Integer.parseInt(raw[0]);
        int m = Integer.parseInt(raw[1]);

        int k = Integer.parseInt(in.readLine());

        raw = in.readLine().split(" ");

        boolean[][] map = new boolean[n][m];
        LinkedList<Point> queue = new LinkedList<>();

        for (int i = 0; i < k; i++) {
            Point fireStarter = new Point(Integer.parseInt(raw[i * 2]) - 1, Integer.parseInt(raw[i * 2 + 1]) - 1);

            queue.addLast(fireStarter);
        }

        int treesLeft = n * m;

        while (true) {
            Point firepoint = queue.removeFirst();

            if (map[firepoint.x][firepoint.y])
                continue;

            treesLeft--;
            map[firepoint.x][firepoint.y] = true;

            if (treesLeft == 0) {
                out.printf("%d %d", firepoint.x + 1, firepoint.y + 1);
                out.flush();
                return;
            }

            if (firepoint.x > 0 && !map[firepoint.x - 1][firepoint.y])
                queue.add(new Point(firepoint.x - 1, firepoint.y));

            if (firepoint.y > 0 && !map[firepoint.x][firepoint.y - 1])
                queue.add(new Point(firepoint.x, firepoint.y - 1));

            if (firepoint.x < n - 1 && !map[firepoint.x + 1][firepoint.y])
                queue.add(new Point(firepoint.x + 1, firepoint.y));

            if (firepoint.y < m - 1 && !map[firepoint.x][firepoint.y + 1])
                queue.add(new Point(firepoint.x, firepoint.y + 1));

//
//            for (int i = 0; i < n; i++) {
//                for (int j = 0; j < m; j++) {
//                    System.out.printf("%d ", map[i][j] ? 1 : 0);
//                }
//                System.out.println();
//            }
//            System.out.println("\n-------\n");
        }
    }

    private static class Point {
        public int x;
        public int y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic

import java.awt.Point;
import java.io.*;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

import static java.lang.Integer.*;
import static java.lang.Math.*;
@SuppressWarnings("unused")
public class round35C {
    static class state{
        int x, y, time;
        public state(int xx, int yy, int t){
            x = xx;
            y = yy;
            time = t;
        }
    }
    static int N,M;
    static int [] dx = new int [] {1,-1,0,0};
    static int [] dy = new int [] {0,0,1,-1};
    static Queue<state> bfs = new LinkedList<round35C.state>();
    public static Point runBFS(){
        boolean [][] vis = new boolean [N + 1][M + 1];
        int max = -(int)1e9;
        int bestx = -1;
        int besty = -1;
        while(!bfs.isEmpty()){
            state p = bfs.poll();
            int x = p.x;
            int y = p.y;
            int time = p.time;
            if(vis[x][y])
                continue;
            vis[x][y] = true;
            if(time > max){
                max = time;
                bestx = x + 1;
                besty = y + 1;
            }
            for(int i = 0 ; i < 4 ; ++i){
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(nx < 0 || ny < 0 || nx >= N || ny >= M)
                    continue;
                if(vis[nx][ny] == false)
                    bfs.offer(new state(nx, ny, time + 1));
            }
        }
        return new Point(bestx, besty);
    }
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("input.txt"));
        PrintWriter out = new PrintWriter("output.txt");
        String [] use = null;
        use = br.readLine().split(" ");
        N = parseInt(use[0]);
        M = parseInt(use[1]);
        int K = parseInt(br.readLine());
        use = br.readLine().split(" ");
        for(int i = 0 ; i < 2 * K ; i += 2){
            int f = parseInt(use[i]) - 1;
            int t = parseInt(use[i + 1]) - 1;
            bfs.offer(new state(f, t, 0));
        }
        Point ans = runBFS();
        out.println(ans.x + " " + ans.y);
        out.flush();
        out.close();
    }

}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution implements Runnable {
  BufferedReader in;
  PrintWriter out;
  StringTokenizer tok = new StringTokenizer("");

  @Override
  public void run() {
    try {
      init();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    long time = System.currentTimeMillis();
    try {
      solve();
    } catch (Exception e) {
      e.printStackTrace();
    }
    out.close();
    //System.err.println(System.currentTimeMillis() - time);
  }

  private void init() throws FileNotFoundException {
    String file = "123";
    if (!file.equals("")) {
      in = new BufferedReader(new FileReader("input.txt"));
      out = new PrintWriter("output.txt");
    } else {
      in = new BufferedReader(new InputStreamReader(System.in));
      out = new PrintWriter(System.out);
    }
  }

  public static void main(String[] args) {
    new Thread(new Solution()).start();
  }

  private String readString() {
    while (!tok.hasMoreTokens()) {
      try {
        tok = new StringTokenizer(in.readLine());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return tok.nextToken();
  }

  private int readInt() {
    return Integer.parseInt(readString());
  }

  int[] counts = new int[1000];

  private long readLong() {
    return Long.parseLong(readString());
  }

  private void solve() {
    int n = readInt()+2;
    int m = readInt()+2;
    boolean[][] graph = new boolean[n][m];
    for (int i = 0; i < n; i++) {
      graph[i][m-1] = true;
      graph[i][0] = true;
    }
    for (int i = 0; i < m; i++) {
      graph[n-1][i] = true;
      graph[0][i] = true;
    }
    int k = readInt();
    int inFire = 0;
    Queue<Point> q = new ArrayDeque<>();
    for (int i = 0; i < k; i++) {
      int x = readInt();
      int y = readInt();
      Point p = new Point(x, y);
      graph[x][y] = true;
      q.add(p);
    }
    while (!q.isEmpty()) {
      Point current = q.poll();
      inFire++;
      if(!graph[current.x+1][current.y]) {
        graph[current.x+1][current.y] = true;
        q.add(new Point(current.x+1, current.y));
      }
      if(!graph[current.x-1][current.y]) {
        graph[current.x-1][current.y] = true;
        q.add(new Point(current.x-1, current.y));
      }
      if(!graph[current.x][current.y+1]) {
        graph[current.x][current.y+1] = true;
        q.add(new Point(current.x, current.y+1));
      }
      if(!graph[current.x][current.y-1]) {
        graph[current.x][current.y-1] = true;
        q.add(new Point(current.x, current.y-1));
      }
      if(q.isEmpty()) {
        out.print(current.x+" "+current.y);
        return;
      }
    }


  }

  class Point{
    int x, y;

    public Point(int x, int y) {
      this.x = x;
      this.y = y;
    }
  }
}