1.

/**
* ACM Training 2009
* ACM Problem #11230 - Annoying Painting Tool
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=2171&mosmsg=Submission+received+with+ID+7309054
*
* @author Evgeni Pavlidis
* @version 1.0, 10/08/2009
*
* Methode: ad hoc
* Status : Accepted
* Runtime: 0.300
*/
import java.io.*;
import java.util.*;

public class Main {

private static int n,m,rows,columns;
private static boolean image[][];

private static int countOperations()
{
int counter = 0;

for(int y = 0; y <= n-rows; y++)
{
for(int x = 0; x <= m-columns; x++)
if(image[y][x]) // perform operation
{
for(int r=0; r < rows; r++)
for(int c=0; c < columns; c++)
image[y+r][x+c] = !image[y+r][x+c];

counter++;
}

// check remainings of current row
for(int x = m - columns + 1; x < m; x++)
if(image[y][x])
return -1;
}

// check remaining block
for(int y = n - rows + 1; y < n; y++)
for(int x = 0; x < m; x++)
if(image[y][x])
return -1;


return counter;
}

public static void main(String...args)
{
Scanner sc = new Scanner(System.in);
String input;

while(true)
{
n = sc.nextInt();
m = sc.nextInt();
rows = sc.nextInt();
columns = sc.nextInt();

if(n == 0 && m == 0 && columns == 0 && rows == 0)
break;

image = new boolean[n][m];
for(int y = 0; y < n; y++)
{
input = sc.next();
for(int x = 0; x < m; x++)
image[y][x] = (input.charAt(x) == '1')? true : false;
}

System.out.println(countOperations());
}
}
}