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

import static java.lang.Math.abs;

/**
 * 35C
 *
 * @author artyom
 */
public class FireAgain implements Runnable {
    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok;

    private void solve() throws IOException {
        int n = nextInt(), m = nextInt();
        int[][] sources = readIntMatrix(nextInt(), 2);
        int max = -1, maxI = 0, maxJ = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int min = Integer.MAX_VALUE;
                for (int[] source : sources) {
                    int dist = abs(source[0] - i) + abs(source[1] - j);
                    if (dist < min) {
                        min = dist;
                    }
                }
                if (min > max) {
                    max = min;
                    maxI = i;
                    maxJ = j;
                }
            }
        }
        out.print((maxI + 1) + " " + (maxJ + 1));
    }

    //--------------------------------------------------------------
    public static void main(String[] args) {
        new FireAgain().run();
    }

    @Override
    public void run() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
            tok = null;
            solve();
            in.close();
            out.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

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

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

    private int[][] readIntMatrix(int n, int m) throws IOException {
        int[][] mx = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                mx[i][j] = nextInt() - 1;
            }
        }
        return mx;
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		int R = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		int[] x = new int[K];
		int[] y = new int[K];
		for (int i = 0; i < K; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		int best = -1;
		int bestX = 0;
		int bestY = 0;

		for (int r = 1; r <= R; r++) for (int c = 1; c <= C; c++) {
			int here = R + C;
			for (int i = 0; i < K; i++) {
				int t = abs(r - x[i]) + abs(c - y[i]);
				here = min(here, t);
			}
			if (best < here){
				best = here;
				bestX = r;
				bestY = c;
			}
		}

		out.println(bestX + " " + bestY);
	}

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

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

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
//		sc = new MyScanner(System.in);
//		out = new PrintWriter(System.out);
		sc = new MyScanner(new FileInputStream(new File("input.txt")));
		out = new PrintWriter(new File("output.txt"));
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}
// 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.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;


public class R035C {
    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;
    int[][] iss;
    
