import java.util.*; import static java.lang.Math.*; import static java.util.Collections.*; class Point implements Comparable { int y, x, d; Point(int y, int x) { this(y,x,Integer.MAX_VALUE); } Point(int y, int x, int d) { this.y=y; this.x=x; this.d=d; } public int compareTo(Point rhs) { return drhs.d ? +1 : 0; } } class EOI extends Exception {} public class BlackForce { public static void main( String[] args ) { try { for(Scanner in = new Scanner(System.in) ;; ) new BlackForce(in).solve(); } catch( EOI e ) {} } // read the input ------------------------------------------------------- public final int H,W,C,R; public final int[][] Height; public final boolean[][] Reside; public BlackForce( Scanner in ) throws EOI { H = in.nextInt(); W = in.nextInt(); C = in.nextInt(); R = in.nextInt(); if( H==0 && W==0 && C==0 && R==0 ) throw new EOI(); assert 0 Q = new LinkedList(); for(Q.offer(s); !Q.isEmpty(); ) { Point p = Q.poll(); if( !checked[p.y][p.x] && w[p.y][p.x]>Height[p.y][p.x] ) { v += w[p.y][p.x] - Height[p.y][p.x]; checked[p.y][p.x] = true; Q.offer(new Point(p.y-1,p.x)); Q.offer(new Point(p.y+1,p.x)); Q.offer(new Point(p.y,p.x-1)); Q.offer(new Point(p.y,p.x+1)); } } return v; } // """水を張れるだけ張る""" // // PriorityQueueを使ったFloodFillで :: O(HW log(HW)) になるはず int[][] pourWater() { // とりあえず十分に大量の水を全てのセルに入れておく int[][] d = new int[H][W]; for(int y=0; y Q = new PriorityQueue(); for(int y=0; y d2 ) { d[p.y][p.x] = d2; if(p.y>0) Q.offer(new Point(p.y-1,p.x,d2)); if(p.y0) Q.offer(new Point(p.y,p.x-1,d2)); if(p.x