#include <bits/stdc++.h>

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular

namespace Base {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline void read(Tp &x) {
        x = input<Tp>();
    }
    template <typename Tp>
    inline void chmax(Tp &x, Tp y) {
        x < y ? x = y : 0;
    }
    template <typename Tp>
    inline void chmin(Tp &x, Tp y) {
        x > y ? x = y : 0;
    }
};  // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 1007
#define bsn std::bitset<MAX_N>
#define V std::vector

int N, tot;
int vt[MAX_N];
bsn f[MAX_N], g[MAX_N], t[MAX_N], tmp;
bool nlf[MAX_N], flg[MAX_N];

void print(bsn k) {
    puts("----begin----");
    for (int i = k._Find_first(); i != k.size(); i = k._Find_next(i))
        printf("%d ", i);
    puts("");
    puts("----end----");
}

void solve() {
    Rep(i, N) {
        Lep(j, i) {
            tmp = f[i] & f[j];
            if (tmp.count() == 2) {
                int u = tmp._Find_first(), v = tmp._Find_next(u);
                if (!g[u][v]) printf("%d %d\n", u, v);
                g[u].set(v), g[v].set(u);
                nlf[u] = nlf[v] = true;
            }
        }
    }
    int cnt = 0, rt;
    Rep(i, N) {
        if (nlf[i])
            vt[++cnt] = i, rt = i;
        else {
            int mn = 0;
            Rep(j, N) if (f[j][i] &&
                          (mn == 0 || f[mn].count() > f[j].count()) && !flg[j])
                mn = j;
            assert(mn > 0);
            // printf("> %d %d\n", i, mn);
            t[i] = f[mn];
            flg[mn] = true;
        }
    }
    if (cnt == 0) {
        rt = 1;
        Rep(i, N) if (i != rt) printf("%d %d\n", i, rt);
        return;
    } else if (cnt == 2) {
        int rt2;
        Rep(i, N) if (nlf[i] && i != rt) rt2 = i;
        Rep(i, N) if (!nlf[i]) {
            for (int j = t[i]._Find_first(); j != t[i].size();
                 j = t[i]._Find_next(j))
                if (!nlf[j]) {
                    printf("%d %d\n", j, rt);
                    nlf[j] = true;
                }
            std::swap(rt, rt2);
        }
        return;
    }
    Rep(i, cnt) g[vt[i]].set(vt[i]);
    Rep(i, N) if (!nlf[i]) {
        for (int j = t[i]._Find_first(); j != t[i].size();
             j = t[i]._Find_next(j))
            if (!nlf[j]) t[i][j] = 0;
        // printf("%d:\n", i);
        // print(t[i]);
        bool shit = false;
        Rep(j, cnt) if (g[vt[j]].count() == t[i].count() &&
                        ((g[vt[j]] & t[i]) == t[i])) {
            printf("%d %d\n", i, vt[j]);
            shit = true;
            break;
        }
        if (!shit) {
            puts("shit");
            exit(3);
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    FIN("3.in");
    FOUT("1.out");
#endif
    read(N);
    if (N == 1) return 0;
    if (N == 2) return puts("1 2"), 0;
    int k;
    Rep(i, N) {
        read(k);
        while (k--) f[i].set(input<int>());
    }
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular

namespace Base {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline void read(Tp &x) {
        x = input<Tp>();
    }
    template <typename Tp>
    inline void chmax(Tp &x, Tp y) {
        x < y ? x = y : 0;
    }
    template <typename Tp>
    inline void chmin(Tp &x, Tp y) {
        x > y ? x = y : 0;
    }
};  // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 1007
#define bsn std::bitset<MAX_N>
#define V std::vector

int N, tot;
int vt[MAX_N];
bsn f[MAX_N], g[MAX_N], t[MAX_N], tmp;
bool nlf[MAX_N], vis[MAX_N][MAX_N], flg[MAX_N];
V<int> G[MAX_N];

void print(bsn k) {
    puts("----begin----");
    for (int i = k._Find_first(); i != k.size(); i = k._Find_next(i))
        printf("%d ", i);
    puts("");
    puts("----end----");
}

void solve() {
    Rep(i, N) {
        Lep(j, i) {
            tmp = f[i] & f[j];
            if (tmp.count() == 2) {
                int u = tmp._Find_first(), v = tmp._Find_next(u);
                G[u].push_back(v), G[v].push_back(u);
                if (!vis[u][v])
                    printf("%d %d\n", u, v), vis[u][v] = vis[v][u] = true;
                nlf[u] = nlf[v] = true;
            }
        }
    }
    int cnt = 0, rt;
    Rep(i, N) {
        if (nlf[i])
            vt[++cnt] = i, rt = i;
        else {
            int mn = 0;
            Rep(j, N) if (f[j][i] &&
                          (mn == 0 || f[mn].count() > f[j].count()) && !flg[j])
                mn = j;
            // printf("> %d %d\n", i, mn);
            t[i] = f[mn];
            flg[mn] = true;
        }
    }
    if (cnt == 0) {
        rt = 1;
        Rep(i, N) if (i != rt) printf("%d %d\n", i, rt);
        return;
    } else if (cnt == 2) {
        int rt2;
        Rep(i, N) if (nlf[i] && i != rt) rt2 = i;
        Rep(i, N) if (!nlf[i]) {
            for (int j = t[i]._Find_first(); j != t[i].size();
                 j = t[i]._Find_next(j))
                if (!nlf[j]) {
                    printf("%d %d\n", j, rt);
                    nlf[j] = true;
                }
            std::swap(rt, rt2);
        }
        return;
    }
    Rep(i, cnt) {
        int x = vt[i];
        g[x].set(x);
        for (int y : G[x]) g[x].set(y);
    }
    Rep(i, N) if (!nlf[i]) {
        for (int j = t[i]._Find_first(); j != t[i].size();
             j = t[i]._Find_next(j))
            if (!nlf[j]) t[i][j] = 0;
        // printf("%d:\n", i);
        // print(t[i]);
        Rep(j, cnt) if ((g[vt[j]] & t[i]) == t[i]) {
            printf("%d %d\n", i, vt[j]);
            break;
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    FIN("3.in");
    FOUT("1.out");
#endif
    read(N);
    if (N == 1) return 0;
    if (N == 2) return puts("1 2"), 0;
    int k;
    Rep(i, N) {
        read(k);
        while (k--) f[i].set(input<int>());
    }
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular

namespace Base {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline void read(Tp &x) {
        x = input<Tp>();
    }
    template <typename Tp>
    inline void chmax(Tp &x, Tp y) {
        x < y ? x = y : 0;
    }
    template <typename Tp>
    inline void chmin(Tp &x, Tp y) {
        x > y ? x = y : 0;
    }
};  // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 1007
#define bsn std::bitset<MAX_N>
#define V std::vector

int N, tot;
int vt[MAX_N];
bsn f[MAX_N], g[MAX_N], t[MAX_N], tmp;
bool nlf[MAX_N], flg[MAX_N];

void print(bsn k) {
    puts("----begin----");
    for (int i = k._Find_first(); i != k.size(); i = k._Find_next(i))
        printf("%d ", i);
    puts("");
    puts("----end----");
}

void solve() {
    Rep(i, N) {
        Lep(j, i) {
            tmp = f[i] & f[j];
            if (tmp.count() == 2) {
                int u = tmp._Find_first(), v = tmp._Find_next(u);
                if (!g[u][v]) printf("%d %d\n", u, v);
                g[u].set(v), g[v].set(u);
                nlf[u] = nlf[v] = true;
            }
        }
    }
    int cnt = 0, rt;
    Rep(i, N) {
        if (nlf[i])
            vt[++cnt] = i, rt = i;
        else {
            int mn = 0;
            Rep(j, N) if (f[j][i] &&
                          (mn == 0 || f[mn].count() > f[j].count()) && !flg[j])
                mn = j;
            assert(mn > 0);
            // printf("> %d %d\n", i, mn);
            t[i] = f[mn];
            flg[mn] = true;
        }
    }
    if (cnt == 0) {
        rt = 1;
        Rep(i, N) if (i != rt) printf("%d %d\n", i, rt);
        return;
    } else if (cnt == 2) {
        int rt2;
        Rep(i, N) if (nlf[i] && i != rt) rt2 = i;
        Rep(i, N) if (!nlf[i]) {
            for (int j = t[i]._Find_first(); j != t[i].size();
                 j = t[i]._Find_next(j))
                if (!nlf[j]) {
                    printf("%d %d\n", j, rt);
                    nlf[j] = true;
                }
            std::swap(rt, rt2);
        }
        return;
    }
    Rep(i, cnt) g[vt[i]].set(vt[i]);
    Rep(i, N) if (!nlf[i]) {
        for (int j = t[i]._Find_first(); j != t[i].size();
             j = t[i]._Find_next(j))
            if (!nlf[j]) t[i][j] = 0;
        Rep(j, cnt) if (g[vt[j]] == t[i]) {
            printf("%d %d\n", i, vt[j]);
            break;
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    FIN("3.in");
    FOUT("1.out");
#endif
    read(N);
    if (N == 1) return 0;
    if (N == 2) return puts("1 2"), 0;
    int k;
    Rep(i, N) {
        read(k);
        while (k--) f[i].set(input<int>());
    }
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular

namespace Base {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline void read(Tp &x) {
        x = input<Tp>();
    }
    template <typename Tp>
    inline void chmax(Tp &x, Tp y) {
        x < y ? x = y : 0;
    }
    template <typename Tp>
    inline void chmin(Tp &x, Tp y) {
        x > y ? x = y : 0;
    }
};  // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 1007
#define bsn std::bitset<MAX_N>
#define V std::vector

int N, tot;
int vt[MAX_N];
bsn f[MAX_N], g[MAX_N], t[MAX_N], tmp;
bool nlf[MAX_N], flg[MAX_N];

void print(bsn k) {
    puts("----begin----");
    for (int i = k._Find_first(); i != k.size(); i = k._Find_next(i))
        printf("%d ", i);
    puts("");
    puts("----end----");
}

void solve() {
    Rep(i, N) {
        Lep(j, i) {
            tmp = f[i] & f[j];
            if (tmp.count() == 2) {
                int u = tmp._Find_first(), v = tmp._Find_next(u);
                if (!g[u][v]) printf("%d %d\n", u, v);
                g[u].set(v), g[v].set(u);
                nlf[u] = nlf[v] = true;
            }
        }
    }
    int cnt = 0, rt;
    Rep(i, N) {
        if (nlf[i])
            vt[++cnt] = i, rt = i;
        else {
            int mn = 0;
            Rep(j, N) if (f[j][i] &&
                          (mn == 0 || f[mn].count() > f[j].count()) && !flg[j])
                mn = j;
            // printf("> %d %d\n", i, mn);
            t[i] = f[mn];
            flg[mn] = true;
        }
    }
    if (N == 50) printf("%d\n", cnt);
    if (cnt == 0) {
        rt = 1;
        Rep(i, N) if (i != rt) printf("%d %d\n", i, rt);
        return;
    } else if (cnt == 2) {
        int rt2;
        Rep(i, N) if (nlf[i] && i != rt) rt2 = i;
        Rep(i, N) if (!nlf[i]) {
            for (int j = t[i]._Find_first(); j != t[i].size();
                 j = t[i]._Find_next(j))
                if (!nlf[j]) {
                    printf("%d %d\n", j, rt);
                    nlf[j] = true;
                }
            std::swap(rt, rt2);
        }
        return;
    }
    Rep(i, cnt) g[vt[i]].set(vt[i]);
    Rep(i, N) if (!nlf[i]) {
        for (int j = t[i]._Find_first(); j != t[i].size();
             j = t[i]._Find_next(j))
            if (!nlf[j]) t[i][j] = 0;
        // printf("%d:\n", i);
        // print(t[i]);
        Rep(j, cnt) if ((g[vt[j]] & t[i]) == t[i]) {
            printf("%d %d\n", i, vt[j]);
            break;
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    FIN("3.in");
    FOUT("1.out");
#endif
    read(N);
    if (N == 1) return 0;
    if (N == 2) return puts("1 2"), 0;
    int k;
    Rep(i, N) {
        read(k);
        while (k--) f[i].set(input<int>());
    }
    solve();
    return 0;
}


#pragma comment(linker,"/STACK:64000000")
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <set>
#include <conio.h>

using namespace std;

#define WR printf
#define BR printf("\n")
#define RE scanf
#define PB push_back
#define SE second
#define FI first
#define MP make_pair

#define FOR(i,k,n) for(int i=(k); i<=(n); i++)
#define DFOR(i,k,n) for(int i=(k); i>=(n); i--)
#define SZ(a) (int)((a).size())
#define FA(i,v) FOR(i,0,SZ(v)-1)
#define RFA(i,v) DFOR(i,SZ(v)-1,0)
#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a,k,n,v) FOR(i,k,n) a[i] = v;
#define PRINT(a,k,n) FOR(i,k,n) printf("%d ",a[i]); BR;
#define PRINTM(a,n,m) FOR(i,1,n){ FOR(j,1,m) printf("%d ",a[i][j]); BR;} BR;
#define PRINTF(a,k,n) FOR(i,k,n) printf("%.4f ",a[i]); BR;
#define PRINTC(a,k,n) FOR(i,k,n) printf("%c",a[i]); BR;
#define PRINTMC(a,n,m) FOR(i,1,n){ FOR(j,1,m) printf("%c",a[i][j]); BR;} BR;

#define LL long long
#define VI  vector<int>
#define PAR pair<int ,int>
#define inf 1000000000

void __never(int a) {printf("\nOPS %d\n",a);}

#define ass(f) if  (!(f)) {__never(__LINE__);cout.flush();cerr.flush();abort();}

int n,m,x,y;
char a[1005][1005];
int w[1005],b[1005];
int sow[1005],sob[1005];
int dp[2][1005];

void sol()
{
	FOR(j,1,m){
		int cb = 0, cw = 0;
		FOR(i,1,n)
			if (a[i][j] == '#') cb++; else cw++;
		w[j] = cw;
		b[j] = cb;
	}
	CLR(sow); CLR(sob);
	FOR(i,1,m){
		sow[i] = sow[i-1]+w[i];
		sob[i] = sob[i-1]+b[i];
	}
	dp[0][0] = dp[0][1] = 0;
	dp[0][1] = w[1];
	dp[1][1] = b[1];
	PRINT(w,0,m);
	PRINT(b,0,m);
	PRINT(sow,0,m);
	PRINT(sob,0,m);

	FOR(i,0,x){
		dp[0][i] = sow[i];
		dp[1][i] = sob[i];
	}

	FOR(i,x+1,m)
	{
		int wmi = inf;
		int bmi = inf;
		FOR(a,x,y){
			if (i-a<0) break;
			if (i-a>0 && (i-a<x)) continue;
			wmi = min(wmi,dp[1][i-a] + sow[i]-sow[i-a+1]+w[i-a+1]);
			bmi = min(bmi,dp[0][i-a] + sob[i]-sob[i-a+1]+b[i-a+1]);
		}
		dp[0][i] = wmi;
		dp[1][i] = bmi;
	}
	PRINT(dp[0],0,m);
	PRINT(dp[1],0,m);

	printf("%d",min(dp[0][m],dp[1][m]));
	BR;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	FOR(i,1,1){
		scanf("%d %d %d %d\n",&n,&m,&x,&y);
		FOR(i,1,n){
			FOR(j,1,m-1)
				scanf("%c",&a[i][j]);
			scanf("%c\n",&a[i][m]);
		}
		//PRINTMC(a,n,m);
		sol();
		BR;
	}
	return 0;
}


#include <stdio.h>
#include <vector>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <queue>
#include <math.h>

#pragma comment(linker, "/stack:64000000")
const int INF = 1000 * 1000 * 1000;

using namespace std;

int a[100];
int b[100];

int k, s;

int n, m, x, y;
vector<int> sempty;
vector<int> sblack;

vector< string > shtrih_code;

int dpwhite[1005], dpblack[1005];

int main()
{
    cin >> n >> m >> x >> y;
    shtrih_code.resize(n);
    for(int i = 0; i < n; i++)
        cin >> shtrih_code[i];
    sempty.push_back(0);
    sblack.push_back(0);
    for(int j = 0; j < m; j++)
    {
        int s = 0;
        for(int i = 0; i < n; i++)
            if(shtrih_code[i][j] == '.')
                s++;
        sempty.push_back(s + sempty[j]);
        sblack.push_back(n - s + sblack[j]);
    }

    for(int i = 1; i <= m; i++)
    {
        dpblack[i] = INF;
        for(int j = i - x + 1; j > 0 && j > i - y; j--)
        {
            dpblack[i] = min(dpblack[i], dpwhite[j - 1] + sempty[i] - sempty[j - 1] );
        }
        dpwhite[i] = min(dpwhite[i - 1], dpblack[i - 1]) + sblack[i] - sblack[i - 1];
    }
    cout << min(dpblack[m], dpwhite[m]) << endl;

    return 0;
}


#include <stdio.h>
#include <vector>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <queue>
#include <math.h>

#pragma comment(linker, "/stack:64000000")
const int INF = 1000 * 1000 * 1000;

using namespace std;

int a[100];
int b[100];

int k, s;

int n, m, x, y;
vector<int> sempty;
vector<int> sblack;

vector< string > shtrih_code;

int dpwhite[1005], dpblack[1005];

int main()
{
    cin >> n >> m >> x >> y;
    shtrih_code.resize(n);
    for(int i = 0; i < n; i++)
        cin >> shtrih_code[i];
    sempty.push_back(0);
    sblack.push_back(0);
    for(int j = 0; j < m; j++)
    {
        int s = 0;
        for(int i = 0; i < n; i++)
            if(shtrih_code[i][j] == '.')
                s++;
        sempty.push_back(s + sempty[j]);
        sblack.push_back(n - s + sblack[j]);
    }

    for(int i = 1; i <= m; i++)
    {
        dpblack[i] = INF;
        dpwhite[i] = INF;
        for(int j = i - x + 1; j > 0 && j > i - y; j--)
        {
            dpblack[i] = min(dpblack[i], dpwhite[j - 1] + sempty[i] - sempty[j - 1] );
            dpwhite[i] = min(dpwhite[i], dpblack[j - 1] + sblack[i] - sblack[j - 1] );
        }
    }
    cout << min(dpblack[m], dpwhite[m]) << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <complex>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;

const int MAX_N=1000+10;
typedef long long ll;
typedef complex<double> point;

const int inf=1000*1000*100;
int a[MAX_N][MAX_N], s[MAX_N][MAX_N];
int ans[MAX_N][2];
int n, m, x, y;

int main(){

	cin >>n >>m >>x >>y;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++){
			char ch;	cin >>ch;
			a[i][j]=(ch=='#');
		}
	for(int i=0; i<=n+1; i++)
	for(int j=0; j<=m+1; j++)
		s[i][j]=0;
	for(int i=1; i<=n; i++)
	for(int j=1; j<=m; j++)
		s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];

	ans[0][0]=ans[0][1]=0;
	for(int j=1; j<=m; j++){
		ans[j][0]=ans[j][1]=inf;
		for(int t=0; t<2; t++){
			int first=max(j-y, 0), last=j-x;
			for(int l=first; l<=last; l++){
				int cur=ans[l][!t]+(t==0?s[n][j]-s[n][l]:(j-l)*n-(s[n][j]-s[n][l]));
				if(cur<ans[j][t])	ans[j][t]=cur;
			}
		}
	}
	cout <<min(ans[m][0], ans[m][1]) <<endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <complex>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;

const int MAX_N=1000+10;
typedef long long ll;
typedef complex<double> point;

const int inf=1000*1000*100;
int a[MAX_N][MAX_N], s[MAX_N][MAX_N];
int ans[MAX_N][2];
int n, m, x, y;

int main(){

	cin >>n >>m >>x >>y;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++){
			char ch;	cin >>ch;
			a[i][j]=(ch=='#');
		}
	for(int i=0; i<=n+1; i++)
	for(int j=0; j<=m+1; j++)
		s[i][j]=0;
	for(int i=1; i<=n; i++)
	for(int j=1; j<=m; j++)
		s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];

	ans[0][0]=ans[0][1]=0;
	for(int j=1; j<=m; j++){
		ans[j][0]=ans[j][1]=inf;
		for(int t=0; t<2; t++){
			int first=max(j-y, 0), last=max(j-x, 0);
			for(int l=first; l<=last; l++){
				int cur=ans[l][!t]+(t==0?s[n][j]-s[n][l]:(j-l)*n-(s[n][j]-s[n][l]));
				if(cur<ans[j][t])	ans[j][t]=cur;
			}
		}
	}
	cout <<min(ans[m][0], ans[m][1]) <<endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

int min(int a, int b)
{
    return (a<b)?a:b;
}

class Solver
{
    private:
        static const int inf=1000000000;
        int n, m, x,y;
        vector<int> aSh;
        vector<int> aShSum;
        vector<string> tmpS;
        vector<vector<int> > dp[2];
    public:
        void InputData()
        {
            cin>>m>>n>>x>>y;
            tmpS.resize(m);
            for(int i=0;i<m;i++)
            {
                cin>>tmpS[i];
            }

            aSh.resize(n,0);
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(tmpS[j][i]=='#')
                        aSh[i]++;
                }
            }
            aShSum.resize(n+1);
            aShSum[0]=0;
            for(int i=1;i<aShSum.size();i++)
            {
                aShSum[i]=aShSum[i-1]+aSh[i-1];
            }
        }

        void Solve()
        {
            dp[0].resize(n,vector<int>(n,-1));
            dp[1].resize(n,vector<int>(n,-1));
            for(int i=0;i<n;i++)
            {
                for(int j=i;j<n;j++)
                {
                    if(j-i+1<x)
                        dp[0][i][j]=dp[1][i][j]=inf;
                    else if(j-i+1==x)
                    {
                        dp[0][i][j]=aShSum[j+1]-aShSum[i];
                        dp[1][i][j]=m*(j-i+1)-(aShSum[j+1]-aShSum[i]);
                    }
                }
            }

            int res=f(0,n-1,0);
            res=min(res,f(0,n-1,1));

            printf("%d\n",res);
        }

        void OutputData()
        {
        }
    private:

        int f(int start, int end, int col)
        {
            if(dp[col][start][end]!=-1)
                return dp[col][start][end];

            int minRes=inf;
            int curRes;

            if(end-start+1>y)
            {
                for(int i=start;i<end;i++)
                {
                    curRes=f(start,i,col)+f(i+1,end,col);
                    curRes=min(curRes,f(start,i,(col+1)%2)+f(i+1,end,(col+1)%2));
                    if(curRes<minRes)
                        minRes=curRes;
                }
                return dp[col][start][end]=minRes;
            }
            else
            {
                if(col)
                    curRes=aShSum[end+1]-aShSum[start];
                else
                    curRes=m*(end-start+1)-(aShSum[end+1]-aShSum[start]);
                for(int i=start;i<end;i++)
                {
                    curRes=f(start,i,col)+f(i+1,end,col);
                    curRes=min(curRes,f(start,i,(col+1)%2)+f(i+1,end,(col+1)%2));
                    if(curRes<minRes)
                        minRes=curRes;
                }
                return dp[col][start][end]=minRes;
            }
        }
};

int main()
{
    Solver *S;

    int test;

    test=1;
    //scanf("%d",&test);
    for(int t=1;t<=test;t++)
    {
        S=new Solver();
        S->InputData();
        S->Solve();
        delete S;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

int min(int a, int b)
{
    return (a<b)?a:b;
}

class Solver
{
    private:
        static const int inf=1000000000;
        int n, m, x,y;
        vector<int> aSh;
        vector<int> aShSum;
        vector<string> tmpS;
        vector<vector<int> > dp[2];
    public:
        void InputData()
        {
            cin>>m>>n>>x>>y;
            tmpS.resize(m);
            for(int i=0;i<m;i++)
            {
                cin>>tmpS[i];
            }

            aSh.resize(n,0);
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(tmpS[j][i]=='#')
                        aSh[i]++;
                }
            }
            aShSum.resize(n+1);
            aShSum[0]=0;
            for(int i=1;i<aShSum.size();i++)
            {
                aShSum[i]=aShSum[i-1]+aSh[i-1];
            }
        }

        void Solve()
        {
            dp[0].resize(n,vector<int>(n,-1));
            dp[1].resize(n,vector<int>(n,-1));
            for(int i=0;i<n;i++)
            {
                for(int j=i;j<n;j++)
                {
                    if(j-i+1<x)
                        dp[0][i][j]=dp[1][i][j]=inf;
                    else if(j-i+1==x)
                    {
                        dp[0][i][j]=aShSum[j+1]-aShSum[i];
                        dp[1][i][j]=m*(j-i+1)-(aShSum[j+1]-aShSum[i]);
                    }
                }
            }

            int res=f(0,n-1,0);
            res=min(res,f(0,n-1,1));

            printf("%d\n",res);
        }

        void OutputData()
        {
        }
    private:

        int f(int start, int end, int col)
        {
            if(dp[col][start][end]!=-1)
                return dp[col][start][end];

            int minRes=inf;
            int curRes;

            if(end-start+1>y)
            {
                for(int i=start;i<end;i++)
                {
                    curRes=f(start,i,col)+f(i+1,end,col);
                    curRes=min(curRes,f(start,i,col%2)+f(i+1,end,(col+1)%2));
                    if(curRes<minRes)
                        minRes=curRes;
                }
                return dp[col][start][end]=minRes;
            }
            else
            {
                if(col)
                    curRes=aShSum[end+1]-aShSum[start];
                else
                    curRes=m*(end-start+1)-(aShSum[end+1]-aShSum[start]);
                for(int i=start;i<end;i++)
                {
                    curRes=f(start,i,col)+f(i+1,end,col);
                    curRes=min(curRes,f(start,i,col%2)+f(i+1,end,(col+1)%2));
                    if(curRes<minRes)
                        minRes=curRes;
                }
                return dp[col][start][end]=minRes;
            }
        }
};

int main()
{
    Solver *S;

    int test;

    test=1;
    //scanf("%d",&test);
    for(int t=1;t<=test;t++)
    {
        S=new Solver();
        S->InputData();
        S->Solve();
        delete S;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

int min(int a, int b)
{
    return (a<b)?a:b;
}

class Solver
{
    private:
        static const int inf=1000000000;
        int n, m, x,y;
        vector<int> aSh;
        vector<int> aShSum;
        vector<string> tmpS;
        vector<int> dp[2];
    public:
        void InputData()
        {
            cin>>m>>n>>x>>y;
            tmpS.resize(m);
            for(int i=0;i<m;i++)
            {
                cin>>tmpS[i];
            }

            aSh.resize(n,0);
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(tmpS[j][i]=='#')
                        aSh[i]++;
                }
            }
            aShSum.resize(n+1);
            aShSum[0]=0;
            for(int i=1;i<aShSum.size();i++)
            {
                aShSum[i]=aShSum[i-1]+aSh[i-1];
            }
        }

        void Solve()
        {
            dp[0].resize(n+1,-1);
            dp[1].resize(n+1,-1);
            dp[0][0]=dp[1][0]=0;
            int res=f(n,0);
            res=min(res,f(n,1));

            printf("%d\n",res);
        }

        void OutputData()
        {
        }
    private:

        int f(int end, int col)
        {
            if(dp[col][end]!=-1)
                return dp[col][end];
            if(end<x)
                return dp[col][end]=inf;
            if(end==x)
            {
                if(col)
                    return dp[col][end]=aShSum[end]-aShSum[0];
                else
                    return dp[col][end]=(end)*m-(aShSum[end]-aShSum[0]);
            }

            int minRes=inf;
            int curRes;

            for(int len=x;len<=end && len<=y;len++)
            {
                curRes=f(end-len,(col+1)%2);
                if(col)
                    curRes+=aShSum[end]-aShSum[end-len];
                else
                    curRes+=(len)*m-(aShSum[end]-aShSum[end-len]);

                if(curRes<minRes)
                        minRes=curRes;
            }
            return dp[col][end]=minRes;
        }
};

int main()
{
    Solver *S;

    int test;

    test=1;
    //scanf("%d",&test);
    for(int t=1;t<=test;t++)
    {
        S=new Solver();
        S->InputData();
        S->Solve();
        S->OutputData();
        delete S;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

int min(int a, int b)
{
    return (a<b)?a:b;
}

class Solver
{
    private:
        static const int inf=1000000000;
        int n, m, x,y;
        vector<int> aSh;
        vector<int> aShSum;
        vector<string> tmpS;
        vector<int> dp[2];
    public:
        void InputData()
        {
            cin>>m>>n>>x>>y;
            tmpS.resize(m);
            for(int i=0;i<m;i++)
            {
                cin>>tmpS[i];
            }

            aSh.resize(n,0);
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(tmpS[j][i]=='#')
                        aSh[i]++;
                }
            }
            aShSum.resize(n+1);
            aShSum[0]=0;
            for(int i=1;i<aShSum.size();i++)
            {
                aShSum[i]=aShSum[i-1]+aSh[i-1];
            }
        }

        void Solve()
        {
            dp[0].resize(n,-1);
            dp[1].resize(n,-1);

            int res=f(n-1,0);
            res=min(res,f(n-1,1));

            printf("%d\n",res);
        }

        void OutputData()
        {
        }
    private:

        int f(int end, int col)
        {
            if(dp[col][end]!=-1)
                return dp[col][end];
            if(end+1<x)
                return dp[col][end]=inf;
            if(end+1==x)
            {
                if(col)
                    return dp[col][end]=aShSum[end+1]-aShSum[0];
                else
                    return dp[col][end]=(end-0+1)*m-(aShSum[end+1]-aShSum[0]);
            }

            int minRes=inf;
            int curRes;

            for(int i=end-x;i>=0 && end-i<=y;i--)
            {
                curRes=f(i,(col+1)%2);
                if(col)
                    curRes+=aShSum[end+1]-aShSum[i+1];
                else
                    curRes+=(end-i)*m-(aShSum[end+1]-aShSum[i+1]);

                if(curRes<minRes)
                        minRes=curRes;
            }
            return dp[col][end]=minRes;
        }
};

int main()
{
    Solver *S;

    int test;

    test=1;
    //scanf("%d",&test);
    for(int t=1;t<=test;t++)
    {
        S=new Solver();
        S->InputData();
        S->Solve();
        S->OutputData();
        delete S;
    }

    return 0;
}


// I'm the Topcoder
//C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
//C++
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <stack>
#include <string>
#include <list>
#include <queue>
#include <map>
#include <vector>
#include <deque>
#include <set>
using namespace std;

//*************************OUTPUT*************************
#ifdef WIN32
#define INT64 "%I64d"
#define UINT64 "%I64u"
#else
#define INT64 "%lld"
#define UINT64 "%llu"
#endif

//**************************CONSTANT***********************
#define INF 0x7F7F7F7F
#define eps 1e-8
#define PI acos(-1.)
#define PI2 asin (1.);
//typedef long long LL;
typedef __int64 LL;   //codeforces
typedef unsigned int ui;
typedef unsigned long long ui64;
#define MP make_pair
typedef vector<int> VI;
typedef pair<int, int> PII;
#define pb push_back
#define mp make_pair

//***************************SENTENCE************************
#define CL(a,b) memset (a, b, sizeof (a))
#define sqr(a,b) sqrt ((double)(a)*(a) + (double)(b)*(b))

//****************************FUNCTION************************
template <typename T> double DIS(T va, T vb) { return sqr(va.x - vb.x, va.y - vb.y); }
template <class T> inline T INTEGER_LEN(T v) { int len = 1; while (v /= 10) ++len; return len; }
template <typename T> inline T square(T va, T vb) { return va * va + vb * vb; }

// aply for the memory of the stack
#pragma comment (linker, "/STACK:1024000000,1024000000")
//end

#define CY 1005

char S[CY][CY];
int w[CY], b[CY], dp[CY][2];
int N, M, x, y;

void input(int n, int m) {
	for (int i = 0; i < n; ++i) {
		scanf("%s", S[i]);
	}
	memset(b, 0, sizeof(b));
	memset(w, 0, sizeof(w));
	for (int j = 0; j < m; ++j) {
		for (int i = 0; i < n; ++i) {
			if (S[i][j] == '#') b[j + 1]++;
			else w[j + 1]++;
		}
	}
	for (int j = 1; j <= m; ++j) {
		w[j] += w[j - 1];
		b[j] += b[j - 1];
	}
}

void solve(int n, int m) {
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = dp[0][1] = 0;
	for (int j = 0; j < m; ++j) {
		for (int i = x; i <= y; ++i) {
			if (j + x > m) break;
			dp[j + i][0] = min(dp[j + i][0], dp[j][1] + w[j + i] - w[j]);
			dp[j + i][1] = min(dp[j + i][1], dp[j][0] + b[j + i] - b[j]);
		}
	}
	int ans = INF;
	ans = min(dp[m][0], dp[m][1]);
	cout << ans << endl;
}

int main(void) {
	while (4 == scanf("%d%d%d%d", &N, &M, &x, &y)) {
		input(N, M);
		solve(N, M);
	}
	return 0;
}


// I'm the Topcoder
//C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
//C++
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cctype>
#include <stack>
#include <string>
#include <list>
#include <queue>
#include <map>
#include <vector>
#include <deque>
#include <set>
using namespace std;

//*************************OUTPUT*************************
#ifdef WIN32
#define INT64 "%I64d"
#define UINT64 "%I64u"
#else
#define INT64 "%lld"
#define UINT64 "%llu"
#endif

//**************************CONSTANT***********************
#define INF 0x7F7F7F7F
#define eps 1e-8
#define PI acos(-1.)
#define PI2 asin (1.);
//typedef long long LL;
typedef __int64 LL;   //codeforces
typedef unsigned int ui;
typedef unsigned long long ui64;
#define MP make_pair
typedef vector<int> VI;
typedef pair<int, int> PII;
#define pb push_back
#define mp make_pair

//***************************SENTENCE************************
#define CL(a,b) memset (a, b, sizeof (a))
#define sqr(a,b) sqrt ((double)(a)*(a) + (double)(b)*(b))

//****************************FUNCTION************************
template <typename T> double DIS(T va, T vb) { return sqr(va.x - vb.x, va.y - vb.y); }
template <class T> inline T INTEGER_LEN(T v) { int len = 1; while (v /= 10) ++len; return len; }
template <typename T> inline T square(T va, T vb) { return va * va + vb * vb; }

// aply for the memory of the stack
#pragma comment (linker, "/STACK:1024000000,1024000000")
//end

#define CY 1005

char S[CY][CY];
int w[CY], b[CY], dp[CY][2];
int N, M, x, y;

void input(int n, int m) {
	for (int i = 0; i < n; ++i) {
		scanf("%s", S[i]);
	}
	memset(b, 0, sizeof(b));
	memset(w, 0, sizeof(w));
	for (int j = 0; j < m; ++j) {
		for (int i = 0; i < n; ++i) {
			if (S[i][j] == '#') b[j + 1]++;
			else w[j + 1]++;
		}
	}
	for (int j = 1; j <= m; ++j) {
		w[j] += w[j - 1];
		b[j] += b[j - 1];
	}
}

void solve(int n, int m) {
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = dp[0][1] = 0;
	for (int j = 0; j < m; ++j) {
		for (int i = x; i <= y; ++i) {
			if (j + i > m) break;
			dp[j + i][0] = min(dp[j + i][0], dp[j][1] + w[j + i] - w[j]);
			dp[j + i][1] = min(dp[j + i][1], dp[j][0] + b[j + i] - b[j]);
		}
	}
	int ans = INF;
	ans = min(dp[m][0], dp[m][1]);
	cout << ans << endl;
}

int main(void) {
	while (4 == scanf("%d%d%d%d", &N, &M, &x, &y)) {
		input(N, M);
		solve(N, M);
	}
	return 0;
}


#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<memory>
#include<vector>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int dp[1005][1005][2];
int char1[1005],char2[1005];        //char1 = '#' char2 = '.'
char a[1005][1005];
int maxint=99999999;
int main()
{
    int n,m,x,y;
    scanf("%d%d%d%d",&n,&m,&x,&y);
    if (y>m) y=m;
    int i,j;
    for (i=1;i<=n;i++)
    {
        scanf("%s",a[i]);
    }
    for (i=0;i<m;i++)
    {
        char1[i+1]=0;
        char2[i+1]=0;
        for (j=1;j<=n;j++)
        {
            if (a[j][i]=='#') char1[i+1]++; else char2[i+1]++;
        }
    }
    for (i=1;i<=y;i++)
    {
        dp[1][i][0]=maxint;
        dp[1][i][1]=maxint;
    }
    dp[1][1][0]=char2[1];
    dp[1][1][1]=char1[1];
    for (i=2;i<=m;i++)
    {
        for (j=2;j<=y;j++)
        {
            dp[i][j][0]=dp[i-1][j-1][0]+char2[i];
            dp[i][j][1]=dp[i-1][j-1][1]+char1[i];
        }
        dp[i][1][0]=maxint;
        dp[i][1][1]=maxint;
        for (j=x;j<=y;j++)
        {
            dp[i][1][0]=min(dp[i][1][0],dp[i-1][j][1]+char2[i]);
            dp[i][1][1]=min(dp[i][1][1],dp[i-1][j][0]+char1[i]);
        }
    }
    int mi=maxint;
    for (i=x;i<=y;i++)
    {
        mi=min(mi,min(dp[m][i][0],dp[m][i][1]));
    }
    cout<<mi<<endl;
    return 0;
}


#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<memory>
#include<vector>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int dp[1005][1005][2];
int char1[1005],char2[1005];        //char1 = '#' char2 = '.'
char a[1005][1005];
int maxint=99999999;
int main()
{
    int n,m,x,y;
    scanf("%d%d%d%d",&n,&m,&x,&y);
    int i,j;
    for (i=1;i<=n;i++)
    {
        scanf("%s",a[i]);
    }
    for (i=0;i<m;i++)
    {
        char1[i+1]=0;
        char2[i+1]=0;
        for (j=1;j<=n;j++)
        {
            if (a[j][i]=='#') char1[i+1]++; else char2[i+1]++;
        }
    }
    for (i=1;i<=y;i++)
    {
        dp[1][i][0]=maxint;
        dp[1][i][1]=maxint;
    }
    dp[1][1][0]=char2[i];
    dp[1][1][1]=char1[i];
    for (i=2;i<=m;i++)
    {
        for (j=2;j<=y;j++)
        {
            dp[i][j][0]=dp[i-1][j-1][0]+char2[i];
            dp[i][j][1]=dp[i-1][j-1][1]+char1[i];
        }
        dp[i][1][0]=maxint;
        dp[i][1][1]=maxint;
        for (j=x;j<=y;j++)
        {
            dp[i][1][0]=min(dp[i][1][0],dp[i-1][j][1]+char2[i]);
            dp[i][1][1]=min(dp[i][1][1],dp[i-1][j][0]+char1[i]);
        }
    }
    int mi=maxint;
    for (i=x;i<=y;i++)
    {
        mi=min(mi,min(dp[m][i][0],dp[m][i][1]));
    }
    cout<<mi<<endl;
    return 0;
}


#include <ios>
#include <iostream>
#include <string>

int black[1005] = {};
int prefx[1005] = {};
int dp[1005][2] = {}; //index, black/white

int lines, m, x, y;

int minimum(int a, int b)
{
    return (a < b ? a : b);
}

int minchange(int n, bool isblack)
{
    int ans = 99999999;

    if (dp[n][isblack] == -1)
    {
        for (int i = x; i <= y; i++)
        {
            if (isblack) ans = minimum(ans, ((lines*(i))-(prefx[n]-prefx[n-i-1])) + minchange(n-i, false));
            else ans = minimum(ans, (prefx[n]-prefx[n-i-1]) + minchange(n-i, true));
        }
        dp[n][isblack] = ans;
    }
    return dp[n][isblack];
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::string k;

    std::cin >> lines >> m >> x >> y;
    for (int i = 0; i < lines; i++)
    {
        std::cin >> k;
        for (int j = 0; j < m; j++)
        {
            if (k.at(j) == '#') black[j+1]++;
        }
    }

    prefx[0] = 0;
    for (int i = 1; i <= m; i++) prefx[i] = prefx[i-1] + black[i];

    dp[0][0] = 0;
    dp[0][1] = 0;
    for (int i = 1; i < x; i++)
    {
        dp[i][0] = 99999999;
        dp[i][1] = 99999999;
    }

    for (int i = x; i <= m; i++)
    {
        dp[i][0] = -1;
        dp[i][1] = -1;
    }

    std::cout << minimum(minchange(m, true), minchange(m, false)) << std::endl;
}


#include <ios>
#include <iostream>
#include <string>

int black[1005] = {};
int prefx[1005] = {};
int dp[1005][2] = {}; //index, black/white

int lines, m, x, y;

int minimum(int a, int b)
{
    return (a < b ? a : b);
}

int minchange(int n, bool isblack)
{
    int ans = 99999999;

    if (dp[n][isblack] == -1)
    {
        for (int i = x; i <= y; i++)
        {
            if (isblack) ans = minimum(ans, ((lines*i)-(prefx[n]-prefx[n-i])) + minchange(n-i, false));
            else ans = minimum(ans, (prefx[n]-prefx[n-i]) + minchange(n-i, true));
        }
        dp[n][isblack] = ans;
    }
    return dp[n][isblack];
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::string k;

    std::cin >> lines >> m >> x >> y;
    for (int i = 0; i < lines; i++)
    {
        std::cin >> k;
        for (int j = 0; j < m; j++)
        {
            if (k.at(j) == '#') black[j+1]++;
        }
    }

    prefx[0] = 0;
    for (int i = 1; i <= m; i++) prefx[i] = prefx[i-1] + black[i];

    dp[0][0] = 0;
    dp[0][1] = 0;
    for (int i = 1; i < x; i++)
    {
        dp[i][0] = 99999999;
        dp[i][1] = 99999999;
    }

    for (int i = x; i <= m; i++)
    {
        dp[i][0] = -1;
        dp[i][1] = -1;
    }

    std::cout <<  minimum(minchange(m, true), minchange(m, false)) << std::endl;
}


#include <ios>
#include <iostream>
#include <string>

int black[1005] = {};
int prefx[1005] = {};
int dp[1005][2] = {}; //index, black/white

int lines, m, x, y;

int minimum(int a, int b)
{
    return (a < b ? a : b);
}

int minchange(int n, bool isblack)
{
    int ans = 99999999;

    if (dp[n][isblack] == -1)
    {
        for (int i = x; i <= y; i++)
        {
            if (i > n) break;

            if (isblack) ans = minimum(ans, ((lines*i)-(prefx[n]-prefx[n-i])) + minchange(n-i, false));
            else ans = minimum(ans, (prefx[n]-prefx[n-i]) + minchange(n-i, true));
        }
        dp[n][isblack] = ans;
    }
    return dp[n][isblack];
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::string k;

    std::cin >> lines >> m >> x >> y;
    for (int i = 0; i < lines; i++)
    {
        std::cin >> k;
        for (int j = 0; j < m; j++)
        {
            if (k.at(j) == '#') black[j+1]++;
        }
    }

    prefx[0] = 0;
    for (int i = 1; i <= m; i++) prefx[i] = prefx[i-1] + black[i];

    dp[0][0] = 0;
    dp[0][1] = 0;
    for (int i = 1; i < x; i++)
    {
        dp[i][0] = 99999999;
        dp[i][1] = 99999999;
    }

    for (int i = x; i <= m; i++)
    {
        dp[i][0] = -1;
        dp[i][1] = -1;
    }

    std::cout <<  minimum(minchange(m, true), minchange(m, false)) << std::endl;
}


#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
using namespace std;

typedef long long ll;

int dp[1001][1001][2];
const int INF = 2e9;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
#endif
	memset(dp, -1, sizeof(dp[0][0][0])*1001*1001*2);
	ll n,m,x,y;
	cin >> n >> m >> x >> y;
	cin.ignore();
	vector<int> black(m+1,0), white(m+1,0);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char c;
			scanf("%c", &c);
			if (c == '#')
				black[j+1]++;
			else
				white[j+1]++;
		}
		cin.ignore();
	}
	dp[x][x][0] = dp[x][x][1] = 0;
	for (int i = 1; i <= x; i++)
	{
		dp[x][x][0] += white[i];
		dp[x][x][1] += black[i];
	}
	for (int j = x+1; j <= m; j++)
	{
		dp[j][1][0] = dp[j][1][1] = INF;
		for (int i = x; i <= y; i++)
		{
			if (dp[j-1][i][1] > -1)
				dp[j][1][0] = min(dp[j][1][0], dp[j-1][i][1] + white[j]);
			if (dp[j-1][i][0] > -1)
				dp[j][1][1] = min(dp[j][1][1], dp[j-1][i][0] + black[j]);
		}
		for (int i = 2; i <= y; i++)
		{
			if (dp[j-1][i-1][0] > -1)
				dp[j][i][0] = dp[j-1][i-1][0] + white[j];
			if (dp[j-1][i-1][1] > -1)
				dp[j][i][1] = dp[j-1][i-1][1] + black[j];
		}
	}
	int best = INF;
	for (int i = x; i <= y; i++)
	{
		if (dp[m][i][0] == -1)
			dp[m][i][0] = INF;
		if (dp[m][i][1] == -1)
			dp[m][i][1] = INF;
		best = min(best, min(dp[m][i][0],dp[m][i][1]));
	}
	cout << best << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
using namespace std;

typedef long long ll;

int dp[1001][1001][2];
const int INF = 2e9;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
#endif
	memset(dp, -1, sizeof(dp[0][0][0])*1001*1001*2);
	ll n,m,x,y;
	cin >> n >> m >> x >> y;
	cin.ignore();
	vector<int> black(m+1,0), white(m+1,0);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char c;
			scanf("%c", &c);
			if (c == '#')
				black[j+1]++;
			else
				white[j+1]++;
		}
		cin.ignore();
	}
	dp[x][x][0] = dp[x][x][1] = 0;
	for (int i = 1; i <= x; i++)
	{
		dp[x][x][0] += white[i];
		dp[x][x][1] += black[i];
	}
	for (int j = x+1; j <= m; j++)
	{
		dp[j][1][0] = dp[j][1][1] = INF;
		for (int i = x; i <= y; i++)
		{
			if (dp[j-1][i][1] > -1)
				dp[j][1][0] = min(dp[j][1][0], dp[j-1][i][1] + white[j]);
			if (dp[j-1][i][0] > -1)
				dp[j][1][1] = min(dp[j][1][1], dp[j-1][i][0] + black[j]);
		}
		for (int i = 2; i <= y; i++)
		{
			if (dp[j-1][i-1][0] > -1)
				dp[j][i][0] = dp[j-1][i-1][0] + white[j];
			if (dp[j-1][i-1][1] > -1)
				dp[j][i][1] = dp[j-1][i-1][1] + black[j];
		}
	}
	int best = INF;
	for (int i = x; i <= y; i++)
	{
		best = min(best, min(dp[m][i][0],dp[m][i][1]));
	}
	cout << best << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;

const ll modulo = 1000000007;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ll n,m,x,y;
	cin >> n >> m >> x >> y;
	cin.ignore();
	vector<int> black(m+1,0), white(m+1,0), dp(m+1,0);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char c;
			scanf("%c", &c);
			if (c == '#')
				black[j+1]++;
			else
				white[j+1]++;
		}
		cin.ignore();
	}
	if (x > 1 || black[1] < white[1])
		dp[1] = black[1];
	else
		dp[1] = white[1];
	int bl = (dp[1] == white[1]);
	for (int i = 2; i <= m; i++)
	{
		if (i+1 < x || white[i] > black[i])
		{
			dp[i] = dp[i-1] + black[i];
		}
		else
		{
			if (bl+1 < x)
			{
				int cand = dp[i-1] + black[i], sec = dp[i-x];
				for (int j = 1; j < x; j++)
				{
					sec += white[i-j];
				}
				if (cand <= sec)
				{
					dp[i] = cand;
					bl = 0;
				}
				else
				{
					dp[i] = sec;
					bl = x;
				}
			}
			else if (bl+1 > y)
			{
				int cand = dp[i-1] + black[i], sec = dp[i-1] + white[i] - white[i-y] + black[i-y];
				if (cand <= sec)
				{
					dp[i] = cand;
					bl = 0;
				}
				else
				{
					dp[i] = sec;
					bl = y;
				}
			}
			else
			{
				dp[i] = dp[i-1] + white[i];
				bl++;
			}
		}
	}
	cout << dp[m];
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;

const ll modulo = 1000000007;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	ll n,m,x,y;
	cin >> n >> m >> x >> y;
	cin.ignore();
	vector<int> black(m+1,0), white(m+1,0), dp(m+1,0);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char c;
			scanf("%c", &c);
			if (c == '#')
				black[j+1]++;
			else
				white[j+1]++;
		}
		cin.ignore();
	}
	if (x > 1 || black[1] < white[1])
		dp[1] = black[1];
	else
		dp[1] = white[1];
	int bl = (dp[1] == white[1]);
	for (int i = 2; i <= m; i++)
	{
		if (i < x || white[i] > black[i])
		{
			dp[i] = dp[i-1] + black[i];
		}
		else
		{
			if (bl+1 < x)
			{
				int cand = dp[i-1] + black[i], sec = dp[i-x];
				for (int j = 1; j < x; j++)
				{
					sec += white[i-j];
				}
				if (cand <= sec)
				{
					dp[i] = cand;
					bl = 0;
				}
				else
				{
					dp[i] = sec;
					bl = x;
				}
			}
			else if (bl+1 > y)
			{
				int cand = dp[i-1] + black[i], sec = dp[i-1] + white[i] - white[i-y] + black[i-y];
				if (cand <= sec)
				{
					dp[i] = cand;
					bl = 0;
				}
				else
				{
					dp[i] = sec;
					bl = y;
				}
			}
			else
			{
				dp[i] = dp[i-1] + white[i];
				bl++;
			}
		}
	}
	cout << dp[m];
    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>
