codeparrot/codecomplex huggingface dataset:
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*; 
import java.util.*;
import java.util.regex.*;
/*
	  br = new BufferedReader(new FileReader("input.txt"));
	  pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
	  br = new BufferedReader(new InputStreamReader(System.in));
	  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */


public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	public static void main(String[] args) throws Exception {
		br = new BufferedReader(new FileReader("input.txt"));
		pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++)	{
			int r = readInt();
			int c = readInt();
			int n = readInt();
			int[][] dist = new int[r][c];
			for(int i = 0; i < r; i++) {
				Arrays.fill(dist[i], 1 << 25);
			}
			LinkedList<State> q = new LinkedList<State>();
			while(n-- > 0) {
				q.add(new State(readInt()-1, readInt()-1));
				dist[q.peekLast().x][q.peekLast().y] = 0;
			}
			int[] dx = new int[]{-1,1,0,0};
			int[] dy = new int[]{0,0,-1,1};
			State ret = q.peekLast();
			while(!q.isEmpty()) {
				State curr = q.removeFirst();
				ret = curr;
				for(int k = 0; k < dx.length; k++) {
					int nx = curr.x + dx[k];
					int ny = curr.y + dy[k];
					if(nx >= 0 && nx < r && ny >= 0 && ny < c && dist[nx][ny] > 1 + dist[curr.x][curr.y]) {
						dist[nx][ny] = 1 + dist[curr.x][curr.y];
						q.add(new State(nx, ny));
					}
				}
			}
			pw.println(ret.x+1 + " " + (ret.y+1));
		}
		exitImmediately();
	}

	static class State {
		public int x,y;

		public State(int x, int y) {
			super();
			this.x = x;
			this.y = y;
		}
		
	}
	
	private static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	private static long readLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private static double readDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private static String nextLine() throws IOException  {
		if(!br.ready()) {
			exitImmediately();
		}
		st = null;
		return br.readLine();
	}

	private static String nextToken() throws IOException  {
		while(st == null || !st.hasMoreTokens())  {
			if(!br.ready()) {
				exitImmediately();
			}
			st = new StringTokenizer(br.readLine().trim());
		}
		return st.nextToken();
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) throws IOException {
		File f = new File("input.txt");
		Scanner sc = new Scanner(f);
		BufferedWriter bw = new BufferedWriter(new FileWriter(new File("output.txt")));
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[][] grid = new boolean[n][m];
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) 
			grid[i][j] = false;
		Queue<Pair> q = new LinkedList<>();
		int cnt = sc.nextInt();
		for (int i = 0; i < cnt; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			x--;
			y--;
			grid[x][y] = true;
			q.add(new Pair(x, y));
		}
		Pair last = new Pair(-1, -1);
		while (!q.isEmpty()) {
			Pair current = q.poll();
			last = current;
			for (int i = -1; i <= 1; i++) {
				for (int j = -1; j <= 1; j++) {
					if (i != 0 && j != 0) continue;
					if (inside(current.x + i, current.y + j, n, m) &&
							!grid[current.x + i][current.y + j]) {
						grid[current.x + i][current.y + j] = true;
						q.add(new Pair(current.x + i, current.y + j));
						//bw.append((current.x + i) + " " + (current.y + j) + "\n");
					}
				}
			}
		}
		
		bw.append((last.x + 1) + " " + (last.y + 1) + "\n");
		bw.flush();
		bw.close();
		
		sc.close();
	}
	static class Pair {
		int x;
		int y;
		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
	private static boolean inside(int a, int b, int n, int m) {
		return (a >= 0 && a < n && b >= 0 && b < m);
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.util.*;
import java.io.*;

public class C {

	private static int[] dx = {1, -1, 0, 0};
	private static int[] dy = {0, 0, -1, 1};

	public static void main(String[] args) throws Exception{
		Thread t = new Thread(null, null, "~", Runtime.getRuntime().maxMemory()){
			@Override
			public void run(){
				try {
					solve();
				} catch(Exception e) {
					System.err.println("ERROR");
				}
			}
		};

		t.start();
		t.join();	
	}

	public static void solve() throws Exception {
		Scanner in = new Scanner(new File("input.txt"));
		PrintWriter out = new PrintWriter(new File("output.txt"));

		int n = in.nextInt();
		int m = in.nextInt();

		int[][] time = new int[n][m];
		for(int i = 0; i < n; ++i) {
			Arrays.fill(time[i], Integer.MAX_VALUE);
		}

		int qq = in.nextInt();
		int[] xs = new int[qq];
		int[] ys = new int[qq];

		for(int i = 0; i < qq; ++i){
			xs[i] = in.nextInt() - 1;
			ys[i] = in.nextInt() - 1;
		}


		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < m; ++j) {
				for(int k = 0; k < qq; ++k) {
					int dist = Math.abs(i - xs[k]) + Math.abs(j - ys[k]);
					time[i][j] = Math.min(time[i][j], dist);
				}
			}
		}

		int max = -1;
		int x = -1;
		int y = -1;

		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < m; ++j) if(max < time[i][j]) {

				max = time[i][j];
				x = i + 1;
				y = j + 1;
			} 
		}

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

		out.flush();
		out.close();
	}

	private static class Pair {
		int f, s;
		int time;

		public Pair(int f, int s) {
			this.f = f;
			this.s = s;
		}

		public Pair(int f, int s, int time) {
			this(f, s);
			this.time = time;
		}

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

public class C {
	public static void main(String[] args) throws Exception {
		File in = new File("input.txt"), out = new File("output.txt");
		Scanner s;
		PrintWriter pw;
		if (in.exists()) {
			s = new Scanner(in);
			pw = new PrintWriter(out);
		} else {
			s = new Scanner(System.in);
			pw = new PrintWriter(System.out);
		}
		int n = s.nextInt(), m = s.nextInt();
		int k = s.nextInt();
		List<int[]> list = new ArrayList<int[]>();
		for (int t = 0; t < k; ++t) {
			list.add(new int[] { s.nextInt() - 1, s.nextInt() - 1 });
		}
		int max = 0, mi = 1, mj = 1;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				int min = Integer.MAX_VALUE;
				for (int[] p : list) {
					min = Math.min(min, Math.abs(i - p[0]) + Math.abs(j - p[1]));
				}
				if (min > max) {
					max = Math.max(max, min);
					mi = i + 1;
					mj = j + 1;
				}
			}
		}
		pw.println(mi + " " + mj);
		pw.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.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	static int[] di = {-1,0,1,0};
	static int[] dj = {0,1,0,-1};
	public static void main(String[] args) throws IOException 
	{
		Scanner sc = new Scanner("input.txt");
		PrintWriter out = new PrintWriter("output.txt");
		Queue<Pair> q = new LinkedList<Pair>();
		int n = sc.nextInt(),m = sc.nextInt() , k = sc.nextInt();
		boolean [][] vis = new boolean[n][m];
		while(k-->0)
			q.add(new Pair(sc.nextInt()-1,sc.nextInt()-1));
	
		int ansX = 1 , ansY = 1;
		
		while(!q.isEmpty())
		{
			Pair cur = q.poll();
			if(vis[cur.i][cur.j])continue;
			ansX = cur.i ; ansY = cur.j;
			vis[cur.i][cur.j] = true;
			for (int i = 0; i < di.length; i++) {
				int ni = cur.i + di[i] , nj = cur.j + dj[i];
				if(ni>=0 && ni<n && nj>=0 && nj<m && !vis[ni][nj])
					q.add(new Pair(ni,nj));
			}
		}
		
		out.append(++ansX+" "+ ++ansY);
		out.flush();
		
	}
	static class Pair
	{
		int i,j;
		public Pair(int a,int b) {
			i = a; j = b;
		}
	}
	
	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 String nextLine() throws IOException {return br.readLine();}		
		public long nextLong() throws IOException {return Long.parseLong(next());}		
		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.math.*;
import java.io.*;

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

		int N=c.nextInt();
		int M=c.nextInt();
		int A[][]=new int[N][M];
		for(int i=0;i<N;i++)
			Arrays.fill(A[i],Integer.MAX_VALUE/100);
		int K=c.nextInt();
		for(int i=0;i<K;i++)
			{
			int x=c.nextInt()-1;
			int y=c.nextInt()-1;
			for(int i1=0;i1<N;i1++)
				{
				for(int j1=0;j1<M;j1++)
					A[i1][j1]=Math.min(A[i1][j1],Math.abs(i1-x)+Math.abs(j1-y));
				}
			}
		int maxi=0;
		int maxj=0;
		for(int i=0;i<N;i++)
			{
			for(int j=0;j<M;j++)
				{
				if(A[i][j]>A[maxi][maxj])
					{
					maxi=i;
					maxj=j;
					}
				}
			}
		out.println((maxi+1)+" "+(maxj+1));
		out.close();
		}
	}

