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

public class practice {

		public static void main(String[] args) throws FileNotFoundException {			
			Scanner scn = new Scanner(new FileReader("input.txt"));
			PrintWriter out = new PrintWriter(new File("output.txt"));
		 int n=scn.nextInt(),m=scn.nextInt(),k=scn.nextInt();
		 int[][] inf=new int[k][2];
		 for(int i=0;i<k;i++){
			 inf[i][0]=scn.nextInt();inf[i][1]=scn.nextInt();
		 }
		 int ans=0,x=1,y=1;
		 for(int i=1;i<=n;i++){
			 for(int j=1;j<=m;j++){
				 int temp=Integer.MAX_VALUE;
				 for(int l=0;l<k;l++){
					temp=Math.min(temp, Math.abs(i-inf[l][0])+Math.abs(j-inf[l][1])); 
				 }
				 if(temp>ans){
					 ans=temp;x=i;y=j;
				 }
			 }
		 }
		 out.print(x+ " " + y);
	   	 out.close();
		}
	}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
        PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));
        Scanner in=new Scanner(new File("input.txt"));
        int n,m,k;
        n=in.nextInt();
        m=in.nextInt();
        k=in.nextInt();
        Vector<Integer> vec=new Vector<Integer>();
        Vector<Integer> temp=new Vector<Integer>();
        boolean[][] mas=new boolean[n][m];
        long time=System.currentTimeMillis();
        for(int i=0;i<k;i++)
        {
            vec.add(in.nextInt()-1);
            vec.add(in.nextInt()-1);
            mas[vec.get(vec.size()-2)][vec.get(vec.size()-1)]=true;
        }
        int x,y;
        x=y=0;
        while(vec.size()!=0)
        {
            for(int i=0;i<vec.size();i+=2)
            {
                x=vec.get(i);
                y=vec.get(i+1);
                if(x>0 && !mas[x-1][y])
                {
                    temp.add(x-1);
                    temp.add(y);
                    mas[x-1][y]=true;
                }
                if(x<n-1 && !mas[x+1][y])
                {
                    temp.add(x+1);
                    temp.add(y);
                    mas[x+1][y]=true;
                }
                if(y>0 && !mas[x][y-1])
                {
                    temp.add(x);
                    temp.add(y-1);
                    mas[x][y-1]=true;
                }
                if(y<m-1 && !mas[x][y+1])
                {
                    temp.add(x);
                    temp.add(y+1);
                    mas[x][y+1]=true;
                }
            }
            vec=temp;
            temp=new Vector<Integer>();
        }
        pw.println((x+1)+" "+(y+1));
        System.out.println(System.currentTimeMillis()-time);
        in.close();
        pw.close();
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.Queue;