#include <memory.h>
#include <string.h>
#include <time.h>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:200000000")

#define mp make_pair
#define pb push_back
#define ll long long
#define sz(x) (int)(x).size()

int dp[1010][2];
string matrix[1010];
int sum[1010][1010];

int main()
{
    //freopen("output.txt","wt",stdout);
    //freopen("a.in","rt",stdin);
    //freopen("a.out","wt",stdout);

    int n, m, x, y;
    scanf("%d %d %d %d", &n, &m, &x, &y);
    for(int i = 0; i < n; i++) cin >> matrix[i];
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(matrix[i][j] == '.') sum[i+1][j+1] = 1;
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            sum[i][j] += sum[i][j-1];
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            sum[i][j] += sum[i-1][j];
        }
    }

    for(int i = 1; i <= m + 1; i++)
        dp[i][0]= 1e9, dp[i][1] = 1e9;
    dp[1][0] = 0;
    dp[1][1] = 0;

    for(int i = 1; i <= m; i++) {
        // сначала будем красить в черный (#)
        for(int nxt = i + x, maxnxt = min(i + y, m + 1); nxt <= maxnxt; nxt++) {
            int ccc = sum[n][nxt-1] - sum[n][i-1]; // столько белых перекрасить в черный
            dp[nxt][1] = min(dp[nxt][1], dp[i][0] + ccc);
        }
        for(int nxt = i + x, maxnxt = min(i + y, m + 1); nxt <= maxnxt; nxt++) {
            int ccc = n * (nxt - i) - sum[n][nxt-1] + sum[n][i-1]; // столько белых перекрасить в черный
            dp[nxt][0] = min(dp[nxt][0], dp[i][1] + ccc);
        }
    }
    printf("%d\n", min(dp[m+1][0], dp[m+1][1]));

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstdio>

