codeparrot/codecomplex huggingface dataset:
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.util.ArrayDeque;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Zyflair Griffane
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		PandaScanner in = new PandaScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		C solver = new C();
		solver.solve(1, in, out);
		out.close();
	}
}

class C {
    final int dx[] = { -1, 0, 1, 0};
    final int dy[] = { 0, -1, 0, 1};
    final int SHIFT = 15;
    final int COLUMN_MASK = (1 << SHIFT) - 1;
    public void solve(int testNumber, PandaScanner in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        boolean burning[][] = new boolean[n][m];
        int k = in.nextInt();
        ArrayDeque<Integer> q = new ArrayDeque<>();
        for (int i = 0; i < k; i++) {
            int x = in.nextInt() - 1;
            int y = in.nextInt() - 1;
            burning[x][y] = true;
            q.add((x << SHIFT) + y);
        }
        int last = 0;
        while (!q.isEmpty()) {
            last = q.poll();
            int x = last >> SHIFT;
            int y = last & COLUMN_MASK;
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d];
                int ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && !burning[nx][ny]) {
                    burning[nx][ny] = true;
                    q.add((nx << SHIFT) + ny);
                }
            }
        }
        out.printf("%d %d\n", (last >> SHIFT) + 1, (last & COLUMN_MASK) + 1);
    }
}

class PandaScanner {
    public BufferedReader br;
    public StringTokenizer st;
    public InputStream in;

    public PandaScanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(this.in = in));
    }

    public String nextLine() {
        try {
            return br.readLine();
        }
        catch (Exception e) {
            return null;
        }
    }

    public String next() {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(nextLine().trim());
            return next();
        }
        return st.nextToken();
    }

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

    }
// Problem: 35_C. Fire Again
// Time complexity: cubic
 
