package no402; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.Arrays; import java.util.InputMismatchException; import java.util.NoSuchElementException; import java.util.Queue; public class Main { public static int[] DI = {0,-1,-1,-1,0,1,1,1}; public static int[] DJ = {1,1,0,-1,-1,-1,0,1}; public static void main(String[] args) { IO io = new IO(); int h = io.nextInt(); int w = io.nextInt(); char[][] m = new char[h+2][w+2]; for(int i=0;i<=h+1;i++) { Arrays.fill(m[i], '.'); } for(int i=0;i q = new ArrayDeque<>(); for(int i=0;i= h2 || nj < 0 || nj >= w2 || dist[ni][nj] <= dist[ci][cj] + 1) { continue; } dist[ni][nj] = dist[ci][cj] + 1; q.offer(ni * 10000 + nj); } } // System.out.println(Arrays.deepToString(dist)); int ans = 0; for(int i=0;i Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public char nextChar() { if (!hasNext()) { throw new NoSuchElementException(); } return (char) readByte(); } public double nextDouble() { return Double.parseDouble(next());} public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i=0;i