using namespace std;

#pragma comment(linker, "/STACK:100000000")

int mas[4444];
map<int,vector<int>> v;
map<int, int> cnt;

int main() {
    //freopen("a.txt", "rt", stdin);
    //freopen("b.txt", "wt", stdout);

    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &mas[i]);
        v[mas[i]].push_back(i);
        cnt[mas[i]]++;
    }
    if(cnt.size() < 2) {
        printf("%d\n", n);
        return 0;
    }
    int maxlen = 0;
    map<int, int>::iterator it = cnt.end();
    it--;
    map<int, int>::iterator stop = cnt.begin();
    stop--;
    while(it != stop) {
        map<int, int>::iterator it2 = it;
        while(it2 != stop) {
            if((*it2).second + (*it).second < maxlen) {
                it2--;
                continue;
            }
            if(it2 == it && (*it2).second > maxlen) {
                maxlen = (*it2).second;
                it2--;
                continue;
            }
            else if(it2 == it){
                it2--;
                continue;
            }
            int val1 = (*it).first, val2 = (*it2).first;
            map<int, vector<int>>::iterator vit1 = v.find(val1);
            map<int, vector<int>>::iterator vit2 = v.find(val2);
            int s1 = (*vit1).second.size();
            int s2 = (*vit2).second.size();

            int res = 1;
            int p1 = 0, p2 = 0;
            bool fl = true;
            if((*vit1).second[p1] > v[val2][p2]) fl = false;
            while(true) {
                if(fl) {
                    if(p2 >= s2) break;
                    if((*vit1).second[p1] < (*vit2).second[p2]) {
                        res++;
                        fl = false;
                        continue;
                    }
                    else {
                        p2++;
                        continue;
                    }
                }
                if(!fl) {
                    if(p1 >= s1) break;
                    if((*vit1).second[p1] > (*vit2).second[p2]) {
                        res++;
                        fl = true;
                        continue;
                    }
                    else {
                        p1++;
                        continue;
                    }
                }
            }
            if(res > maxlen) maxlen = res;
            it2--;
        }
        it--;
    }
    printf("%d\n", maxlen);
    return 0;
}