import java.util.ArrayList;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.*;
 public class Main {


    public static void main(String[] args) throws NumberFormatException, IOException 
    {
        Scanner sc = new Scanner(new File("input.txt"));
        
        int n = sc.nextInt();
        int m =sc.nextInt();
        sc.nextLine();
        int k =sc.nextInt();
        int les[][] = new int[n][m];
        PrintWriter out = new PrintWriter(new FileWriter("output.txt")); 
        //sc.nextLine();
        ArrayList<Integer[]> list = new ArrayList();
        sc.nextLine();
        for(int i = 0;i<k;i++)
        {
            
            Integer[] ii = new Integer[2];
            ii[0] = sc.nextInt()-1;
            ii[1] = sc.nextInt()-1;
            list.add(ii);
            
        }
        sc.close(); 
        int maxr = 0;
        int maxi = 0;
        int maxj = 0;
        for(int i = 0;i<n;i++)
        {
            for(int j = 0;j<m;j++)
            {
                int minr = 100000;
                int mini = 0;
                int minj = 0;
                for(int f = 0;f<k;f++)
                {
                    Integer[] ii = list.get(f);
                    int ww = Math.abs(ii[0] - i);
                    int hh = Math.abs(ii[1] - j);
                    int r = ww+hh;
                    if(r<minr)
                    {
                        minr = r;
                        mini=i;
                        minj=j;
                    }
                    
                }
                if(maxr<minr&&minr<100000)
                {
                    maxi = mini;
                    maxj = minj;
                    maxr = minr;
                }
            }
        }
        
        out.print((maxi+1)+" "+(maxj+1));
        out.close();
        
    }
    
    


    
    
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.util.*;
import java.io.*;

public class C{
	public static void main(String args[]) throws Exception{
		Scanner in = new Scanner(new FileReader("input.txt"));
		PrintWriter out = new PrintWriter(new File("output.txt"));

		int N = in.nextInt();
		int M = in.nextInt();
		int K = in.nextInt();

		int[] X = new int[K], Y = new int[K];
		for (int i = 0; i < K; i++){
			X[i] = in.nextInt();
			Y[i] = in.nextInt();
		}

		int d = -1;
		int a = -1; int b = -1;
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= M; j++){
				int h = Integer.MAX_VALUE;
				for (int p = 0; p < K; p++)
					h = Math.min(h,Math.abs(i-X[p]) + Math.abs(j-Y[p]));
				if (h > d){
					d = h; a = i; b = j;
				}
			}


		out.print(a + " " + b);
		out.close();
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;

public class Main implements Runnable {

	public void _main() throws IOException {
		int height = nextInt();
		int width = nextInt();		
		int k = nextInt();
		int[] r = new int[k];
		int[] c = new int[k];
		for (int i = 0; i < k; i++) {
			r[i] = nextInt() - 1;
			c[i] = nextInt() - 1;			
		}
		int res = 0, R = r[0], C = c[0];
		for (int i = 0; i < height; i++)
			for (int j = 0; j < width; j++) {
				int cur = Integer.MAX_VALUE;
				for (int z = 0; z < k; z++)
					cur = Math.min(cur, Math.abs(i - r[z]) + Math.abs(j - c[z]));
				if (res < cur) {
					res = cur;
					R = i;
					C = j;
				}
			}
		out.print((R + 1) + " " + (C + 1));
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

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

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

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

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

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

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new FileWriter("output.txt"));

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}
// Problem: 35_C. Fire Again
// Time complexity: cubic

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


public class C
{
   public static void main(String[] args) throws Exception
   {
      new C(new Scanner(new File("input.txt")), new PrintWriter("output.txt"));
   }

   int oo = 987654321;
   int W, H;

   public C(Scanner in, PrintWriter out)
   {
      W = in.nextInt();
      H = in.nextInt();

      int[][] grid = new int[W][H];
      for (int[] gri : grid)
         Arrays.fill(gri, oo);
   
      ArrayDeque<Node> q = new ArrayDeque<Node>();
      int K = in.nextInt();
      for (int u=0; u<K; u++)
      {
         q.add(new Node(in.nextInt()-1, in.nextInt()-1, 0));
         while (q.size() > 0)
         {
            Node cur = q.poll();
            if (grid[cur.x][cur.y] <= cur.d)
               continue;
            grid[cur.x][cur.y] = cur.d;
            if (cur.x+1<W)
               q.add(new Node(cur.x+1, cur.y, cur.d+1));
            if (cur.x>0)
               q.add(new Node(cur.x-1, cur.y, cur.d+1));
            if (cur.y+1<H)
               q.add(new Node(cur.x, cur.y+1, cur.d+1));
            if (cur.y>0)
               q.add(new Node(cur.x, cur.y-1, cur.d+1));
         }
      }

      int res = 0;
      for (int j=0; j<H; j++)
         for (int i=0; i<W; i++)
            res = Math.max(res, grid[i][j]);

      for (int j=0; j<H; j++)
         for (int i=0; i<W; i++)
            if (res == grid[i][j])
            {
               out.printf("%d %d%n", i+1, j+1);
               out.close();
               return;
            }
   }
}

class Node
{
   int x, y, d;

   public Node(int xx, int yy, int dd)
   {
      x=xx; y=yy; d=dd;
   }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.Queue;
public class Solution{
    static int[] dx = {1,-1,0,0};
    static int[] dy = {0,0,1,-1};
    static Queue<Pair> q ;
    static boolean[][] visited ;
    static Pair result = new Pair(0,0);
    static int n,m,k;
    public static void main(String[] args){
        try(BufferedReader in = new BufferedReader(new FileReader("input.txt"));
                BufferedWriter out = new BufferedWriter(new FileWriter("output.txt")))
        {
            StringTokenizer s = new StringTokenizer(in.readLine());
            n = Integer.parseInt(s.nextToken());
            m = Integer.parseInt(s.nextToken());
            k = Integer.parseInt(in.readLine());
            visited = new boolean[n][m];
            q = new LinkedList <>();
            s = new StringTokenizer(in.readLine());
            for(int i=0;i<k;i++){
                int x = Integer.parseInt(s.nextToken());
                int y = Integer.parseInt(s.nextToken());
                q.add(new Pair(--x,--y));
            }
            bfs();
            String ans = "" + (result.x+1) +" "+ (result.y+1);
            out.write(ans);
        }catch(IOException e){

        }
    }
    static void bfs(){
        while(!q.isEmpty()){
            Pair temp = q.poll();
            if(visited[temp.x][temp.y]) continue;
            visited[temp.x][temp.y] = true;
            result.x = temp.x;
            result.y= temp.y;
            for(int i=0;i<4;i++){
                int x = temp.x + dx[i];
                int y = temp.y + dy[i];
                if(x>=0 && x<n && y>=0 && y<m && !visited[x][y])
                    q.add(new Pair(x,y));
            }
            
        }
    }
    
}
class Pair{
    int x,y;
    public Pair(int x,int y){
        this.x=x;
        this.y=y;
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.awt.Point;
import java.util.LinkedList;
import java.util.Queue;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		Scanner scan = new Scanner("input.txt");
		PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
		
		int n,m;
		n = scan.nextInt();
		m = scan.nextInt();

		boolean visited[][] = new boolean[n][m];
    
		int numOfStartingPoints;
		numOfStartingPoints = scan.nextInt();
		    		
		int resX = 0, resY = 0;
		
		Queue<Point> que = new LinkedList<Point>();
		for (int i = 0; i < numOfStartingPoints; i++) {
			int x = scan.nextInt() - 1;
			int y = scan.nextInt() - 1;
			que.add(new Point(x, y));
			visited[x][y] = true;
		}
		
		while (true) {
			Point current = que.poll();

			if (current == null) {
				break;
			} else {
				resX = current.x;
				resY = current.y;
				
				if (current.x + 1 < n && !visited[current.x + 1][current.y])
				{
					que.add(new Point(current.x + 1, current.y));
					visited[current.x + 1][current.y] = true;


				}
				if (current.y + 1 < m && !visited[current.x][current.y + 1])
				{
					que.add(new Point(current.x, current.y + 1));
					visited[current.x][current.y + 1] = true;
		

				}
				if (current.x - 1 >= 0 && !visited[current.x - 1][current.y])
				{
					que.add(new Point(current.x - 1, current.y));
					visited[current.x - 1][current.y] = true;
				
				}
				if (current.y - 1 >= 0 && !visited[current.x][current.y - 1])
				{
					que.add(new Point(current.x, current.y - 1));
					visited[current.x][current.y - 1] = true;
				
				}

				
			}
		}
		
		
		out.printf("%d %d\n", ++resX, ++resY);
		out.close();
		    
	}
	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.util.*;
import java.io.*;
import java.awt.Point;

public class Main{
	public static void main(String[] args)throws FileNotFoundException,IOException{
		File file = new File("input.txt");
		Scanner sc = new Scanner(file);
		File outFile = new File("output.txt");
		PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));

		int w = sc.nextInt();
		int h = sc.nextInt();
		boolean[][] map = new boolean[h+1][w+1]; //false:�u�G�v���ĂȂ�

		int x = -1, y = -1;
		Queue<Point> open = new LinkedList<Point>();
		int k = sc.nextInt();
		for(int i=0;i<k;i++){
			int tx = sc.nextInt();
			int ty = sc.nextInt();
			map[ty][tx] = true;
			x = tx;
			y = ty;
			open.add(new Point(x,y));
		}

		int dx[] = {1,-1,0,0};
		int dy[] = {0,0,1,-1};
		while(!open.isEmpty()){
			Point p = open.poll();

			for(int i=0;i<4;i++){
				int nx = p.x + dx[i];
				int ny = p.y + dy[i];

				if(nx>0 && nx<=w && ny>0 && ny<=h && !map[ny][nx]){
					map[ny][nx] = true;
					x = nx;
					y = ny;
					open.add(new Point(nx,ny));
				}
			}
		}

		pw.println(x + " " + y);

		pw.close();
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.awt.Point;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class FireAgain {

	Point coordinate;
	Queue<Point> q = new LinkedList<Point>();
	int m, n;
	boolean[][] arr;
	PrintStream out ;

	void bfs(Point start) {

		while (!q.isEmpty()) {
			Point front = q.poll();
			Point p = new Point();

			p.x = front.x - 1;
			p.y = front.y;
			if (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1) {
				if (!arr[p.x][p.y]) {
					arr[p.x][p.y] = true;
					q.add(p);
				}
			}
			
			p = new Point();
			p.x = front.x + 1;
			p.y = front.y;
			if (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)
				if (!arr[p.x][p.y]) {
					arr[p.x][p.y] = true;
					q.add(p);
				}

			p = new Point() ;
			p.x = front.x;
			p.y = front.y + 1;
			if (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)
				if (!arr[p.x][p.y]) {
					arr[p.x][p.y] = true;
					q.add(p);
				}

			p = new Point() ;
			p.x = front.x;
			p.y = front.y - 1;
			if (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)
				if (!arr[p.x][p.y]) {
					arr[p.x][p.y] = true;
					q.add(p);
				}

			if (q.size() == 0)
				out.print(front.x + " " + front.y);
		}
	}

	/**
	 * @param args
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		FireAgain fa = new FireAgain();
		Scanner Scan = new Scanner(new FileInputStream("input.txt"));
		fa.out = new PrintStream(new File("output.txt"));
		fa.n = Scan.nextInt();
		fa.m = Scan.nextInt();
		int k = Scan.nextInt();
		fa.arr = new boolean[2001][2001];

		for (int i = 0; i < k; i++) {
			fa.coordinate = new Point();
			fa.coordinate.x = Scan.nextInt();
			fa.coordinate.y = Scan.nextInt();
			fa.q.add(fa.coordinate);
			fa.arr[fa.coordinate.x][fa.coordinate.y] = true;
		}

		fa.bfs(fa.q.peek());

	}

}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.util.*;
import java.io.*;

public class C {
	public static void main(String[] args) throws Exception {
		final int fuck = 2001;

		Scanner in = new Scanner(new File("input.txt"));
		PrintWriter out = new PrintWriter(new File("output.txt"));

		int n = in.nextInt(), m = in.nextInt();
		int[] D = new int[ fuck*fuck ],
			dx = new int[] { 1, -1, 0, 0},
			dy = new int[] { 0, 0, -1, 1};
		Arrays.fill(D, -1);

		ArrayDeque<Integer> Q = new ArrayDeque<>();
		int k = in.nextInt(), ans = 0;
		for(int i = 0; i < k; ++i) {
			int x = in.nextInt(), y = in.nextInt();
			D[ans = (x * fuck + y)] = 0;
			Q.offer(ans);
		}
		
		while(!Q.isEmpty()) {
			int idx = Q.poll();
			int x = idx / fuck, y = idx % fuck;
			for(int i = 0; i < 4; ++i) {
				int wtf = (dx[i] + x) * fuck + (dy[i] + y);
				if(dx[i] + x <= n && dx[i] + x >= 1 && dy[i] + y <= m && dy[i] + y >= 1 && D[wtf] == -1) {
					D[wtf] = D[idx] + 1;
					Q.offer(wtf);

					if(D[wtf] >= D[ans])
						ans = wtf;
				}
			}
		}

		out.println((ans / fuck) + " " + (ans % fuck));
		out.close();
		in.close();
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
		Scanner read = new Scanner(new FileInputStream(new File("input.txt")));
		PrintWriter out = new PrintWriter(new File("output.txt"));
		int n = read.nextInt(), m = read.nextInt(), k = read.nextInt(), tree[][] = new int[n][m], a[] = new int[k],
				b[] = new int[k], x = 0, y = 0, max = -1, d = 0;

		for (int i = 0; i < k; i++) {
			a[i] = read.nextInt() - 1;
			b[i] = read.nextInt() - 1;	
			tree[a[i]][b[i]] = 0;
		}
		for(int i = 0; i < n; i++){
			Arrays.fill(tree[i], Integer.MAX_VALUE);
		}
		for (int o = 0; o < k; o++) {
			for(int i = 0; i < n; i++){
				for(int j = 0; j < m; j++){
					d = Math.abs(a[o] - i) + Math.abs(b[o] - j);
					if(d < tree[i][j])
						tree[i][j] = d;
				}
			}
		}
		for(int i = 0; i<n; i++){
			for(int j = 0; j < m ; j ++){
				if(tree[i][j] > max){
					max=  tree[i][j];
					x=  i;
					y = j;
				}
			}
		}
		out.println(x + 1 + " " + (y + 1));
		out.close();
	}

}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;


public class Main {

    static boolean used[][];
    static int n;
    static int m;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new FileReader("input.txt"));
        PrintWriter out = new PrintWriter("output.txt");
        n = nextInt();
        m = nextInt();
        int k = nextInt();
        used = new boolean[n][m];
        Deque<point> deq = new ArrayDeque<>();
        for (int i = 0; i < k; i++) {
            deq.addLast(new point(nextInt() - 1, nextInt() - 1));
            used[deq.peekLast().x][deq.peekLast().y] = true;
        }
        point last = new point(0, 0);
        while (!deq.isEmpty()) {
            point v = deq.pollFirst();
            int x = v.x;
            int y = v.y;
            if (checker(x, y + 1)) {
                last = new point(x, y + 1);
                deq.addLast(new point(x, y + 1));
                used[x][y + 1] = true;
            }
            if (checker(x, y - 1)) {
                last = new point(x, y - 1);
                deq.addLast(new point(x, y - 1));
                used[x][y - 1] = true;
            }
            if (checker(x + 1, y)) {
                last = new point(x + 1, y);
                deq.addLast(new point(x + 1, y));
                used[x + 1][y] = true;
            }
            if (checker(x - 1, y)) {
                last = new point(x - 1, y);
                deq.addLast(new point(x - 1, y));
                used[x - 1][y] = true;
            }
        }
        out.println(last.x + 1 + " " + (last.y + 1));
        out.close();
    }

    static boolean checker(int x, int y) {
        if (x < n && y < m && x >= 0 && y >= 0 && !used[x][y]) return true;
        return false;
    }


    static StringTokenizer st = new StringTokenizer("");
    static BufferedReader br;

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

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

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

class point {
    int x, y;

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

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader in = new BufferedReader//(new InputStreamReader(System.in));
                                            (new FileReader("input.txt"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;
        PrintWriter pw = new PrintWriter("output.txt", "UTF-8");
        
        int [] dx = {-1,1,0,0},dy = {0,0,-1,1};
        
        tk = new StringTokenizer(in.readLine());
        int n = parseInt(tk.nextToken()),m = parseInt(tk.nextToken());
        int k = parseInt(in.readLine());
        
        int [][] dist = new int[n][m];
        for(int i=0; i<n; i++) 
            Arrays.fill(dist[i], -1);
        
        int ans = -1,atx = -1,aty = -1;
        
        Queue<point> q = new LinkedList<point>();
        
        tk = new StringTokenizer(in.readLine());
        while(k-- > 0) {
            int x = parseInt(tk.nextToken())-1,y = parseInt(tk.nextToken())-1;
            
            dist[x][y] = 0;
            q.add(new point(x,y));
        }
        
        while(!q.isEmpty()) {
            point p = q.remove();
            
            if(dist[p.x][p.y]>ans) {
                ans = dist[p.x][p.y];
                atx = p.x+1;
                aty = p.y+1;
            }
            
            for(int i=0; i<4; i++) {
                int nx = p.x + dx[i];
                int ny = p.y + dy[i];
                
                if(nx>=0 && nx<n && ny>=0 && ny<m && dist[nx][ny]==-1) {
                    dist[nx][ny] = dist[p.x][p.y] + 1;
                    q.add(new point(nx,ny));
                }
            }
        }
        
        pw.println(atx+" "+aty);
        pw.close();
    }
   
}

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