Problem:
Score : 300 points

Problem Statement

We have a square grid with H rows and W columns.
Snuke wants to write 0 or 1 in each of the squares.
Here, all of the following conditions have to be satisfied:

For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)

For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.

Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.

Constraints

1 \leq H,W \leq 1000

0 \leq A

2 \times A \leq W

0 \leq B

2 \times B \leq H

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W A B

Output

If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1.

If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:

s_{11}s_{12}\cdots s_{1W}
s_{21}s_{22}\cdots s_{2W}
\vdots
s_{H1}s_{H2}\cdots s_{HW}

Here s_{ij} is the digit written in the square at the i-th row from the top and the j-th column from the left in the grid.

If multiple solutions exist, printing any of them will be accepted.

Sample Input 1

3 3 1 1

Sample Output 1

100
010
001

Every row contains two 0s and one 1, so the first condition is satisfied.
Also, every column contains two 0s and one 1, so the second condition is satisfied.

Sample Input 2

1 5 2 0

Sample Output 2

01010

Solution in C (GCC 5.4.1) (judge verdict: Accepted)

#include <stdio.h>
#include <stdlib.h>

/*
void attempt(int H, int W, int row_0, int row_1, int col_0, int col_1) {
*/
void attempt(int H, int W, int row_x, int col_x, int row_x_is_0, int col_x_is_0) {
	char* haiti_data;
	char** haiti;
	int* count_0;
	int i, j;

	/*
	if (row_0 * H != col_0 * W || row_1 * H != col_1 * H) return;
	if ((row_0 + row_1) != W || (col_0 + col_1) != H) return;
	*/

	haiti_data = malloc(sizeof(char) * (W + 1) * H);
	if (haiti_data == NULL) {
		perror("malloc 1");
		exit(1);
	}
	haiti = malloc(sizeof(char*) * H);
	if (haiti == NULL) {
		perror("malloc 2");
		exit(1);
	}
	count_0 = malloc(sizeof(int) * W);
	if (count_0 == NULL) {
		perror("malloc 3");
		exit(1);
	}

	for (i = 0; i < H; i++) {
		haiti[i] = &haiti_data[(W + 1) * i];
		haiti[i][W] = '\0';
	}
	for (i = 0; i < W; i++) {
		count_0[i] = 0;
	}

	for (i = 0; i < H; i++) {
		int row_0_left = (i < row_x_is_0 ? row_x : W - row_x);
		for (j = 0; j < W; j++) {
			if (row_0_left > 0 && count_0[j] < (j < col_x_is_0 ? col_x : H - col_x)) {
				haiti[i][j] = '0';
				count_0[j]++;
				row_0_left--;
			} else {
				haiti[i][j] = '1';
			}
		}
		if (row_0_left > 0) {
			/* failed */
			free(haiti_data);
			free(haiti);
			free(count_0);
			return;
		}
	}
	for (i = 0; i < W; i++) {
		if (count_0[i] != (i < col_x_is_0 ? col_x : H - col_x)) {
			/* failed */
			free(haiti_data);
			free(haiti);
			free(count_0);
			return;
		}
	}
	/* OK */
	for (i = 0; i < H; i++) {
		puts(haiti[i]);
	}
	free(haiti_data);
	free(haiti);
	free(count_0);
	exit(0);
}

int main(void) {
	int H, W, A, B;
	int n, m;
	if (scanf("%d%d%d%d", &H, &W, &A, &B) != 4) return 1;
	/*
	attempt(H, W, A, W-A, B, H-B);
	attempt(H, W, W-A, A, B, H-B);
	*/
	/* col_0はcol_1より小さいことを仮定し、必要に応じて反転 */
	/*
	attempt(H, W, A, W-A, H-B, B);
	attempt(H, W, W-A, A, H-B, B);
	*/
	/*
	attempt(H, W, A, B, 0);
	attempt(H, W, W-A, B, 0);
	attempt(W, H, B, A, 1);
	attempt(W, H, H-B, A, 1);
	*/
	for (n = 0; n < H; n++) {
		for (m = 0; m < W; m++) {
			int row_0_num = A * n + (W-A) * (H-n);
			int col_0_num = B * m + (H-B) * (W-m);
			if (row_0_num == col_0_num) {
				attempt(H, W, A, B, n, m);
			}
		}
	}
	puts("No");
	return 0;
}

/*
0がA → 0がA*H個、1が(W-A)*H個
1がA → 1がA*H個、0が(W-A)*H個

0がB → 0がB*W個、1が(H-B)*W個
1がB → 1がB*W個、0が(H-B)*W個

0か1の割当は固定ではない！
*/

/*
2 2 0 1
で落ちたので、反転する仕組みを入れた。
*/

/*
上からn行は0がA個、1が(W-A)個
残りの(H-n)行は0が(W-A)個、1がA個

左からm列は0がB個、1が(H-B)個
残りの(W-m)列は0が(H-B)個、1がB個
*/