#include <fstream>
#include <iostream>

using namespace std;

const long long N = 1003;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N][2];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	for (long long i = 0; i < n; ++i) {
		mem[0][i][0] = INF;
		mem[0][i][1] = INF;
	}
	mem[0][0][0] = 0;
	mem[0][0][1] = 0;

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn_to_zero = mem[i - 1][x][1];
		long long mn_to_one = mem[i - 1][x][0];
		for (long long k = x; k <= y; ++k) {
			mn_to_zero = min(mem[i - 1][k][1], mn_to_zero);
			mn_to_one = min(mem[i - 1][k][0], mn_to_one);
		}
		mem[i][0][0] = mn_to_zero + count_to_zero;
		mem[i][0][1] = mn_to_one + count_to_one;

		for (long long k = 1; k <= y; ++k) {
			mem[i][k][1] = mem[i - 1][k - 1][1] + count_to_one;
			mem[i][k][0] = mem[i - 1][k - 1][0] + count_to_zero;
		}
	}

	long long mn = min(mem[m][0][0], mem[m][0][1]);
	for (long long k = x; k <= y; ++k) {
		mn = min(mem[m][k][1], min(mem[m][k][0], mn));
	}

	cout << mn << endl;
	return 0;
}


#include <fstream>
#include <iostream>