    public R035C() {
        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(iss[nx][ny] != 0) { continue; } 
                np.count = cur.count+1;
                iss[nx][ny] = np.count;
                q.add(np);
            }
        }
        return p;
    }
    
    private void solve() {
        this.n = scanner.nextInt();
        this.m = scanner.nextInt();
        this.iss = new int[n][m];
        int k = scanner.nextInt();
        q = new PriorityQueue<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);
            iss[x][y] = 1;
        }
        Point p = bfs();
        out.println((p.x+1) + " " + (p.y+1));
    }
    
    private void finish() { this.out.close(); }
    
    public static void main(String[] args) { 
        R035C obj = new R035C();
        obj.solve();
        obj.finish();
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;

public class P035C {
    private class Pair {
        private int x;
        private int y;
        
        private Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
        
        public int hashCode() {
            return 37 * x + y;
        }
        
        public boolean equals(Object other) {
            if (other instanceof Pair) {
                Pair otherPair = (Pair)other;
                return x == otherPair.x && y == otherPair.y;
            }
            
            return false;
        }
    }
    
    private boolean[][] visited;
    private final int N;
    private final int M;
    private final int k;
    private ArrayList<Pair> fires = new ArrayList<Pair>();
    private ArrayList<Pair> neighbors = new ArrayList<Pair>();
    
    public P035C() throws IOException {
        Scanner sc = new Scanner(new File("input.txt"));

        N = sc.nextInt();
        M = sc.nextInt();
        visited = new boolean[N][M];
        k = sc.nextInt();
        for (int i = 0; i < k; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            fires.add(new Pair(x, y));
        }
        bfs();
    }
    
    private void bfs() throws IOException{
        java.util.Queue<Pair> queue = new ArrayDeque<Pair>();
        for (Pair p : fires) {
            queue.add(p);
            visited[p.x][p.y] = true;
        }
        
        Pair last = fires.get(0);
        while (!queue.isEmpty()) {
            Pair p = last = queue.poll();            
            for (Pair pn : getNeighbors(p)) {
                if (!visited[pn.x][pn.y]) {
                    queue.add(pn);
                    visited[pn.x][pn.y] = true;
                }
            }
        }
        
        PrintWriter output = new PrintWriter(new FileWriter(new File("output.txt")));
        output.printf("%d %d\n", last.x + 1, last.y + 1);
        output.close();
    }
    
    private Collection<Pair> getNeighbors(Pair p) {
        neighbors.clear();
        if (p.x > 0)   neighbors.add(new Pair(p.x-1, p.y));
        if (p.x < N-1) neighbors.add(new Pair(p.x+1, p.y));
        if (p.y > 0)   neighbors.add(new Pair(p.x, p.y-1));
        if (p.y < M-1) neighbors.add(new Pair(p.x, p.y+1));
        
        return neighbors;
    }
    
    public static void main(String[] args) throws IOException {
        P035C solution = new P035C();
    }
}
// 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.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import javafx.util.Pair;


public class FireAgain {

     static Queue q=new LinkedList<>();
     static boolean[][] fired;
     static Pair index = null;
    public static void main(String[] args) throws IOException {
        // BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          BufferedReader in=new BufferedReader(new FileReader("input.txt"));
          BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"));
         StringTokenizer s = new StringTokenizer(in.readLine());
         int n=Integer.parseInt(s.nextToken());
         int m=Integer.parseInt(s.nextToken());
         fired=new boolean[n][m];
         Pair result=null;
         s = new StringTokenizer(in.readLine());
         int firenum=Integer.parseInt(s.nextToken());
         s = new StringTokenizer(in.readLine());
         int i;
         ArrayList<Integer> tree=new ArrayList<>();
         for(i=0;i<firenum*2;i++){
             tree.add(Integer.parseInt(s.nextToken())-1);
         }
        for(i=0;i<2*firenum-1;i+=2){
           fired[tree.get(i)][tree.get(i+1)]=true;
           q.add(new Pair(tree.get(i),tree.get(i+1)));
        }
        index=(Pair) q.peek();
         result=bfs((int)index.getKey(),(int)index.getValue(),n,m);
       int x1=(int)result.getKey()+1;
       int x2=(int)result.getValue()+1;
        String str = x1 + " " + x2;
        writer.write(str);

        writer.close();
    }
    public static Pair bfs(int x,int y,int xmax,int ymax){
        fired[x][y]=true;
        while(!q.isEmpty()){
            index=(Pair) q.poll();
            int i=(int) index.getKey();
            int j=(int) index.getValue();
            if(i-1>=0){
                if(!fired[i-1][j]){
                fired[i-1][j]=true;
                q.add(new Pair((i-1),j));
                }
            }if(j-1>=0){
                if(!fired[i][j-1]){
                fired[i][j-1]=true;
                q.add(new Pair(i,(j-1)));
                }
            } if(i+1<xmax){
                if(!fired[i+1][j]){
                fired[i+1][j]=true;
                q.add(new Pair(i+1,j));
                }
            } if(j+1<ymax){
                if(!fired[i][j+1]){
                fired[i][j+1]=true;
                q.add(new Pair(i,j+1));
                }
            }
        }    
         return index;   
            
            
    }
    
    
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;

public class C {

	void run() throws IOException {
		int n = ni(), m = ni(), k = ni(), q = n * m, h = 0, t = 0, inf = 123456;
		int[] x = new int[q], y = new int[q];
		int[][] d = new int[n][m];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				d[i][j] = inf;
		for (int i = 0; i < k; i++) {
			int u = ni() - 1, v = ni() - 1;
			d[u][v] = 0;
			x[t] = u;
			y[t] = v;
			t++;
		}
		if (k < q)
			while (t != h) {
				int u = x[h], v = y[h];
				int l = d[u][v] + 1;
				h++;
				if (u > 0 && d[u - 1][v] > l) {
					d[u - 1][v] = l;
					x[t] = u - 1;
					y[t] = v;
					t++;
				}
				if (u < n - 1 && d[u + 1][v] > l) {
					d[u + 1][v] = l;
					x[t] = u + 1;
					y[t] = v;
					t++;
				}
				if (v > 0 && d[u][v - 1] > l) {
					d[u][v - 1] = l;
					x[t] = u;
					y[t] = v - 1;
					t++;
				}
				if (v < m - 1 && d[u][v + 1] > l) {
					d[u][v + 1] = l;
					x[t] = u;
					y[t] = v + 1;
					t++;
				}
			}
		int max = 0, tx = 0, ty = 0;

		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				if (d[i][j] > max) {
					max = d[i][j];
					tx = i;
					ty = j;

				}
		pw.print(1 + tx + " " + (1 + ty));
	}

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

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

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

	PrintWriter pw;
	BufferedReader br;
	StringTokenizer st;

	public static void main(String[] args) throws IOException {
		BufferedReader _br = new BufferedReader(new FileReader(new File("input.txt")));
		PrintWriter _pw = new PrintWriter(new FileWriter(new File("output.txt")));
		new C(_br, _pw).run();
		_br.close();
		_pw.close();
	}

	public C(BufferedReader _br, PrintWriter _pw) {
		br = _br;
		pw = _pw;
	}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

public class FireAgain 
{

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

	      FileInputStream in = null;
	      FileOutputStream out = null;
	
	      try 
	      {
	         in = new FileInputStream("input.txt");
	         out = new FileOutputStream("output.txt");
	         
		  		Scanner sc = new Scanner(in);

	      
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		int k = sc.nextInt();
		
		int[] xk = new int[k];
		int[] yk = new int[k];
		
		for(int i = 0; i < k; i++)
		{
			int y = sc.nextInt()-1;
			int x = sc.nextInt()-1;
			
			xk[i] = x;
			yk[i] = y;
		}

		int best = -1;
		int bestx = -1;
		int besty = -1;
		for(int x = 0; x < w; x++)
		{
			for(int y = 0; y < h; y++)
			{
				int cur = 99999;
				for(int f = 0; f < k; f++)
				{
					cur = Math.min(cur, Math.abs(xk[f] - x)+Math.abs(yk[f] - y));
				}
				
				if(cur > best)
				{
					best = cur;
					bestx = x;
					besty = y;
				}
			}
		}
		
//		System.out.println((besty+1) + " " + (bestx+1));
		String s = (besty+1) + " " + (bestx+1);

		out.write(s.getBytes());
		
	      }finally 
	      {
	         if (in != null) 
	         {
	            in.close();
	         }
	         if (out != null) 
	         {
	            out.close();
	         }
	      }		
	}

}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.File;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
 
public class C {
	Scanner in;
	PrintWriter out;
//	String INPUT = "3 3 1 1 1";
	String INPUT = "";
	
	void solve()
	{
		int n = ni();
		int m = ni();
		int k = ni();
	    int[][] f=new int[k][2];
        		
        		for(int i=0;i<k;i++) {
        			f[i][0]=ni()-1;
        			f[i][1]=ni()-1;
        		}
        		int mx=-1;
        		int resx=0;
        		int resy=0;        		
        		
        		for(int i=0;i<n;i++) {
        			for(int j=0;j<m;j++) {
        				int min=Integer.MAX_VALUE;
        				for(int l=0;l<k;l++) {
        					min=Math.min(min, Math.abs(f[l][0]-i)+Math.abs(f[l][1]-j));
        				}
        				if(min>mx) {
        					mx=min;
        					resx=i;
        					resy=j;
        				}
        			}
        			
        		}
        		out.println((resx+1)+" "+(resy+1));
        		
	}

	void run() throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(new File("input.txt")) : new Scanner(INPUT);
		out = INPUT.isEmpty() ? new PrintWriter("output.txt") : new PrintWriter(System.out);
 
		solve();
		out.flush();
	}
	
	
	public static void main(String[] args) throws Exception
	{
		new C().run();
	}
	
	int ni() { return Integer.parseInt(in.next()); }
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }
	static String join(int[] a, int d){StringBuilder sb = new StringBuilder();for(int v : a){sb.append(v + d + " ");}return sb.toString();}
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
//package C;

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

public class Fire_Again {
    static int N;
    static int M;
    static int K;
    private class Pos {
        public int r;
        public int c;
        int last;
        public Pos(int r,int c, int last) {
            this.r = r;
            this.c = c;
            this.last = last;
        }
    }
    static ArrayList<Pos> pos = new ArrayList<>();

    static boolean[][] used;// = new boolean[2001][2001];
    static int[] rows = {-1,1,0,0};
    static int[] cols = {0,0,-1,1};
    int LAST = 0;
    int lastRow = 1;
    int lastCol = 1;
    public static void main(String[] args) throws IOException {
        Fire_Again fire_again = new Fire_Again();
        BufferedReader bufferedReader =
                new BufferedReader(new FileReader("input.txt"));
        String[] nm = bufferedReader.readLine().split(" ");
        N = Integer.parseInt(nm[0]) + 1;
        M = Integer.parseInt(nm[1]) + 1;
        K = Integer.parseInt(bufferedReader.readLine());
        used = new boolean[N][M];
        String[] rc = bufferedReader.readLine().split(" ");
        for(int k = 0;k < rc.length;k+=2) {
            int r = Integer.parseInt(rc[k]);
            int c = Integer.parseInt(rc[k+1]);
            pos.add(fire_again.new Pos(r,c,0));
        }
        fire_again.bfs();
        PrintStream ps = new PrintStream("output.txt");
        ps.printf("%d %d\n",fire_again.lastRow,fire_again.lastCol);
        ps.flush();
        ps.close();
    }
     Queue<Pos> queue = new LinkedList<>();
    private void bfs() {
      queue.addAll(pos);
      for(Pos p : pos) {
          used[p.r][p.c] = true;
        //  System.out.println("r = "+(p.r) + " c = " + (p.c));
      }
      while(!queue.isEmpty()) {
          Pos p = queue.poll();
          if(p.last > LAST) {
              LAST = p.last;
              lastRow = p.r;
              lastCol = p.c;
          }
          for(int i = 0;i < rows.length;i++) {
              int currR = p.r;
              int currC = p.c;
              if(currR + rows[i] >= 1 && currR + rows[i] < N &&
              currC + cols[i] >= 1 && currC + cols[i] < M &&
              !used[currR + rows[i] ] [currC + cols[i] ] ) {
              //    System.out.println("r = "+(currR+rows[i]) + " c = " + (currC+cols[i]));
                  queue.add(new Pos(currR+rows[i],currC+cols[i],p.last+1));
                  used[currR + rows[i] ] [currC + cols[i] ] = true;
              }
          }
      }

    }

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


public class C {
    private static boolean marked[][] ; 
    
    
    public static void main(String[] args) throws Exception {
//        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//        InputStream inputStream = System.in;
//        OutputStream outputStream = System.out;
//        InputReader s = new InputReader(inputStream);
//        PrintWriter out = new PrintWriter(outputStream);
        
        
         // input.txt / output.txt
         File file = new File("input.txt") ; 
         Scanner s = new Scanner(file) ; 
        
        int n = s.nextInt();
        int m = s.nextInt(); 
        
        marked = new boolean [n + 1 ][m + 1] ; 
        
        int k = s.nextInt();
        
        Queue<Point> queue = new LinkedList<Point>(); 
        
        
        for(int i =0 ; i < k ; ++i){
            int tempX = s.nextInt() ;
            int tempY = s.nextInt() ; 
            marked[tempX][tempY] = true ; 
            queue.add(new Point(tempX , tempY));             
        }
        
         Point c = null ;
        
         while(!queue.isEmpty()){
             c = queue.poll() ; 
            
            if(c.x>1 && !marked[c.x-1][c.y]){
                marked[c.x -1 ][c.y] = true ; 
                queue.add(new Point(c.x-1,c.y));
            }
            
            if(c.y>1 && !marked[c.x][c.y-1]){
                marked[c.x][c.y-1] = true ; 
                queue.add(new Point(c.x,c.y-1));
            }
            
            if(c.x < n  && !marked[c.x+1][c.y]){
                marked[c.x + 1 ][c.y] = true ; 
                queue.add(new Point(c.x + 1,c.y));
            }
            
            if(c.y < m && !marked[c.x][c.y+1]){
                marked[c.x][c.y+1] = true ; 
                queue.add(new Point(c.x,c.y+1));
            }
        }
        PrintWriter out = new PrintWriter(new File("output.txt"));
        out.println(c.x+" "+c.y); 
        out.close();

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


class InputReader {

    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

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

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