import java.util.LinkedList; import java.util.Scanner; public class Main { static Scanner scan = new Scanner(System.in); static int W, H; static int[][] M; static boolean[][] F; static int[] dx = {0, 0, 1, -1}; static int[] dy = {1, -1, 0, 0}; static LinkedList q = new LinkedList<>(); public static void main(String[] args) { W = scan.nextInt(); H = scan.nextInt(); M = new int[H][W]; F = new boolean[H][W]; for(int i=0; i= W || ny < 0 || ny >= H) continue; if(F[ny][nx]) continue; if(M[ny][nx] != number) continue; q.add(new Node(nx, ny, i)); } } } static class Node { int x, y, d; Node(int x, int y, int d) { this.x = x; this.y = y; this.d = d; } } }