using namespace std;

const long long N = 1003;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N][2];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	for (long long i = 0; i <= m; ++i) {
		mem[0][i][0] = INF;
		mem[0][i][1] = INF;
	}

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn_to_zero = (i - 1 == 0) ? 0 : mem[i - 1][x - 1][1];
		long long mn_to_one = (i - 1 == 0) ? 0 : mem[i - 1][x - 1][0];
		for (long long k = x - 1; k < y; ++k) {
			mn_to_zero = min(mem[i - 1][k][1], mn_to_zero);
			mn_to_one = min(mem[i - 1][k][0], mn_to_one);
		}
		mem[i][0][0] = mn_to_zero + count_to_zero;
		mem[i][0][1] = mn_to_one + count_to_one;

		for (long long k = 1; k < y; ++k) {
			mem[i][k][1] = mem[i - 1][k - 1][1] + count_to_one;
			mem[i][k][0] = mem[i - 1][k - 1][0] + count_to_zero;
		}
	}

	long long mn = mem[m][x - 1][1];
	for (long long k = x - 1; k < y; ++k) {
		mn = min(mem[m][k][1], min(mem[m][k][0], mn));
	}

	cout << mn << endl;
	return 0;
}


#include <fstream>
#include <iostream>

using namespace std;

const long long N = 1003;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N][2];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	for (long long i = 0; i < n; ++i) {
		mem[0][i][0] = INF;
		mem[0][i][1] = INF;
	}
	mem[0][0][0] = 0;
	mem[0][0][1] = 0;

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn_to_zero = mem[i - 1][x - 1][1];
		long long mn_to_one = mem[i - 1][x - 1][0];
		for (long long k = x - 1; k < y; ++k) {
			mn_to_zero = min(mem[i - 1][k][1], mn_to_zero);
			mn_to_one = min(mem[i - 1][k][0], mn_to_one);
		}
		mem[i][0][0] = mn_to_zero + count_to_zero;
		mem[i][0][1] = mn_to_one + count_to_one;

		for (long long k = 1; k < y; ++k) {
			mem[i][k][1] = mem[i - 1][k - 1][1] + count_to_one;
			mem[i][k][0] = mem[i - 1][k - 1][0] + count_to_zero;
		}
	}

	long long mn = mem[m][x - 1][1];
	for (long long k = x - 1; k < y; ++k) {
		mn = min(mem[m][k][1], min(mem[m][k][0], mn));
	}

	cout << mn << endl;
	return 0;
}


#include <fstream>
#include <iostream>

using namespace std;

const long long N = 1003;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N][2];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	for (long long i = 0; i < n; ++i) {
		mem[0][i][0] = INF;
		mem[0][i][1] = INF;
	}

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn_to_zero = (i - 1 == 0) ? 0 : mem[i - 1][x - 1][1];
		long long mn_to_one = (i - 1 == 0) ? 0 : mem[i - 1][x - 1][0];
		for (long long k = x - 1; k < y; ++k) {
			mn_to_zero = min(mem[i - 1][k][1], mn_to_zero);
			mn_to_one = min(mem[i - 1][k][0], mn_to_one);
		}
		mem[i][0][0] = mn_to_zero + count_to_zero;
		mem[i][0][1] = mn_to_one + count_to_one;

		for (long long k = 1; k < y; ++k) {
			mem[i][k][1] = mem[i - 1][k - 1][1] + count_to_one;
			mem[i][k][0] = mem[i - 1][k - 1][0] + count_to_zero;
		}
	}

	long long mn = mem[m][x - 1][1];
	for (long long k = x - 1; k < y; ++k) {
		mn = min(mem[m][k][1], min(mem[m][k][0], mn));
	}

	cout << mn << endl;
	return 0;
}


#include <fstream>
//#include <iostream>

using namespace std;