public class A {

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

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner("input.txt");
        PrintWriter out = new PrintWriter("output.txt");
        int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
        int[][] dist = new int[n][m];
        for(int[] a : dist) Arrays.fill(a, -1);
        Queue<Point> q = new LinkedList<>();
        for(int i = 0; i < k; i++)
        {
            int x = sc.nextInt() - 1, y = sc.nextInt() - 1;
            dist[x][y] = 0;
            q.add(new Point(x, y));
        }
        int ansX = -1, ansY = -1;
        while(!q.isEmpty())
        {
            Point cur = q.remove();
            ansX = cur.x; ansY = cur.y;
            for(int i = 0; i < 4; i++)
            {
                int x = cur.x + dx[i], y = cur.y + dy[i];
                if(x != -1 && y != -1 && x != n && y != m && dist[x][y] == -1)
                {
                    q.add(new Point(x, y));
                    dist[x][y] = dist[cur.x][cur.y] + 1;
                }
            }
        }
        out.println((ansX + 1) + " " + (ansY + 1));
        out.flush();
        out.close();
    }
    static class Scanner
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));}
        public Scanner(String file) throws Exception {br = new BufferedReader(new FileReader(file));}
        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        public String nextLine()throws IOException{return br.readLine();}
        public int nextInt() throws IOException {return Integer.parseInt(next());}
        public double nextDouble() throws IOException {return Double.parseDouble(next());}
        public char nextChar()throws IOException{return next().charAt(0);}
        public Long nextLong()throws IOException{return Long.parseLong(next());}
        public boolean ready() throws IOException{return br.ready();}
        public void waitForInput() throws InterruptedException {Thread.sleep(4000);}
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
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 A {

	static final int[] dx = {0, 0, -1, 1};
	static final int[] dy = {-1, 1, 0, 0};
	
	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner("input.txt");
		PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
//		Scanner sc = new Scanner(System.in);
//		PrintWriter out = new PrintWriter(System.out);

		int N = sc.nextInt(), M = sc.nextInt();
		int[][] dist = new int[N][M];
		Queue<Integer> q = new LinkedList<>();
		int K = sc.nextInt();
		while(K-->0)
		{
			int x = sc.nextInt() - 1, y = sc.nextInt() - 1;
			q.add(x * M + y);
			dist[x][y] = 1;
		}
		
		int max = 0, ansX = -1, ansY = -1;
		while(!q.isEmpty())
		{
			int u = q.remove(), x = u / M, y = u % M;
			if(dist[x][y] > max) 
				max = dist[ansX = x][ansY = y];
			for(int k = 0; k < 4; ++k)
			{
				int nx = x + dx[k], ny = y + dy[k];
				if(nx >= 0 && ny >= 0 && nx < N && ny < M && dist[nx][ny] == 0)
				{
					dist[nx][ny] = dist[x][y] + 1;
					q.add(nx * M + ny);
				}
				
			}
		}
		out.printf("%d %d\n", ansX + 1, ansY + 1);
		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.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class P35C {
	public static void main(String[] args) throws FileNotFoundException {
		InputStream inputStream = new FileInputStream("input.txt");
		OutputStream outputStream = new FileOutputStream("output.txt");
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(in, out);
		out.close();
	}

	static class Task {
		private class Point {
			int x, y;

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

		}

		private int dis(int i, int j, Point p2) {
			return Math.abs(i - p2.x) + Math.abs(j - p2.y);
		}

		public void solve(InputReader in, PrintWriter out) {
			int n = in.nextInt(), m = in.nextInt();
			int k = in.nextInt();
			Point[] ps = new Point[k];
			for (int i = 0; i < k; i++) {
				ps[i] = new Point(in.nextInt() - 1, in.nextInt() - 1);
			}
			int max = 0;
			Point argmax = ps[0];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					int val = dis(i, j, ps[0]);
					for (int l = 1; l < k; l++) {
						val = Math.min(val, dis(i, j, ps[l]));
					}
					if (val > max) {
						max = val;
						argmax = new Point(i, j);
					}
				}
			}
			out.println((argmax.x + 1) + " " + (argmax.y + 1));
		}
	}

	static 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 String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}

}
// Problem: 35_C. Fire Again
// Time complexity: cubic
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x35C
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new FileReader("input.txt"));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(infile.readLine());
         int[][] grid = new int[N][M];
         for(int i=0; i < N; i++)
            Arrays.fill(grid[i], -1);
         ArrayDeque<Integer> q = new ArrayDeque<Integer>();
         st = new StringTokenizer(infile.readLine());
         while(K-->0)
         {
            int a = Integer.parseInt(st.nextToken())-1;
            int b = Integer.parseInt(st.nextToken())-1;
            grid[a][b] = 0;
            q.add(a);   q.add(b);
         }
         while(q.size() > 0)
         {
            int x = q.poll();
            int y = q.poll();
            if(x > 0 && grid[x-1][y] == -1)
            {
               grid[x-1][y] = grid[x][y]+1;
               q.add(x-1); q.add(y);
            }
            if(y > 0 && grid[x][y-1] == -1)
            {
               grid[x][y-1] = grid[x][y]+1;
               q.add(x);   q.add(y-1);
            }
            if(x+1 < N && grid[x+1][y] == -1)
            {
               grid[x+1][y] = grid[x][y]+1;
               q.add(x+1); q.add(y);
            }
            if(y+1 < M && grid[x][y+1] == -1)
            {
               grid[x][y+1] = grid[x][y]+1;
               q.add(x);   q.add(y+1);
            }
         }
         int r = 0;
         int c = 0;
         for(int i=0; i < N; i++)
            for(int j=0; j < M; j++)
               if(grid[r][c] < grid[i][j])
               {
                  r = i;
                  c = j;
               }
         r++;  c++;
         System.setOut(new PrintStream(new File("output.txt")));
         System.out.println(r+" "+c);
      }
   }
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static InputStream IN;
    public static OutputStream OUT;
    public static PrintWriter out;
    public static BufferedReader in;
    
    public static StringTokenizer st = null;
    public static int ni() throws Exception {
        for (;st == null || !st.hasMoreTokens();){
            st = new StringTokenizer(in.readLine());
        }
        return Integer.parseInt(st.nextToken());
    }
    public static void main(String[] args) throws Exception {
        IN = new FileInputStream("input.txt");
        OUT = new FileOutputStream("output.txt");
        out = new PrintWriter(OUT);
        in = new BufferedReader(new InputStreamReader(IN));
        int n = ni();
        int m = ni();
        int k = ni();
        int[] x = new int[k];
        int[] y = new int[k];
        for (int i = 0 ; i < k; i++){
            x[i] = ni() - 1;
            y[i] = ni() - 1;
        }
        int w = Integer.MIN_VALUE;
        int aa = -1;
        int ab = -1;
        for (int i = 0 ; i < n ; i++){
            for (int j = 0; j < m; j++){
                int min = Integer.MAX_VALUE;
                for (int q = 0; q < k; q++){
                    int cur = Math.abs(i - x[q]) + Math.abs(j - y[q]);
                    min = Math.min(cur, min);
                }
                if (min > w){
                    w = min;
                    aa = i;
                    ab = j;
                }
            }
        }
        out.println((aa + 1) + " " + (ab + 1));
        
        out.flush();
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic

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

/**
 * @author igor_kz
 */
public class C35 {
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(new File("input.txt"));
        PrintWriter out = new PrintWriter("output.txt");
        int n = in.nextInt() , m = in.nextInt();
        int k = in.nextInt();
        int[] x = new int[k];
        int[] y = new int[k];
        int res = 0;
        for (int i = 0 ; i < k ; i++) {
            x[i] = in.nextInt();
            y[i] = in.nextInt();
        }
        int xx = 1 , yy = 1;
        for (int i = 1 ; i <= n ; i++)
            for (int j = 1 ; j <= m ; j++) {
                int cnt = Integer.MAX_VALUE;
                for (int l = 0 ; l < k ; l++) {
                    int time = Math.abs(i - x[l]) + Math.abs(j - y[l]);
                    cnt = Math.min(cnt , time);
                }
                if (cnt > res) {
                    res = cnt;
                    xx = i;
                    yy = j;
                }
                res = Math.max(res , cnt);
            }
        out.print(xx + " " + yy);
        out.close();
    }
}
// Problem: 35_C. Fire Again
// Time complexity: cubic
import java.io.*;
import java.util.*;

