Problem: There is an area map that is a rectangular matrix n × m, each cell of the matrix contains the average height of a corresponding area part. Peter works for a company that has to build several cities within this area, each of the cities will occupy a rectangle a × b cells on the map. To start construction works in a particular place Peter needs to remove excess ground from the construction site where a new city will be built. To do so he chooses a cell of the minimum height within this site, and removes excess ground from other cells of the site down to this minimum level. Let's consider that to lower the ground level from h2 to h1 (h1 ≤ h2) they need to remove h2 - h1 ground units.

Let's call a site's position optimal, if the amount of the ground removed from this site is minimal compared to other possible positions. Peter constructs cities according to the following algorithm: from all the optimum site's positions he chooses the uppermost one. If this position is not unique, he chooses the leftmost one. Then he builds a city on this site. Peter repeats this process untill he can build at least one more city. For sure, he cannot carry out construction works on the occupied cells. Would you, please, help Peter place cities according to the algorithm? 

Input

The first line contains four space-separated integers: map sizes n, m and city sizes a, b (1 ≤ a ≤ n ≤ 1000, 1 ≤ b ≤ m ≤ 1000). Then there follow n lines, each contains m non-negative space-separated numbers, describing the height matrix. Each number doesn't exceed 109. 

Output

In the first line output k — the amount of constructed cities. In each of the following k lines output 3 space-separated numbers — the row number and the column number of the upper-left corner of a subsequent construction site, and the amount of the ground to remove from it. Output the sites in the order of their building up.

Examples

Input

2 2 1 2
1 2
3 5


Output

2
1 1 1
2 1 2


Input

4 4 2 2
1 5 3 4
2 7 6 1
1 1 2 2
2 2 1 2


Output

3
3 1 2
3 3 3
1 2 9

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Main implements Runnable {	
	
	class MegaQueue {
		final static int N = 1024;

		int[] st1;
		int[] st2;
		int[] mins1;
		int[] mins2;
		int p1, p2;

		MegaQueue() {
			st1 = new int[N];
			st2 = new int[N];
			mins1 = new int[N];
			mins2 = new int[N];
			p1 = p2 = 0;
		}

		void offer(int x) {
			if (p1 == 0)
				mins1[p1] = x;
			else
				mins1[p1] = Math.min(x, mins1[p1 - 1]);
			st1[p1++] = x;
		}	

		int poll() {
			if (p2 == 0) {
				while (p1 > 0) {
					int x = st1[--p1];
					if (p2 == 0)
						mins2[p2] = x;
					else
						mins2[p2] = Math.min(x, mins2[p2 - 1]);
					st2[p2++] = x;
				}
			}
			return st2[--p2];
		}

		int min() {
			int a = p1 > 0 ? mins1[p1 - 1] : Integer.MAX_VALUE;
			int b = p2 > 0 ? mins2[p2 - 1] : Integer.MAX_VALUE;
			return Math.min(a, b);
		}
	}
	
	class Corner implements Comparable<Corner> {
		int r, c;		
		long am;
		Corner(int r, int c, long am) {
			this.r = r;
			this.c = c;
			this.am = am;
		}
		public int compareTo(Corner o) {
			if (am != o.am)
				return am < o.am ? -1 : 1;
			if (r != o.r)
				return r - o.r;
			if (c != o.c)
				return c - o.c;
			return 0;
		}
	}

	public void _main() throws IOException {
		int height = nextInt();
		int width = nextInt();
		int a = nextInt();
		int b = nextInt();
		int[][] h = new int[height][width];
		for (int r = 0; r < height; r++)
			for (int c = 0; c < width; c++)
				h[r][c] = nextInt();
		
		int[][] mins = buildMins(h, height, width, a, b);
		long[][] sums = buildSums(h, height, width, a, b);
	
		Corner[] corners = new Corner[(height - a + 1) * (width - b + 1)];
		int num = 0;
		for (int r = 0; r + a <= height; r++)
			for (int c = 0; c + b <= width; c++)
				corners[num++] = new Corner(r, c, sums[r][c] - a * b * (long) mins[r][c]);
		mins = null;
		sums = null;
		Arrays.sort(corners);
		List<Corner> res = new ArrayList<Corner>();
		boolean[][] was = new boolean[height][width];
		for (int i = 0; i < num; i++) {
			Corner z = corners[i];
			if (was[z.r][z.c]) continue;
			res.add(z);
			for (int r = -a + 1; r < a; r++)
				for (int c = -b + 1; c < b; c++) {
					int nr = r + z.r;
					int nc = c + z.c;
					if (nr < 0 || nr >= height || nc < 0 || nc >= width) continue;
					was[nr][nc] = true;
				}					
		}
		out.println(res.size());
		for (Corner c : res)
			out.println((c.r + 1) + " " + (c.c + 1) + " " + c.am);
	}
	
	int[][] buildMins(int[][] h, int height, int width, int a, int b) {
		int[][] mins = new int[height][width];
		for (int c = 0; c < width; c++) {
			MegaQueue q = new MegaQueue();
			for (int r = 0; r < a - 1; r++)
				q.offer(h[r][c]);
			for (int r = a - 1; r < height; r++) {
				q.offer(h[r][c]);
				mins[r - (a - 1)][c] = q.min();
				q.poll();
			}
		}
		for (int r = 0; r < height; r++) {
			int[] val = new int[width];
			MegaQueue q = new MegaQueue();
			for (int c = 0; c < b - 1; c++)
				q.offer(mins[r][c]);
			for (int c = b - 1; c < width; c++) {
				q.offer(mins[r][c]);
				val[c - (b - 1)] = q.min();
				q.poll();
			}
			mins[r] = val;
		}
		return mins;
	}

	private long[][] buildSums(int[][] h, int height, int width, int a, int b) {
		long[][] sums = new long[height][width];
		for (int c = 0; c < width; c++) {
			long s = 0;
			for (int r = 0; r < a - 1; r++)
				s += h[r][c];
			for (int r = a - 1; r < height; r++) {
				s += h[r][c];
				sums[r - (a - 1)][c] = s;
				s -= h[r - (a - 1)][c];
			}
		}
		for (int r = 0; r < height; r++) {
			long[] val = new long[width];
			long s = 0;
			for (int c = 0; c < b - 1; c++)
				s += sums[r][c];
			for (int c = b - 1; c < width; c++) {
				s += sums[r][c];
				val[c - (b - 1)] = s;
				s -= sums[r][c - (b - 1)];
			}
			sums[r] = val;
		}
		return sums;		
	}


	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	private String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String rl = in.readLine();
			if (rl == null)
				return null;
			st = new StringTokenizer(rl);
		}
		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) {
		new Thread(new Main()).start();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}