const long long N = 1003;

ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N][2];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	for (long long i = 0; i < n; ++i) {
		mem[0][i][0] = INF;
		mem[0][i][1] = INF;
	}
	mem[0][0][0] = 0;
	mem[0][0][1] = 0;

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn_to_zero = mem[i - 1][x][1];
		long long mn_to_one = mem[i - 1][x][0];
		for (long long k = x; k < y; ++k) {
			mn_to_zero = min(mem[i - 1][k][1], mn_to_zero);
			mn_to_one = min(mem[i - 1][k][0], mn_to_one);
		}
		mem[i][0][0] = mn_to_zero + count_to_zero;
		mem[i][0][1] = mn_to_one + count_to_one;

		for (long long k = 1; k < y; ++k) {
			mem[i][k][1] = mem[i - 1][k - 1][1] + count_to_one;
			mem[i][k][0] = mem[i - 1][k - 1][0] + count_to_zero;
		}
	}

	long long mn = min(mem[m][0][0], mem[m][0][1]);
	for (long long k = x; k < y; ++k) {
		mn = min(mem[m][k][1], min(mem[m][k][0], mn));
	}

	cout << mn << endl;
	return 0;
}


#include <fstream>
#include <iostream>

using namespace std;

const long long N = 1003;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N][2];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	y = min(m, y);
	x = min(x, y);

	for (long long i = 0; i <= m; ++i) {
		mem[0][i][0] = INF;
		mem[0][i][1] = INF;
	}

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn_to_zero = (i - 1 == 0) ? 0 : mem[i - 1][x - 1][1];
		long long mn_to_one = (i - 1 == 0) ? 0 : mem[i - 1][x - 1][0];
		for (long long k = x - 1; k < y; ++k) {
			mn_to_zero = min(mem[i - 1][k][1], mn_to_zero);
			mn_to_one = min(mem[i - 1][k][0], mn_to_one);
		}
		mem[i][0][0] = mn_to_zero + count_to_zero;
		mem[i][0][1] = mn_to_one + count_to_one;

		for (long long k = 1; k < y; ++k) {
			mem[i][k][1] = mem[i - 1][k - 1][1] + count_to_one;
			mem[i][k][0] = mem[i - 1][k - 1][0] + count_to_zero;
		}
	}

	long long mn = mem[m][x - 1][1];
	for (long long k = x - 1; k < y; ++k) {
		mn = min(mem[m][k][1], min(mem[m][k][0], mn));
	}

	cout << mn << endl;
	return 0;
}


#include <fstream>
#include <iostream>

using namespace std;

const long long N = 1003;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	for (long long i = 0; i < n; ++i) {
		mem[0][i] = INF;
	}
	mem[0][0] = 0;

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn = mem[i - 1][0];
		for (long long k = x; k <= y; ++k) {
			mn = min(mem[i - 1][k], mn);
		}
		mem[i][0] = mn + count_to_zero;

		for (long long k = 1; k <= y; ++k) {
			mem[i][k] = mem[i - 1][k - 1] + count_to_one;
		}
	}

	long long mn = mem[m][0];
	for (long long k = x; k <= y; ++k) {
		mn = min(mem[m][k], mn);
	}

	cout << mn << endl;
	return 0;
}


#include <fstream>
#include <iostream>

using namespace std;

const long long N = 1003;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N][2];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	for (long long i = 0; i < n; ++i) {
		mem[0][i][0] = INF;
		mem[0][i][1] = INF;
	}
	mem[0][x - 1][0] = 0;
	mem[0][x - 1][1] = 0;

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn_to_zero = mem[i - 1][x - 1][1];
		long long mn_to_one = mem[i - 1][x - 1][0];
		for (long long k = x - 1; k < y; ++k) {
			mn_to_zero = min(mem[i - 1][k][1], mn_to_zero);
			mn_to_one = min(mem[i - 1][k][0], mn_to_one);
		}
		mem[i][0][0] = mn_to_zero + count_to_zero;
		mem[i][0][1] = mn_to_one + count_to_one;

		for (long long k = 1; k < y; ++k) {
			mem[i][k][1] = mem[i - 1][k - 1][1] + count_to_one;
			mem[i][k][0] = mem[i - 1][k - 1][0] + count_to_zero;
		}
	}

	long long mn = mem[m][x - 1][1];
	for (long long k = x - 1; k < y; ++k) {
		mn = min(mem[m][k][1], min(mem[m][k][0], mn));
	}

	cout << mn << endl;
	return 0;
}


#include <fstream>
#include <iostream>

using namespace std;

const long long N = 1003;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N][2];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	for (long long i = 0; i < n; ++i) {
		mem[0][i][0] = INF;
		mem[0][i][1] = INF;
	}
	mem[0][0][0] = 0;
	mem[0][0][1] = 0;

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn_to_zero = mem[i - 1][x - 1][1];
		long long mn_to_one = mem[i - 1][x - 1][0];
		for (long long k = x - 1; k < y; ++k) {
			mn_to_zero = min(mem[i - 1][k][1], mn_to_zero);
			mn_to_one = min(mem[i - 1][k][0], mn_to_one);
		}
		mem[i][0][0] = mn_to_zero + count_to_zero;
		mem[i][0][1] = mn_to_one + count_to_one;

		for (long long k = 1; k < y; ++k) {
			mem[i][k][1] = mem[i - 1][k - 1][1] + count_to_one;
			mem[i][k][0] = mem[i - 1][k - 1][0] + count_to_zero;
		}
	}

	long long mn = min(mem[m][0][0], mem[m][0][1]);
	for (long long k = x - 1; k < y; ++k) {
		mn = min(mem[m][k][1], min(mem[m][k][0], mn));
	}

	cout << mn << endl;
	return 0;
}


#include <fstream>
#include <iostream>

using namespace std;

const long long N = 1003;

//ifstream cin ("input.txt"); ofstream cout ("output.txt");

const long long INF = 1000000000;

long long sm[N][N];
long long mem[N][N][2];

int main () {
	long long n, m, x, y;
	cin >> n >> m >> x >> y;
	char ch;
	for (long long i = 0; i < n; ++i) {
		for (long long j = 0; j < m; ++j) {
			cin >> ch;
			if (ch == '#') {
				sm[i][j] = 1;
			} else {
				sm[i][j] = 0;
			}
		}
	}

	for (long long i = 0; i < n; ++i) {
		mem[0][i][0] = INF;
		mem[0][i][1] = INF;
	}
	mem[0][0][0] = 0;
	mem[0][0][1] = 0;

	for (long long i = 1; i <= m; ++i) {
		long long count_to_zero = 0;
		for (long long j = 0; j < n; ++j) {
			count_to_zero += sm[j][i - 1];
		}
		long long count_to_one = n - count_to_zero;

		long long mn_to_zero = mem[i - 1][x][1];
		long long mn_to_one = mem[i - 1][x][0];
		for (long long k = x; k < y; ++k) {
			mn_to_zero = min(mem[i - 1][k][1], mn_to_zero);
			mn_to_one = min(mem[i - 1][k][0], mn_to_one);
		}
		mem[i][0][0] = mn_to_zero + count_to_zero;
		mem[i][0][1] = mn_to_one + count_to_one;

		for (long long k = 1; k < y; ++k) {
			mem[i][k][1] = mem[i - 1][k - 1][1] + count_to_one;
			mem[i][k][0] = mem[i - 1][k - 1][0] + count_to_zero;
		}
	}

	long long mn = min(mem[m][0][0], mem[m][0][1]);
	for (long long k = x; k < y; ++k) {
		mn = min(mem[m][k][1], min(mem[m][k][0], mn));
	}

	cout << mn << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a,long long b){   while(b)b^=a^=b^=a%=b;  return a;   }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = {-1, 0, 1, 0, -1, 1,  1, -1};
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1};

LL B[1005],W[1005];
LL dp[1005][2];
int main() {
	//freopen ("d:/Codejam/B-small-attempt0.in","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL  x, u ,v, y, z, sum, test_case = 0, length, ans, test = 0, l, w, num;
	//string str[10005], str1;
	char str[1005][1005];
	while(cin>> n >> m >> x >>y){
		memset(B,0,sizeof B);
		memset(W,0,sizeof W);
		for(i=1;i<=n;i++){
				scanf("%s",str[i]+1);
				for(j=1;j<=m;j++)
					if(str[i][j] == '#')
						B[j]++;
					else
						W[j]++;
		}

		for(i=0;i<=m;i++)
			for(j=0;j<2;j++)
				dp[i][j] = 1e9;
		dp[0][0] = dp[0][1] = 0;
		for(i=2;i<=m;i++)
			B[i]+=B[i-1];

		for(i=2;i<=m;i++)
			W[i]+=W[i-1];
		/*for(i=1;i<=m;i++)
			cout<<W[i]<<" ";

		cout<<endl;

		for(i=1;i<=m;i++)
			cout<<B[i]<<" ";
		cout<<endl;*/

		dp[x][0] = x*n - B[x];
		dp[x][1] = B[x];

		for(i= x+1; i<=m; i++){

			for(j=std::max(0LL,i-y); j<= i-x; j++){

			dp[i][0] = min ( dp[i][0],dp[j][1]+ (i-j)*n - (B[i] - B[j]));//'.'

			dp[i][1] = min ( dp[i][1],dp[j][0]+ (B[i] - B[j]));//'#'
			}

		}
		 cout<<std::min(dp[m][0],dp[m][1])<<"\n";
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a,long long b){   while(b)b^=a^=b^=a%=b;  return a;   }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = {-1, 0, 1, 0, -1, 1,  1, -1};
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1};

LL B[1005],W[1005];
LL dp[1005][2];
int main() {
	//freopen ("d:/Codejam/B-small-attempt0.in","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL  x, u ,v, y, z, sum, test_case = 0, length, ans, test = 0, l, w, num;
	//string str[10005], str1;
	char str[1005][1005];
	while(cin>> n >> m >> x >>y){
		memset(B,0,sizeof B);
		memset(W,0,sizeof W);
		for(i=1;i<=n;i++){
				scanf("%s",str[i]+1);
				for(j=1;j<=m;j++)
					if(str[i][j] == '#')
						B[j]++;
					else
						W[j]++;
		}
		memset(dp,0,sizeof dp);
		for(i=0;i<=m;i++)
			for(j=0;j<2;j++)
				dp[i][j] = 1e9;

		for(i=2;i<=m;i++)
			B[i]+=B[i-1];

		for(i=2;i<=m;i++)
			W[i]+=W[i-1];
		for(i=1;i<=m;i++)
			cout<<W[i]<<" ";

		cout<<endl;

		for(i=1;i<=m;i++)
			cout<<B[i]<<" ";
		cout<<endl;

		dp[x][0] = W[x];
		dp[x][1] = B[x];

		for(i= x+1; i<=m; i++){

			for(j=std::max(0LL,i-y); j<= i-x; j++){

			dp[i][0] = min ( dp[i][0],dp[j][1]+ (W[i] - W[j]));//'.'

			dp[i][1] = min ( dp[i][1],dp[j][0]+ (B[i] - B[j]));//'#'
			}

		}
		 cout<<std::min(dp[m][0],dp[m][1])<<"\n";
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a,long long b){   while(b)b^=a^=b^=a%=b;  return a;   }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = {-1, 0, 1, 0, -1, 1,  1, -1};
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1};

