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 D15 {
public static void main(String[] args) throws IOException {
	input.init(System.in);
	PrintWriter out = new PrintWriter(System.out);
	Random rand = new Random();
	int n = input.nextInt(), m = input.nextInt(), a = input.nextInt(), b = input.nextInt();
	int[][] data = new int[n][m];
	for(int i = 0; i<n; i++)
		for(int j = 0; j<m; j++)
			data[i][j] = input.nextInt();
	int[][] rowmin = new int[n][m];
	int[] q = new int[1001];
	int[] d = new int[1001];
	int ql = 0, qr = 0, dl = 0, dr = 0;
	for(int i = 0; i<n; i++)
	{
		ql = qr = dl = dr = 0;
		for(int j = 0; j<b; j++)
		{
			q[qr++] = data[i][j];
			while(dl<dr && d[dr-1] > data[i][j]) dr--;
			d[dr++] = data[i][j];
		}
		rowmin[i][0] = d[dl];
		//for(int k = dl; k<dr; k++) out.print(d[k]+" ");
		//out.println();
		for(int j = b; j<m; j++)
		{
			int tmp = q[ql++];
			if(dl<dr && d[dl] == tmp) dl++;
			q[qr++] = data[i][j];
			while(dl<dr && d[dr-1] > data[i][j]) dr--;
			d[dr++] = data[i][j];
			rowmin[i][j-b+1] = d[dl];
		}
	}
	//for(int[] A : rowmin) out.println(Arrays.toString(A));
	int[][] rectmin = new int[n][m];
	for(int j = 0; j+b<=m; j++)
	{
		dl = dr = ql = qr = 0;
		for(int i = 0; i<a; i++)
		{
			q[qr++] = rowmin[i][j];
			while(dl<dr && d[dr-1] > rowmin[i][j]) dr--;
			d[dr++] = rowmin[i][j];
		}
		rectmin[0][j] = d[dl];
		for(int i = a; i<n; i++)
		{
			int tmp = q[ql++];
			if(dl<dr && d[dl] == tmp) dl++;
			q[qr++] = rowmin[i][j];
			while(dl<dr && d[dr-1] > rowmin[i][j]) dr--;
			d[dr++] = rowmin[i][j];
			rectmin[i-a+1][j] = d[dl];
		}
	}
	//for(int[] A:rectmin) out.println(Arrays.toString(A));
	long[][] prefsum = new long[n][m];
	for(int i = 0; i<n; i++)
		for(int j = 0; j<m; j++)
		{
			prefsum[i][j] = data[i][j];
			if(i > 0) prefsum[i][j] += prefsum[i-1][j];
			if(j > 0) prefsum[i][j] += prefsum[i][j-1];
			if(i > 0 && j > 0) prefsum[i][j] -= prefsum[i-1][j-1];
		}
	//for(long[] A : prefsum) out.println(Arrays.toString(A));
	Rect[] pq =new Rect[(n - a + 1) * (m - b+1)];
	Rect[] good =new Rect[(n - a + 1) * (m - b+1)];
	int idx = 0;
	for(int i = 0; i+a<=n; i++)
		for(int j = 0; j+b<=m; j++)
		{
			long sum = prefsum[i+a-1][j+b-1];
			if(i > 0) sum -= prefsum[i-1][j+b-1];
			if(j > 0) sum -= prefsum[i+a-1][j-1];
			if(i > 0 && j > 0) sum += prefsum[i-1][j-1];
			long cost = sum - (long)a*b*rectmin[i][j];
			pq[idx++] = (new Rect(i, j, cost));
		}
	idx = 0;
	Arrays.sort(pq);
	boolean[][] used = new boolean[n][m];
	for(int ii = 0; ii<pq.length; ii++)
	{
		Rect at = pq[ii];
		if(used[at.i][at.j]) continue;
		if(used[at.i+a-1][at.j+b-1]) continue;
		if(used[at.i][at.j+b-1]) continue;
		if(used[at.i+a-1][at.j]) continue;
		good[idx++] = at;
		for(int i = at.i; i<at.i + a; i++)
			for(int j = at.j; j < at.j + b; j++)
				used[i][j] = true;
	}
	out.println(idx);
	for(int i= 0; i<idx; i++)
	{
		Rect r = good[i];
		out.println((1+r.i)+" "+(1+r.j)+" "+r.c);
	}
	out.close();
}
static class Rect implements Comparable<Rect>
{
	int i, j;
	long c;
	public Rect(int ii, int jj, long cc)
	{
		i = ii; j = jj; c = cc;
	}
	@Override
	public int compareTo(Rect o) {
		if(c != o.c) return Long.compare(c, o.c);
		if(i != o.i) return i - o.i;
		return j - o.j;
	}
}
static class MinQueue
{
	ArrayDeque<Integer> d;
	Queue<Integer> q;
	MinQueue()
	{
		d = new ArrayDeque<Integer>();
		q = new LinkedList<Integer>();
	}
	void add(int x)
	{
		q.add(x);
		while(!d.isEmpty() && d.peekLast() > x) d.removeLast();
		d.addLast(x);
	}
	void remove()
	{
		int tmp = q.poll();
		if(!d.isEmpty() && d.peekFirst() == tmp) d.pollFirst();
	}
	int min()
	{
		return d.peekFirst();
	}
}
public static class input {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(reader.readLine());
		return tokenizer.nextToken();
	}

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

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

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