//must declare new classes here
// Problem: 35_C. Fire Again
// Time complexity: cubic

import java.awt.Point;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class FireAgain {

    int k, i, j,n,m,x,y;
    void run() {
        try {
            BufferedReader bfd = new BufferedReader(new FileReader("input.txt"));
            BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
//          BufferedReader bfd = new BufferedReader(new InputStreamReader(System.in));
            StringTokenizer tk = new StringTokenizer(bfd.readLine());
            
            n = Integer.parseInt(tk.nextToken());
            m = Integer.parseInt(tk.nextToken());
            boolean vis[][] = new boolean[n][m];
            k = Integer.parseInt(bfd.readLine());
            tk = new StringTokenizer(bfd.readLine());
            Queue<Point> q = new LinkedList<Point>();
            Point last = new Point(0,0);
            while(k-->0){
                x = Integer.parseInt(tk.nextToken())-1;
                y = Integer.parseInt(tk.nextToken())-1;
                q.add(new Point(x,y));
                vis[x][y] = true;
            }
            while(!q.isEmpty()) {
                Point frnt = q.poll();
                for(i=frnt.x-1;i<=frnt.x+1;++i)
                    for(j=frnt.y-1;j<=frnt.y+1;++j)
                        if(val(i,j)&& !vis[i][j]&&(frnt.x==i||frnt.y==j)){
                            q.add(new Point(i,j));
                            last = new Point(i,j);
                            vis[i][j] = true;
                        }
            }
//          System.out.println(last.x+1 + " " +(last.y+1));
            out.write(last.x+1 + " " +(last.y+1)+"\n");
            out.flush();
            out.close();
        } catch (Exception e) {

        }
    }
    
    boolean val(int x,int y){
        return x>=0&&x<n&&y>=0&&y<m;
    }
    public static void main(String[] args) {
        new FireAgain().run();
    }

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

import java.awt.Point;
import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class BetaRound35_C implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws IOException {
		in = new BufferedReader(new FileReader("input.txt"));
		out = new PrintWriter("output.txt");
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

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

	@Override
	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	public static void main(String[] args) {
		new Thread(new BetaRound35_C()).start();
	}
	
	void solve() throws IOException {
		int n = readInt();
		int m = readInt();
		int k = readInt();
		Queue<Point> q = new ArrayDeque<Point>();
		boolean[][] visited = new boolean[n + 2][m + 2];
		for (int j = 0; j < m + 2; j++) {
			visited[0][j] = true;
			visited[n + 1][j] = true;
		}
		for (int i = 0; i < n + 2; i++) {
			visited[i][0] = true;
			visited[i][m + 1] = true;
		}
		for (int i = 0; i < k; i++) {
			int x = readInt();
			int y = readInt();
			q.add(new Point(x, y));
			visited[x][y] = true;
		}
		
		Point p = null;
		while (!q.isEmpty()) {
			p = q.poll();
			int x = p.x, y = p.y;
			if (!visited[x + 1][y]) {
				q.add(new Point(x + 1, y));
				visited[x + 1][y] = true;
			}
			if (!visited[x - 1][y]) {
				q.add(new Point(x - 1, y));
				visited[x - 1][y] = true;
			}
			if (!visited[x][y + 1]) {
				q.add(new Point(x, y + 1));
				visited[x][y + 1] = true;
			}
			if (!visited[x][y - 1]) {
				q.add(new Point(x, y - 1));
				visited[x][y - 1] = true;
			}
		}
		out.print(p.x + " " + p.y);
	}
	
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;

/**
 * Created by tmdautov on 07.02.18.
 */
public class ArFireAgain {


    int n, m, k;
    int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
    int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };

    int[][] dist;
    ArrayList<Pair> arr;
    // res -> get coordinates of most remote tree

    Scanner sc;
    PrintWriter out;

    public void solve() {

        try {
            sc = new Scanner(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();

        arr = new ArrayList<Pair>();

        for (int i=0; i<k; i++) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            Pair p = new Pair(x, y);
            arr.add(p);
        }


        //out.println("helll");
        Pair last = bfs();
        out.println(last.x + " " + last.y);
        out.flush();
        out.close();
    }


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

    private Pair bfs() {
        // 1. create objects
        Queue<Pair> q = new LinkedList<Pair>();
        dist = new int[n][m];

        // 2. fill dist array with -1
        for (int i=0; i<n; i++) {
            for (int j=0; j<m; j++) {
                dist[i][j] = -1;
            }
        }

        // 3. fill queue with fired k-trees
        for (int i=0; i<k; i++) {
            dist[arr.get(i).x][arr.get(i).y] = 0; // dist to fired trees is 0
            q.add(arr.get(i));
        }

        // 4. run bfs
        while(!q.isEmpty()) {
            Pair cur = q.remove();

            for (int d=0; d<4; d++) {
                int X = cur.x + dx[d];
                int Y = cur.y + dy[d];

                if (isValid(X, Y) && dist[X][Y] == -1) {
                    dist[X][Y] = dist[cur.x][cur.y] + 1;
                    Pair p = new Pair(X, Y);
                    q.add(p);
                }
            }

            //System.out.println(cur);
        }

        // 5. find max pair by dist array
        Pair res = null;
        int maxx = -1;
        for (int i=0; i<n; i++) {
            for (int j=0; j<m; j++) {
                if (dist[i][j] > maxx) {
                    maxx = dist[i][j];
                    res = new Pair(i+1, j+1);
                }
            }
        }

        return res;
    }


    // how to sort array of pairs?
    class Pair {
        int x, y;
        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public static void main(String[] args) {
        new ArFireAgain().solve();
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.File;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public String[][] a;
	public void run () throws Exception {
		Scanner in = new Scanner(new File("input.txt"));
		PrintWriter pw = new PrintWriter(new  File("output.txt"));

		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		
		int[] xx = new int[k];
		int[] yy = new int[k];
		for(int i=0;i<k;i++){
			xx[i] = in.nextInt();
			yy[i]= in.nextInt();
		}
		int x=0,y=0,r;
		r=-1;
		
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++){
				int rr = 1000000;
				for(int q=0;q<k;q++)
					rr = Math.min(rr, Math.abs(xx[q]-1-i)+Math.abs(yy[q]-1-j));
				if(rr>r){
					r=rr;
					x=i;
					y=j;
				}
			}
		pw.print((x+1)+" "+(y+1));

		pw.close();
	}
	public static void main(String[] args) throws Exception {
		new Main ().run();
	}

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

// :%s/Cbeta35/"name"/
// if (debug) 

public class Cbeta35 {
	public static void main(String[] args) { new Cbeta35(); }
	Scanner in;
	PrintWriter out;

	int t;
	int n, m, k, oo;
	int[][] grid;

	boolean debug = !true, multi = !true;

	Cbeta35() {
		if (multi) t = in.nextInt();
		do {
			if (multi) if (z(t--)) break;

			try {
				in = new Scanner(new File("input.txt"));
				out = new PrintWriter(new File("output.txt"));
			}
			catch (Exception e) {
				in = new Scanner(System.in);
				out = new PrintWriter(System.out);
			}

			n = in.nextInt();
			m = in.nextInt();
			k = in.nextInt();

			oo = n + m + 1;
			grid = new int[n][m];
			for (int i = 0; i < n; i++)
				Arrays.fill(grid[i], oo);
			for (int i = 0; i < k; i++) {
				int x = in.nextInt() - 1;
				int y = in.nextInt() - 1;
				for (int j = 0; j < n; j++)
					for (int kk = 0; kk < m; kk++) {
						int dx = j - x < 0 ? x - j : j - x;
						int dy = kk - y < 0 ? y - kk : kk - y;
						grid[j][kk] = min(grid[j][kk], dx + dy);
					}
			}

			int x = 0, y = 0;
			int max = 0;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++)
					if (max < grid[i][j]) {
						max = grid[i][j];
						x = i; y = j;
					}
			out.printf("%d %d%n", x + 1, y + 1);

		} while (debug || multi);
		out.close();
	}

	

	int min(int a, int b) { if (a < b) return a; return b; }	
	int max(int a, int b) { if (a > b) return a; return b; }	
	long min(long a, long b) { if (a < b) return a; return b; }	
	long max(long a, long b) { if (a > b) return a; return b; }	

	boolean z(int x) { if (x == 0) return true; return false; }	
	boolean z(long x) { if (x == 0) return true; return false; }	

	void sort(int[] arr) {
		int szArr = arr.length;
		Random r = new Random();
		for (int i = 0; i < szArr; i++) {
			int j = r.nextInt(szArr);
			arr[i] = arr[j]^(arr[i]^(arr[j] = arr[i]));
		}
		Arrays.sort(arr);
	}

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author madis
 */
public class Pjar {

    static int a[][];

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

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

        a = new int[N][M];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                a[i][j] = Integer.MAX_VALUE;
            }
        }
        int k = in.nextInt();
        in.nextLine();
        for (int i = 0; i < k; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            a[x - 1][y - 1] = 1;
            burn(x - 1, y - 1);
        }
        int max = Integer.MIN_VALUE;
        int x = 0;
        int y = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                if(a[i][j]>max){
                    max = a[i][j];
                    x = i+1;
                    y = j+1;
                }
            }
        }
        out.printf("%d %d",x,y);
        out.close();
        in.close();
    }

    static void burn(int i, int j) {
        for(int k = 0;k<a.length;k++){
            for(int l=0;l<a[k].length;l++){
                if(a[k][l]>Math.abs(k-i) + Math.abs(l-j)){
                    a[k][l]=Math.abs(k-i) + Math.abs(l-j);
                }
            }
        }
    }
}