package no402; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.NoSuchElementException; 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) throws IOException { //IO io = new IO(new FileInputStream("402.txt")); IO io = new IO(System.in); 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= 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