#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define DEBUG(x) cerr << ">> " << #x << ": " << x << endl;
#define REP(i,a) for (int i =0; i < (a);++i)
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
struct Point
{
int x;
int y;
Point(int a, int b)
{
x=a;y=b;
}
};
int mapwidth, mapheight, tilewidth, tileheight;
long long testcase = 0;
char character;
bool pixels[1000][1000];
int tileFound[1000][1000];
int firstX, firstY;
int topleftx, toplefty;
vector<Point> allpoints;
int pointsCount;
int gettileX(int x, int y)
{
// cerr << "Tile (" << x << "," << y << ") has X: " << (x-topleftx) / tilewidth << endl;
return (x-topleftx) / tilewidth;
}
int gettileY(int x, int y)
{
// cerr << "Tile (" << x << "," << y << ") has Y: " << (y-toplefty) / tileheight << endl;
return (y-toplefty) / tileheight;
}
int main() {
for (int x = 0; x < 1000;x ++)
for (int y =0 ;y<1000;y++)
{
tileFound[x][y] = -1;
}
while (scanf("%d%d%d%d", &mapheight, &mapwidth, &tileheight, &tilewidth) != EOF)
{
scanf("%c", &character);
long maxtc = 1000000;
pointsCount = 0;
// Load map
for (int y =0 ;y <mapheight;y++)
{
for (int x = 0; x < mapwidth; x++)
{
scanf("%c", &character);
pixels[x][y] = (character == 'X');
if (pixels[x][y])
{
allpoints.push_back(Point(x,y));
pointsCount++;
}
if (firstX == -1 && pixels[x][y])
{
firstX = x; firstY = y;
}
}
scanf("%c", &character);
}
for (int rfx = 0; rfx < tilewidth; rfx++)
{
for (int rfy = 0; rfy <tileheight;rfy++)
{
topleftx = -rfx;
toplefty = -rfy;
long tc = 0;
for(vector<Point>::iterator it = allpoints.begin(); it != allpoints.end(); it++)
{
int tx = gettileX(it->x, it->y);
int ty= gettileY(it->x, it->y);
if (tileFound[tx][ty] < testcase)
{
tileFound[tx][ty] = testcase;
//cout << "Testcase " << testcase << ": " << tx << "," << ty << endl;
tc++;
if (tc > maxtc) break;
}
}
if (tc < maxtc)
{
maxtc = tc;
}
testcase++;
}
}
printf("%ld\n", maxtc);
// Vector pop all
for (int i = 0; i <pointsCount;i++)
{
allpoints.pop_back();
}
}
return 0;
}