public class C
{
	String line;
	StringTokenizer inputParser;
	BufferedReader is;
	FileInputStream fstream;
	DataInputStream in;
	
	void openInput(String file)
	{

		if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
		else
		{
			try{
		
				
			fstream = new FileInputStream(file);
			in = new DataInputStream(fstream);
			is = new BufferedReader(new InputStreamReader(in));
			}catch(Exception e)
			{
				System.err.println(e);
			}
		}

	}
	
	void readNextLine()
	{
		try {
			line = is.readLine();
			inputParser = new StringTokenizer(line, " ");
			//System.err.println("Input: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}	
		
	}
	
	int NextInt()
	{
		String n = inputParser.nextToken();
		int val = Integer.parseInt(n);
		
		//System.out.println("I read this number: " + val);
		return val;
	}
	
	String NextString()
	{
		String n = inputParser.nextToken();
		return n;
	}
	
	void closeInput()
	{
		try {
			is.close();
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}
			
	}
	
	
	public static void main(String [] argv)
	{
		String filePath=null;
		if(argv.length>0)filePath=argv[0];
		C c = new C(filePath);
	}
	
	public C(String inputFile)
	{
		inputFile="input.txt";
        openInput(inputFile);
        PrintWriter writer=null;
		try {
			writer = new PrintWriter("output.txt");
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
		readNextLine();
		int N=NextInt();
		int M=NextInt();
		readNextLine();
		int K=NextInt();
		readNextLine();
		int [] [] p = new int[N][M];
		int [] [] init = new int [K][2];
		
		for(int i=0; i<K; i++)
		{
			int x=NextInt()-1;
			int y=NextInt()-1;
			p[x][y]=0;
			init[i][0]=x;
			init[i][1]=y;
		}
		
		int max=-1;
		int maxX=-1, maxY=-1;
		
		for(int i=0; i<N; i++)
			for(int j=0; j<M; j++)
			{
				p[i][j]=10000;
				for(int k=0; k<K; k++)
				{
					int n=Math.abs(init[k][0]-i)+Math.abs(init[k][1]-j);
					if(n<p[i][j])p[i][j]=n;
				}
				if(p[i][j]>max)
				{
					max=p[i][j];
					maxX=i+1;
					maxY=j+1;
				}
			}
		
		
	
		writer.println( maxX+" "+maxY);
		
		

		
		closeInput();
		writer.close();
	}

	
}
// 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.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class FireAgain {
    static int dx[] = { 0, 0, 1, -1 };
    static int dy[] = { 1, -1, 0, 0 };

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(new File("input.txt"));
        BufferedWriter write = new BufferedWriter(new FileWriter("output.txt"));
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[][] v = new boolean[n][m];
        int k = sc.nextInt();
        Queue<Integer> q = new LinkedList<Integer>();
        for (int i = 0; i < k; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            q.add(x);
            q.add(y);
            v[x][y] = true;
        }
        int lastx = 0;
        int lasty = 0;
        while (!q.isEmpty()) {
            lastx = q.poll();
            lasty = q.poll();
            for (int i = 0; i < 4; i++) {
                int r = lastx + dx[i];
                int c = lasty + dy[i];
                if (r >= 0 && c >= 0 && r < n && c < m && !v[r][c]) {
                    v[r][c] = true;
                    q.add(r);
                    q.add(c);
                }
            }
        }
        write.write((lastx + 1) + " " + (lasty + 1));
        write.close();
    }

}
// 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.io.IOException;
import java.util.LinkedList;
import java.util.Queue;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new FileReader("input.txt"));
		
		String dimensions = br.readLine();
		String extractDim = "";
		int n = 0, m;
		for (int i = 0 ; i < dimensions.length() ; i++)
		{
			if(dimensions.charAt(i) == ' ')
			{
				n = Integer.parseInt(extractDim);
				extractDim = "";
				continue;
			}
			extractDim += dimensions.charAt(i);
		}
		m = Integer.parseInt(extractDim); 
		
		String burningTrees = br.readLine();
		
		int k = Integer.parseInt(burningTrees);		
		
		Point[] coord = new Point[k];
		
		String coordSet = br.readLine();
		int spaceCount = 0;
		String newCoord = "";
		int s = 0;
		for(int i = 0 ; i < coordSet.length() ; i++)
		{
			if(coordSet.charAt(i) == ' ')
				spaceCount++;
			
			if(spaceCount == 2)
			{
				String extractCoord = "";
				int x = 0, y;
				for (int j = 0 ; j < newCoord.length() ; j++)
				{
					if(newCoord.charAt(j) == ' ')
					{
						x = Integer.parseInt(extractCoord);
						extractCoord = "";
						continue;
					}
					extractCoord += newCoord.charAt(j);
				}
				y = Integer.parseInt(extractCoord);
				
				coord[s] = new Point(x,y);
				s++;
				newCoord = "";
				spaceCount = 0;
				continue;
			}
			
			newCoord += coordSet.charAt(i);
		}
		
		String extractCoord = "";
		int x = 0, y;
		for (int j = 0 ; j < newCoord.length() ; j++)
		{
			if(newCoord.charAt(j) == ' ')
			{
				x = Integer.parseInt(extractCoord);
				extractCoord = "";
				continue;
			}
			extractCoord += newCoord.charAt(j);
		}
		y = Integer.parseInt(extractCoord);
		
		coord[s] = new Point(x,y);
		s++;
		
		br.close();
		
		int[][] forest = new int[n+2][m+2];
		
		for(int i = 0 ; i < forest.length ; i++)
		{
			for(int j = 0 ; j < forest[i].length ; j++)
			{
				if(i == 0 || i == n+1 || j == 0 || j == m+1 )
					forest[i][j] = 0;
				else
					forest[i][j] = 1;
			}
		}
		
		
		Queue<Point> q = new LinkedList<>();
		
		for(int i = 0 ; i < coord.length ; i++)
		{
			forest[coord[i].x][coord[i].y] = 0;
			q.add(coord[i]);
		}
		
		Point tree = new Point();
		while(!q.isEmpty())
		{
			Point temp = q.remove();
			forest[temp.x][temp.y] = 0;
			
			if(q.isEmpty())
				tree = new Point(temp.x ,temp.y);
			for(int i = -1 ; i <= 1 ; i++)
			{
				for(int j = -1; j <= 1; j++)
				{
					if(i != 0 && j != 0 || i == 0 && j == 0)
						continue;
					if(forest[temp.x+i][temp.y+j] == 0)
						continue;
					else
					{
						forest[temp.x+i][temp.y+j] = 0;
						q.add(new Point(temp.x+i , temp.y+j));
					}
				}
			}
			
		}
		
		
		BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt"));
		bw.write(tree.x + " " + tree.y);
		bw.close();
		
	
	}

}