LL B[1005],W[1005];
LL dp[1005][2];
int main() {
	//freopen ("d:/Codejam/B-small-attempt0.in","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL  x, u ,v, y, z, sum, test_case = 0, length, ans, test = 0, l, w, num;
	//string str[10005], str1;
	char str[1005][1005];
	while(cin>> n >> m >> x >>y){
		memset(B,0,sizeof B);
		memset(W,0,sizeof W);
		for(i=1;i<=n;i++){
				scanf("%s",str[i]+1);
				for(j=1;j<=m;j++)
					if(str[i][j] == '#')
						B[j]++;
					else
						W[j]++;
		}
		memset(dp,0,sizeof dp);
		for(i=0;i<=m;i++)
			for(j=0;j<2;j++)
				dp[i][j] = 1e9;

		for(i=2;i<=m;i++)
			B[i]+=B[i-1];

		for(i=2;i<=m;i++)
			W[i]+=W[i-1];
		/*for(i=1;i<=m;i++)
			cout<<W[i]<<" ";

		cout<<endl;

		for(i=1;i<=m;i++)
			cout<<B[i]<<" ";
		cout<<endl;*/

		dp[x][0] = x*n - B[x];
		dp[x][1] = B[x];

		for(i= x+1; i<=m; i++){

			for(j=std::max(0LL,i-y); j<= i-x; j++){

			dp[i][0] = min ( dp[i][0],dp[j][1]+ (i-j)*n - (B[i] - B[j]));//'.'

			dp[i][1] = min ( dp[i][1],dp[j][0]+ (B[i] - B[j]));//'#'
			}

		}
		 cout<<std::min(dp[m][0],dp[m][1])<<"\n";
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a,long long b){   while(b)b^=a^=b^=a%=b;  return a;   }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = {-1, 0, 1, 0, -1, 1,  1, -1};
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1};

LL B[1005],W[1005];
LL dp[1005][2];
int main() {
	//freopen ("d:/Codejam/B-small-attempt0.in","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL  x, u ,v, y, z, sum, test_case = 0, length, ans, test = 0, l, w, num;
	//string str[10005], str1;
	char str[1005][1005];
	while(cin>> n >> m >> x >>y){
		memset(B,0,sizeof B);
		memset(W,0,sizeof W);
		for(i=1;i<=n;i++){
				scanf("%s",str[i]+1);
				for(j=1;j<=m;j++)
					if(str[i][j] == '#')
						B[j]++;
					else
						W[j]++;
		}
		memset(dp,0,sizeof dp);
		for(i=0;i<=m;i++)
			for(j=0;j<2;j++)
				dp[i][j] = 1e9;

		for(i=2;i<=m;i++)
			B[i]+=B[i-1];

		for(i=2;i<=m;i++)
			W[i]+=W[i-1];
		/*for(i=1;i<=m;i++)
			cout<<W[i]<<" ";

		cout<<endl;

		for(i=1;i<=m;i++)
			cout<<B[i]<<" ";
		cout<<endl;*/

		dp[x][0] = W[x];
		dp[x][1] = B[x];

		for(i= x+1; i<=m; i++){

			for(j=std::max(0LL,i-y); j<= i-x; j++){

			dp[i][0] = min ( dp[i][0],dp[j][1]+ (W[i] - W[j]));//'.'

			dp[i][1] = min ( dp[i][1],dp[j][0]+ (B[i] - B[j]));//'#'
			}

		}
		 cout<<std::min(dp[m][0],dp[m][1])<<"\n";
	}

	return 0;
}


//#pragma comment(linker,"/STACK:256000000")

#include <cstdio>
#include <memory>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <fstream>
#include <functional>
#include <list>
#include <string>
#include <cstring>
#include <stack>
#include <complex>
#include <cmath>
#include <queue>
#include <ctime>
#include <iostream>

using namespace std;

#define rep(x,y,z) for(int x=(y),e##x=(z);x<e##x;x++)
#define all(c) (c).begin(), (c).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INF=1e9;
int B[1003][1003];
int W[1003][1003];
char A[1003][1003];
int bcnt[1003]={0};
int wcnt[1003]={0};

void mainProc()
{
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	y=min(y,m);
	rep(i,0,n)
		scanf(" %s",A[i]);
	rep(i,0,n)
		rep(j,0,m)
			if (A[i][j]=='#')
				bcnt[j]++;
			else
				wcnt[j]++;
	rep(i,0,m+1)
		rep(j,0,m+1)
			B[i][j]=W[i][j]=INF;
	B[0][1]=wcnt[0];
	W[0][1]=bcnt[0];
	rep(i,1,m)
	{
		int val=INF;
		rep(j,x,y+1)
			val=min(val,W[i-1][j]);
		if (val==INF)
			B[i][1]==INF;
		else
			B[i][1]=val+wcnt[i];
		rep(j,2,m+1)
			if (B[i-1][j-1]!=INF)
				B[i][j]=B[i-1][j-1] + wcnt[i];
			else
				B[i][j]=INF;
		//make white
		val=INF;
		rep(j,x,y+1)
			val=min(val,B[i-1][j]);
		if (val==INF)
			W[i][1]=INF;
		else
			W[i][1]=val+bcnt[i];
		rep(j,2,m+1)
			if (W[i-1][j-1]!=INF)
				W[i][j]=W[i-1][j-1] + bcnt[i];
			else
				W[i][j]=INF;
	}
	int res=INF;
	rep(i,x,y+1)
		res=min(res,min(B[m-1][i],W[m-1][i]));
	printf("%d\n",res);
}

int main()
{
#ifdef _ANNA_
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    time_t cl_begin=clock();
#endif
    mainProc();
#ifdef _ANNA_
    printf("--------------------\n");
    printf("Time %.2lf sec\n",(clock()-cl_begin)/double(CLOCKS_PER_SEC));
#endif
    return 0;
}

/*

*/


//#pragma comment(linker,"/STACK:256000000")

#include <cstdio>
#include <memory>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <fstream>
#include <functional>
#include <list>
#include <string>
#include <cstring>
#include <stack>
#include <complex>
#include <cmath>
#include <queue>
#include <ctime>
#include <iostream>

using namespace std;

#define rep(x,y,z) for(int x=(y),e##x=(z);x<e##x;x++)
#define all(c) (c).begin(), (c).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INF=1e9;
int B[1003][1003];
int W[1003][1003];
char A[1003][1003];
int bcnt[1003]={0};
int wcnt[1003]={0};

void mainProc()
{
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	rep(i,0,n)
		scanf(" %s",A[i]);
	rep(i,0,n)
		rep(j,0,m)
			if (A[i][j]=='#')
				bcnt[j]++;
			else
				wcnt[j]++;
	rep(i,0,m+1)
		rep(j,0,m+1)
			B[i][j]=W[i][j]=INF;
	B[0][1]=wcnt[0];
	W[0][1]=bcnt[0];
	rep(i,1,m)
	{
		int val=INF;
		rep(j,x,y+1)
			val=min(val,W[i-1][j]);
		B[i][1]=val+wcnt[i];
		rep(j,2,m+1)
			if (B[i-1][j-1]!=INF)
				B[i][j]=B[i-1][j-1] + wcnt[i];
		//make white
		val=INF;
		rep(j,x,y+1)
			val=min(val,B[i-1][j]);
		W[i][1]=val+bcnt[i];
		rep(j,2,m+1)
			if (W[i-1][j-1]!=INF)
				W[i][j]=W[i-1][j-1] + bcnt[i];
	}
	int res=INF;
	rep(i,x,y+1)
		res=min(res,min(B[m-1][i],W[m-1][i]));
	printf("%d\n",res);
}

int main()
{
#ifdef _ANNA_
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    time_t cl_begin=clock();
#endif
    mainProc();
#ifdef _ANNA_
    printf("--------------------\n");
    printf("Time %.2lf sec\n",(clock()-cl_begin)/double(CLOCKS_PER_SEC));
#endif
    return 0;
}

/*

*/


//#pragma comment(linker,"/STACK:256000000")

#include <cstdio>
#include <memory>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <fstream>
#include <functional>
#include <list>
#include <string>
#include <cstring>
#include <stack>
#include <complex>
#include <cmath>
#include <queue>
#include <ctime>
#include <iostream>

using namespace std;

#define rep(x,y,z) for(int x=(y),e##x=(z);x<e##x;x++)
#define all(c) (c).begin(), (c).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INF=1e9;
int B[1003][1003];
int W[1003][1003];
char A[1003][1003];
int bcnt[1003]={0};
int wcnt[1003]={0};

void mainProc()
{
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	rep(i,0,n)
		scanf(" %s",A[i]);
	rep(i,0,n)
		rep(j,0,m)
			if (A[i][j]=='#')
				bcnt[j]++;
			else
				wcnt[j]++;
	rep(i,0,m+1)
		rep(j,0,m+1)
			B[i][j]=W[i][j]=INF;
	B[0][1]=wcnt[0];
	W[0][1]=bcnt[0];
	rep(i,1,m)
	{
		int val=INF;
		rep(j,x,y+1)
			val=min(val,W[i-1][j]);
		if (val==INF)
			B[i][1]==INF;
		else
			B[i][1]=val+wcnt[i];
		rep(j,2,m+1)
			if (B[i-1][j-1]!=INF)
				B[i][j]=B[i-1][j-1] + wcnt[i];
			else
				B[i][j]=INF;
		//make white
		val=INF;
		rep(j,x,y+1)
			val=min(val,B[i-1][j]);
		if (val==INF)
			W[i][1]=INF;
		else
			W[i][1]=val+bcnt[i];
		rep(j,2,m+1)
			if (W[i-1][j-1]!=INF)
				W[i][j]=W[i-1][j-1] + bcnt[i];
			else
				W[i][j]=INF;
	}
	int res=INF;
	rep(i,x,y+1)
		res=min(res,min(B[m-1][i],W[m-1][i]));
	printf("%d\n",res);
}

int main()
{
#ifdef _ANNA_
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    time_t cl_begin=clock();
#endif
    mainProc();
#ifdef _ANNA_
    printf("--------------------\n");
    printf("Time %.2lf sec\n",(clock()-cl_begin)/double(CLOCKS_PER_SEC));
#endif
    return 0;
}

/*

*/


//#pragma comment(linker,"/STACK:256000000")

#include <cstdio>
#include <memory>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <fstream>
#include <functional>
#include <list>
#include <string>
#include <cstring>
#include <stack>
#include <complex>
#include <cmath>
#include <queue>
#include <ctime>
#include <iostream>

using namespace std;

#define rep(x,y,z) for(int x=(y),e##x=(z);x<e##x;x++)
#define all(c) (c).begin(), (c).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INF=1e9;
int B[1003][1003];
int W[1003][1003];
char A[1003][1003];
int bcnt[1003]={0};
int wcnt[1003]={0};

void mainProc()
{
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	rep(i,0,n)
		scanf(" %s",A[i]);
	rep(i,0,n)
		rep(j,0,m)
			if (A[i][j]=='#')
				bcnt[j]++;
			else
				wcnt[j]++;
	rep(i,0,m+1)
		rep(j,0,m+1)
			B[i][j]=W[i][j]=INF;
	B[0][1]=wcnt[0];
	W[0][1]=bcnt[0];
	rep(i,1,m)
	{
		int val=INF;
		rep(j,x,y+1)
			val=min(val,W[i-1][j]);
		B[i][1]=val+wcnt[i];
		rep(j,2,i+2)
			B[i][j]=B[i-1][j-1] + wcnt[i];
		//make white
		val=INF;
		rep(j,x,y+1)
			val=min(val,B[i-1][j]);
		W[i][1]=val+bcnt[i];
		rep(j,2,i+2)
			W[i][j]=W[i-1][j-1] + bcnt[i];
	}
	int res=INF;
	rep(i,x,y+1)
		res=min(res,min(B[m-1][i],W[m-1][i]));
	printf("%d\n",res);
}

int main()
{
#ifdef _ANNA_
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    time_t cl_begin=clock();
#endif
    mainProc();
#ifdef _ANNA_
    printf("--------------------\n");
    printf("Time %.2lf sec\n",(clock()-cl_begin)/double(CLOCKS_PER_SEC));
#endif
    return 0;
}

/*

*/


//#pragma comment(linker,"/STACK:256000000")

#include <cstdio>
#include <memory>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <fstream>
#include <functional>
#include <list>
#include <string>
#include <cstring>
#include <stack>
#include <complex>
#include <cmath>
#include <queue>
#include <ctime>
#include <iostream>

using namespace std;

#define rep(x,y,z) for(int x=(y),e##x=(z);x<e##x;x++)
#define all(c) (c).begin(), (c).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INF=1e9;
int B[1003][1003];
int W[1003][1003];
char A[1003][1003];
int bcnt[1003]={0};
int wcnt[1003]={0};

void mainProc()
{
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	rep(i,0,n)
		scanf(" %s",A[i]);
	rep(i,0,n)
		rep(j,0,m)
			if (A[i][j]=='#')
				bcnt[j]++;
			else
				wcnt[j]++;
	rep(i,0,m+1)
		rep(j,0,m+1)
			B[i][j]=W[i][j]=INF;
	B[0][1]=wcnt[0];
	W[0][1]=bcnt[0];
	rep(i,1,m)
	{
		int val=INF;
		rep(j,x,y+1)
			val=min(val,W[i-1][j]);
		if (val==INF)
			B[i][1]==INF
		else
			B[i][1]=val+wcnt[i];
		rep(j,2,m+1)
			if (B[i-1][j-1]!=INF)
				B[i][j]=B[i-1][j-1] + wcnt[i];
			else
				B[i][j]=INF;
		//make white
		val=INF;
		rep(j,x,y+1)
			val=min(val,B[i-1][j]);
		if (val==INF)
			W[i][1]=INF;
		else
			W[i][1]=val+bcnt[i];
		rep(j,2,m+1)
			if (W[i-1][j-1]!=INF)
				W[i][j]=W[i-1][j-1] + bcnt[i];
			else
				W[i][j]=INF;
	}
	int res=INF;
	rep(i,x,y+1)
		res=min(res,min(B[m-1][i],W[m-1][i]));
	printf("%d\n",res);
}

int main()
{
#ifdef _ANNA_
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    time_t cl_begin=clock();
#endif
    mainProc();
#ifdef _ANNA_
    printf("--------------------\n");
    printf("Time %.2lf sec\n",(clock()-cl_begin)/double(CLOCKS_PER_SEC));
#endif
    return 0;
}

/*

*/


#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>
#include<stdio.h>
#include <math.h>
using namespace std;
/*struct MyStruct
{
	long long m;
	long long s;
};

struct my_comparer {
	bool operator()(const MyStruct & one, const MyStruct & two) const {
		return one.m < two.m;
	}
};*/

long long dp[2][1009];
int a[1007];
long long summ[1005];
void main() {
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	int n,m, x,y;
	char ch;
	cin >> n >> m >> x >> y;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> ch;
			if (ch == '#')
			{
				a[j]++;
			}
		}
	}
	summ[0] = 0;
	for (int i = 1; i <= m; i++)
	{
		summ[i] = summ[i - 1] + a[i-1];

	}
	for (int i = 1; i <= 1000; i++)
	{
		dp[0][i] = 100000000;
		dp[1][i] = 100000000;
	}
	for (int i = x; i <= m; i++)
	{
		for (int j = x; j <= y; j++)
		{
			if (i - j >=0)
			{
				int g = summ[i] - summ[i - j];
				if (dp[0][i] > dp[1][i - j]+g)
				{
					dp[0][i] = dp[1][i - j] + g;
				}
				if (dp[1][i] > dp[0][i - j] + j*n-g)
				{
					dp[1][i] = dp[0][i - j] +j * n -g;
				}
			}
		}
	}
	cout << min(dp[1][m ], dp[0][m]);
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<stack>
#include<vector>
#include<set>
#include<iomanip>
#include<stdio.h>
#include <math.h>
using namespace std;
/*struct MyStruct
{
	long long m;
	long long s;
};

struct my_comparer {
	bool operator()(const MyStruct & one, const MyStruct & two) const {
		return one.m < two.m;
	}
};*/

long long dp[2][1009];
int a[1007];
long long summ[1005];
void main() {
#if defined(_DEBUG)
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif
	int n,m, x,y;
	char ch;
	cin >> n >> m >> x >> y;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> ch;
			if (ch == '#')
			{
				a[j]++;
			}
		}
	}
	summ[0] = 0;
	for (int i = 1; i <= m; i++)
	{
		summ[i] = summ[i - 1] + a[i-1];

	}
	for (int i = x; i <= 1000; i++)
	{
		dp[0][i] = 100000000;
		dp[1][i] = 100000000;
	}
	for (int i = x; i <= m; i++)
	{
		for (int j = x; j <= y; j++)
		{
			if (i - j >=0)
			{
				int g = summ[i] - summ[i - j];
				if (dp[0][i] > dp[1][i - j]+g)
				{
					dp[0][i] = dp[1][i - j] + g;
				}
				if (dp[1][i] > dp[0][i - j] + j*n-g)
				{
					dp[1][i] = dp[0][i - j] +j * n -g;
				}
			}
		}
	}
	cout << min(dp[1][m ], dp[0][m]);
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
long long capacity[100];
long long cost[100];
int counting[1001];
long long n, m, x, y;

int Memo[1002][1002][3];
int dpstyle(int index, int numberofwidth, int laststatus)
{
	if (index == m)
	{
		if (numberofwidth < x || numberofwidth > y)
			return 100000000;
		return 0;
	}
	int &answer = Memo[index][numberofwidth][laststatus];

	if (answer != -1)
		return answer;

	int choice1 = 1e9;

	if (index == 0 || (laststatus == 0 && numberofwidth + 1 <= y) || (laststatus == 1 && numberofwidth >= x))
	{
		if (laststatus == 0)
		{
			choice1 = n - counting[index] + dpstyle(index + 1, numberofwidth + 1, 0);
		}
		else
			choice1 = n - counting[index] + dpstyle(index + 1, 1, 0);
	}

	int choice2 = 1e9;

	if (index == 0 || (laststatus == 1 && numberofwidth + 1 <= y) || (laststatus == 0 && numberofwidth >= x))
	{
		if (laststatus == 1)
		{
			choice2 = counting[index] + dpstyle(index + 1, numberofwidth + 1, 1);
		}
		else
		{
			choice2 = counting[index] + dpstyle(index + 1, 1, 1);
		}
	}

	answer = min(choice1, choice2);
	return answer;

}
int main()
{
	cin >> n >> m >> x >> y;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char ch;
			cin >> ch;
			if (ch == '.')
			{
				counting[j]++;
			}
		}
	}
	memset(Memo, -1, sizeof(Memo));
	cout << dpstyle(0, 0, 2);
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
long long capacity[100];
long long cost[100];
int counting[1001];
long long n, m, x, y;
int Memo[1002][1002][3];
int dpstyle(int index, int numberofwidth, int laststatus)
{
	if (index == m)
	{
		if (numberofwidth < x || numberofwidth > y)
			return 100000000;
		return 0;
	}
	int &answer = Memo[index][numberofwidth][laststatus];
	if (answer != -1)
		return answer;

	int choice1 = 1e9;

	if (index == 0 || (laststatus == 0 && numberofwidth + 1 <= y) || (laststatus == 1 && numberofwidth >= x))
			choice1 = n - counting[index] + dpstyle(index + 1, laststatus ==0 ? numberofwidth + 1 :1, 0);

	int choice2 = 1e9;

	if (index == 0 || (laststatus == 1 && numberofwidth + 1 <= y) || (laststatus == 0 && numberofwidth >= x))
		choice2 = counting[index] + dpstyle(index + 1,laststatus ==1 ? numberofwidth+1:1, 1);

	answer = min(choice1, choice2);
	return answer;

}
int main()
{
	cin >> n >> m >> x >> y;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char ch;
			cin >> ch;
			if (ch == '.')
				counting[j]++;
		}
	}
	memset(Memo, -1, sizeof(Memo));
	cout << dpstyle(0, 0, 2);
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <string>
#include <set>
#include <stack>
#include <algorithm>

using namespace std;

typedef vector<int> vint;
typedef vector<vint> vvint;

int mas[1005];
int ms[1005];
int D[1001][2];
int N,m,x,y;

int f(int i, int c)
{
	if (i == m)
		return 0;
	if (i > m)
		return 1000*1000*1000+9;
	if (D[i][c] != -1)
		return D[i][c];
	int res = 1000*1000*1000 + 9;
	for (int j = x; j<=y; j++)
		res = min(res,f(i+j,!c) + (c ? ms[i+j] - ms[i] : N * j - (ms[i+j] - ms[i]) ));
	D[i][c] = res;
	return res;
}

void reset()
{
		for (int j = 0; j < 1001; j++)
		{
			D[j][0] = -1;
			D[j][1] = -1;
		}
}

int main()
{
	reset();
	cin >> N >> m >> x >> y;
	char ch;
	for (int i=0; i<N; i++)
	{
		ch = getchar();
		for (int j=0; j<m; j++)
		{
			ch = getchar();
			mas[j] += ch == '#';
		}
	}
	ms[0] = 0;
	for (int i=1; i<=m; i++)
		ms[i] = ms[i-1] + mas[i-1];
	cout << min(f(0,0), f(0,1));
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int mas[1001];

int  D[1001][1001][2];
int N,m,x,y;

int f(int i, int n, int c)
{
    if (i == m)
        return 0;
    if (D[i][n][c] != -1)
        return D[i][n][c];
    int res = 1000*1000*1000+9;
    if (n < y)
        res = min(res,f(i+1, n+1, c) + (c ? N - mas[i] : mas[i]));
    if (n >= x)
        res = min(res, f(i+1, 1, (c+1) % 2) + (!c ? N - mas[i] : mas[i]));
    D[i][n][c] = res;
    return res;
}

void reset()
{
    for (int i=0; i<1001; i++)
        for (int j=0; j<1001; j++)
        {
            D[i][j][0] = -1;
            D[i][j][1] = -1;
        }
}

int main()
{
    reset();
    cin >> N >> m >> x >>y;
    char ch;
    for (int i=0; i<N; i++)
    {
        ch = getchar();
        for (int j=0;j<m; j++)
        {
            ch = getchar();
            mas[j] += ch == '#';
        }
    }
    cout << min(f(0,0,0), f(0,0,1));
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int mas[1001];

int D[1001][1001][2];
int N,m,x,y;

int f(int i, int n, int c)
{
    if (i == m)
        return 0;
    if (D[i][n][c] != -1)
        return D[i][n][c];
    int res = 1000*1000*1000+9;
    if (n < y)
        res = min(res,f(i+1, n+1, c) + (c ? N - mas[i] : mas[i]));
    if (n >= x)
        res = min(res, f(i+1, 1, !c) + (!c ? N - mas[i] : mas[i]));
    D[i][n][c] = res;
    return res;
}

void reset()
{
    for (int i=0; i<1001; i++)
        for (int j=0; j<1001; j++)
        {
            D[i][j][0] = -1;
            D[i][j][1] = -1;
        }
}

int main()
{
    reset();
    cin >> N >> m >> x >>y;
    char ch;
    for (int i=0; i<N; i++)
    {
        ch = getchar();
        for (int j=0;j<m; j++)
        {
            ch = getchar();
            mas[j] += ch == '#';
        }
    }
    int res = f(0,0,0);
    reset();
    cout << min(res, f(0,0,1)) << endl;
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int mas[1001];

int  D[1001][1001][2];
int N,m,x,y;

int f(int i, int n, int c)
{
    if (i == m)
        return 0;
    if (D[i][n][c] != -1)
        return D[i][n][c];
    int res = 100000000;
    if (n < y)
        res = min(res,f(i+1, n+1, c) + (c ? N - mas[i] : mas[i]));
    if (n >= x)
        res = min(res, f(i+1, 1, (c+1) % 2) + (!c ? N - mas[i] : mas[i]));
    D[i][n][c] = res;
    return res;
}

void reset()
{
    for (int i=0; i<1001; i++)
        for (int j=0; j<1001; j++)
        {
            D[i][j][0] = -1;
            D[i][j][1] = -1;
        }
}

int main()
{
    reset();
    cin >> N >> m >> x >>y;
    char ch;
    for (int i=0; i<N; i++)
    {
        ch = getchar();
        for (int j=0;j<m; j++)
        {
            ch = getchar();
            mas[j] += ch == '#';
        }
    }
    cout << min(f(0,0,0), f(0,0,1));
    return 0;
}