#include <cstdio>
#include <cmath>
#include <cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>

#define EPS 1e-8
#define MAX(a,b) ((a)>(b)?(a):(b))
#define sqr(x) ((x)*(x))
using namespace std;
int cost[1005][2],dp[1005][1005],sum[1005];
char mp[1005][1005];
int n,m,x,y;
void solve()
{
	int i,j,k,ans,pre;
	for(i=1;i<=m;i++)
	{
		for(j=k=0;j<n;j++)
			if(mp[j][i]=='#')
				k++;
		cost[i][0]=k;
		cost[i][1]=n-k;
	}
	for(i=1;i<=m;i++)
		sum[i]=sum[i-1]+cost[i][1];
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	for(i=1;i<=m;i++)
	{
		pre=dp[i-1][0];
		for(j=x;j<=y;j++)
		{
			pre=min(pre,dp[i-1][j]);
			if(i+j-1<=m)
				dp[i+j-1][j]=min(dp[i-1][0]+sum[i+j-1]-sum[i-1],dp[i+j-1][j]);
		}
		dp[i][0]=pre+cost[i][0];
	}
	ans=dp[m][0];
	for(i=x;i<=y;i++)
		ans=min(ans,dp[m][i]);
	printf("%d\n",ans);
}
int main()
{
	scanf("%d%d%d%d",&n,&m,&x,&y);
	for(int i=0;i<n;i++)
		scanf("%s",mp[i]+1);
	solve();
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>

#define EPS 1e-8
#define MAX(a,b) ((a)>(b)?(a):(b))
#define sqr(x) ((x)*(x))
#define INF (1<<28)
using namespace std;
int cost[1005][2],dp[1005][2005],sum1[1005],sum2[1005];
char mp[1005][1005];
int n,m,x,y;
void solve()
{
	int i,j,k,ans,pre1,pre2;
	for(i=1;i<=m;i++)
	{
		for(j=k=0;j<n;j++)
			if(mp[j][i]=='#')
				k++;
		cost[i][0]=k;
		cost[i][1]=n-k;
	}
	for(i=1;i<=m;i++)
	{
		sum2[i]=sum2[i-1]+cost[i][1];
		sum1[i]=sum1[i-1]+cost[i][0];
	}
	memset(dp,0x3f,sizeof(dp));
	dp[0][x]=0;
	dp[0][m+x]=0;
	for(i=1;i<=m;i++)
	{
		pre1=INF;
		pre2=INF;
		for(j=x;j<=y;j++)
		{
			pre1=min(pre1,dp[i-1][j]);
			pre2=min(pre2,dp[i-1][m+j]);
		}
		for(j=x;j<=y;j++)
			if(i+j-1<=m)
			{
				dp[i+j-1][j]=min(dp[i+j-1][j],pre2+sum1[i+j-1]-sum1[i-1]);
				dp[i+j-1][j+m]=min(dp[i+j-1][j+m],pre1+sum2[i+j-1]-sum2[i-1]);
			}
	}
	ans=INF;
	for(i=x;i<=y;i++)
		ans=min(ans,min(dp[m][i],dp[m][i+m]));
	printf("%d\n",ans);
}
int main()
{
	scanf("%d%d%d%d",&n,&m,&x,&y);
	for(int i=0;i<n;i++)
		scanf("%s",mp[i]+1);
	solve();
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

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

#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <set>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <complex>
#include <hash_map>
#include <hash_set>

using namespace std;

#define pb push_back
#define pob pop_back
#define rs resize
#define as assign
#define fs first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define mp make_pair
#define sz(a) (int)a.size()
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FOD(i, n) for (int i = n - 1; i >= 0; --i)

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ll> vl;
typedef vector <vl> vvl;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <char> vc;
typedef vector <vc> vvc;
typedef vector <vvc> vvvc;
typedef vector <vvi> vvvi;
typedef vector <vvvi> vvvvi;
typedef vector <vvl> vvvl;
typedef vector <vvvl> vvvvl;
typedef vector <vvb> vvvb;
typedef double db;
typedef long double ldb;
typedef vector <db> vdb;
typedef vector <vdb> vvdb;
typedef vector <vvdb> vvvdb;
typedef vector <ldb> vldb;
typedef pair <int, int> ii;
typedef pair <int, char> ic;
typedef pair <ll, ll> lll;
typedef pair <int, ll> il;
typedef pair <ll, int> li;
typedef vector <ii> vii;
typedef vector <ic> vic;
typedef vector <vic> vvic;
typedef vector <vii> vvii;
typedef vector <lll> vll;
typedef vector <vll> vvll;
typedef set <int> si;
typedef set <ii> sii;
typedef set <pair <int, bool> > sib;
typedef vector <si> vsi;
typedef vector <sii> vsii;
typedef map <int, int> mii;
typedef map <string, char> msc;
typedef map <char, int> mci;
typedef queue <int> qi;
typedef deque <int> di;
typedef stack <int> sti;

const ll inf = (ll)1e9 + 7;
const ldb eps = 1e-18;
const ll pr = 31;
const int sf = 450000;

int n, a[3];

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vs a(n + 1);
    vvi dp(m + 1, vi(2, (int)1e9));
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    vi p(m + 1, 0);
    p[0] = 0;
    for (int i = 1; i <= m; ++i)
    {
        p[i] = p[i - 1];
        for (int j = 1; j <= n; ++j)
            p[i] += (a[j][i] == '#');
    }
    dp[0][0] = 0;
    dp[0][1] = 0;
    for (int i = 1; i <= m; ++i)
        for (int t = 0; t < 2; ++t)
            for (int j = x; j <= min(i, y); ++j)
                dp[i][t] = min(dp[i][t], dp[i - j][1 - t] + (t == 1 ? p[i] - p[i - j] : n * j - p[i] + p[i - j]));
    cout << min(dp[m][0], dp[m][1]);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

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

#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <set>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <complex>
#include <hash_map>
#include <hash_set>

using namespace std;

#define pb push_back
#define pob pop_back
#define rs resize
#define as assign
#define fs first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define mp make_pair
#define sz(a) (int)a.size()
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FOD(i, n) for (int i = n - 1; i >= 0; --i)

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ll> vl;
typedef vector <vl> vvl;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <char> vc;
typedef vector <vc> vvc;
typedef vector <vvc> vvvc;
typedef vector <vvi> vvvi;
typedef vector <vvvi> vvvvi;
typedef vector <vvl> vvvl;
typedef vector <vvvl> vvvvl;
typedef vector <vvb> vvvb;
typedef double db;
typedef long double ldb;
typedef vector <db> vdb;
typedef vector <vdb> vvdb;
typedef vector <vvdb> vvvdb;
typedef vector <ldb> vldb;
typedef pair <int, int> ii;
typedef pair <int, char> ic;
typedef pair <ll, ll> lll;
typedef pair <int, ll> il;
typedef pair <ll, int> li;
typedef vector <ii> vii;
typedef vector <ic> vic;
typedef vector <vic> vvic;
typedef vector <vii> vvii;
typedef vector <lll> vll;
typedef vector <vll> vvll;
typedef set <int> si;
typedef set <ii> sii;
typedef set <pair <int, bool> > sib;
typedef vector <si> vsi;
typedef vector <sii> vsii;
typedef map <int, int> mii;
typedef map <string, char> msc;
typedef map <char, int> mci;
typedef queue <int> qi;
typedef deque <int> di;
typedef stack <int> sti;

const ll inf = (ll)1e9 + 7;
const ldb eps = 1e-18;
const ll pr = 31;
const int sf = 450000;

int n, a[3];

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vs a(n);
    vvi dp(m, vi(2, (int)1e9));
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vi p(m, 0);
    for (int i = 0; i < m; ++i)
    {
        p[i] = (i > 0 ? p[i - 1] : 0);
        for (int j = 0; j < n; ++j)
            p[i] += (a[j][i] == '#');
    }
    dp[0][1] = p[0];
    dp[0][0] = n - p[0];
    for (int i = 0; i < m; ++i)
        for (int t = 0; t < 2; ++t)
            for (int j = x; j <= min(i + 1, y); ++j)
                if (i >= j && dp[i - j][1 - t] == (int)1e9)
                    continue;
                else
                    dp[i][t] = min(dp[i][t], (i == j - 1 ? 0 : dp[i - j][1 - t]) + (t == 1 ? p[i] - (i == j - 1 ? 0 : p[i - j]) : n * j - p[i] + (i == j - 1 ? 0 : p[i - j])));
    cout << min(dp[m - 1][0], dp[m - 1][1]);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

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

#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <set>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <complex>
#include <hash_map>
#include <hash_set>

using namespace std;

#define pb push_back
#define pob pop_back
#define rs resize
#define as assign
#define fs first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define mp make_pair
#define sz(a) (int)a.size()
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FOD(i, n) for (int i = n - 1; i >= 0; --i)

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ll> vl;
typedef vector <vl> vvl;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <char> vc;
typedef vector <vc> vvc;
typedef vector <vvc> vvvc;
typedef vector <vvi> vvvi;
typedef vector <vvvi> vvvvi;
typedef vector <vvl> vvvl;
typedef vector <vvvl> vvvvl;
typedef vector <vvb> vvvb;
typedef double db;
typedef long double ldb;
typedef vector <db> vdb;
typedef vector <vdb> vvdb;
typedef vector <vvdb> vvvdb;
typedef vector <ldb> vldb;
typedef pair <int, int> ii;
typedef pair <int, char> ic;
typedef pair <ll, ll> lll;
typedef pair <int, ll> il;
typedef pair <ll, int> li;
typedef vector <ii> vii;
typedef vector <ic> vic;
typedef vector <vic> vvic;
typedef vector <vii> vvii;
typedef vector <lll> vll;
typedef vector <vll> vvll;
typedef set <int> si;
typedef set <ii> sii;
typedef set <pair <int, bool> > sib;
typedef vector <si> vsi;
typedef vector <sii> vsii;
typedef map <int, int> mii;
typedef map <string, char> msc;
typedef map <char, int> mci;
typedef queue <int> qi;
typedef deque <int> di;
typedef stack <int> sti;

const ll inf = (ll)1e9 + 7;
const ldb eps = 1e-18;
const ll pr = 31;
const int sf = 450000;

int n, a[3];

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vs a(n + 1);
    vvi dp(m, vi(2, (int)1e9));
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vi p(n, 0);
    for (int i = 0; i < m; ++i)
    {
        p[i] = (i > 0 ? p[i - 1] : 0);
        for (int j = 0; j < n; ++j)
            p[i] += (a[j][i] == '#');
    }
    dp[0][1] = p[0];
    dp[0][0] = n - p[0];
    for (int i = 0; i < m; ++i)
        for (int t = 0; t < 2; ++t)
            for (int j = x; j <= min(i + 1, y); ++j)
                dp[i][t] = min(dp[i][t], (i == j - 1 ? 0 : dp[i - j][1 - t]) + (t == 1 ? p[i] - (i == j - 1 ? 0 : p[i - j]) : n * j - p[i] + (i == j - 1 ? 0 : p[i - j])));
    cout << min(dp[m - 1][0], dp[m - 1][1]);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

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

#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <set>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <complex>
#include <hash_map>
#include <hash_set>

using namespace std;

#define pb push_back
#define pob pop_back
#define rs resize
#define as assign
#define fs first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define mp make_pair
#define sz(a) (int)a.size()
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FOD(i, n) for (int i = n - 1; i >= 0; --i)

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ll> vl;
typedef vector <vl> vvl;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <char> vc;
typedef vector <vc> vvc;
typedef vector <vvc> vvvc;
typedef vector <vvi> vvvi;
typedef vector <vvvi> vvvvi;
typedef vector <vvl> vvvl;
typedef vector <vvvl> vvvvl;
typedef vector <vvb> vvvb;
typedef double db;
typedef long double ldb;
typedef vector <db> vdb;
typedef vector <vdb> vvdb;
typedef vector <vvdb> vvvdb;
typedef vector <ldb> vldb;
typedef pair <int, int> ii;
typedef pair <int, char> ic;
typedef pair <ll, ll> lll;
typedef pair <int, ll> il;
typedef pair <ll, int> li;
typedef vector <ii> vii;
typedef vector <ic> vic;
typedef vector <vic> vvic;
typedef vector <vii> vvii;
typedef vector <lll> vll;
typedef vector <vll> vvll;
typedef set <int> si;
typedef set <ii> sii;
typedef set <pair <int, bool> > sib;
typedef vector <si> vsi;
typedef vector <sii> vsii;
typedef map <int, int> mii;
typedef map <string, char> msc;
typedef map <char, int> mci;
typedef queue <int> qi;
typedef deque <int> di;
typedef stack <int> sti;

const ll inf = (ll)1e9 + 7;
const ldb eps = 1e-18;
const ll pr = 31;
const int sf = 450000;

int n, a[3];

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vs a(n);
    vvi dp(m + 1, vi(2, (int)1e9));
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vi p(m + 1, 0);
    for (int i = 0; i < m; ++i)
    {
        p[i + 1] = p[i];
        for (int j = 0; j < n; ++j)
            p[i + 1] += (a[j][i] == '#');
    }
    dp[0][0] = 0;
    dp[0][1] = 0;
    for (int i = 1; i <= m; ++i)
        for (int t = 0; t < 2; ++t)
            for (int j = x; j <= min(i, y); ++j)
                dp[i][t] = min(dp[i][t], dp[i - j][1 - t] + (t == 1 ? p[i] - p[i - j] : n * j - p[i] + p[i - j]));
    cout << min(dp[m][0], dp[m][1]);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

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

#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <set>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <complex>
#include <hash_map>
#include <hash_set>

using namespace std;

#define pb push_back
#define pob pop_back
#define rs resize
#define as assign
#define fs first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define mp make_pair
#define sz(a) (int)a.size()
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FOD(i, n) for (int i = n - 1; i >= 0; --i)

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ll> vl;
typedef vector <vl> vvl;
typedef vector <bool> vb;
typedef vector <vb> vvb;
typedef vector <string> vs;
typedef vector <vs> vvs;
typedef vector <char> vc;
typedef vector <vc> vvc;
typedef vector <vvc> vvvc;
typedef vector <vvi> vvvi;
typedef vector <vvvi> vvvvi;
typedef vector <vvl> vvvl;
typedef vector <vvvl> vvvvl;
typedef vector <vvb> vvvb;
typedef double db;
typedef long double ldb;
typedef vector <db> vdb;
typedef vector <vdb> vvdb;
typedef vector <vvdb> vvvdb;
typedef vector <ldb> vldb;
typedef pair <int, int> ii;
typedef pair <int, char> ic;
typedef pair <ll, ll> lll;
typedef pair <int, ll> il;
typedef pair <ll, int> li;
typedef vector <ii> vii;
typedef vector <ic> vic;
typedef vector <vic> vvic;
typedef vector <vii> vvii;
typedef vector <lll> vll;
typedef vector <vll> vvll;
typedef set <int> si;
typedef set <ii> sii;
typedef set <pair <int, bool> > sib;
typedef vector <si> vsi;
typedef vector <sii> vsii;
typedef map <int, int> mii;
typedef map <string, char> msc;
typedef map <char, int> mci;
typedef queue <int> qi;
typedef deque <int> di;
typedef stack <int> sti;

const ll inf = (ll)1e9 + 7;
const ldb eps = 1e-18;
const ll pr = 31;
const int sf = 450000;

int n, a[3];

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vs a(n + 1);
    vvi dp(m, vi(2, (int)1e9));
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vi p(m, 0);
    for (int i = 0; i < m; ++i)
    {
        p[i] = (i > 0 ? p[i - 1] : 0);
        for (int j = 0; j < n; ++j)
            p[i] += (a[j][i] == '#');
    }
    dp[0][1] = p[0];
    dp[0][0] = n - p[0];
    for (int i = 0; i < m; ++i)
        for (int t = 0; t < 2; ++t)
            for (int j = x; j <= min(i + 1, y); ++j)
                dp[i][t] = min(dp[i][t], (i == j - 1 ? 0 : dp[i - j][1 - t]) + (t == 1 ? p[i] - (i == j - 1 ? 0 : p[i - j]) : n * j - p[i] + (i == j - 1 ? 0 : p[i - j])));
    cout << min(dp[m - 1][0], dp[m - 1][1]);
    return 0;
}


// B. Well-known Numbers

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <sstream>

using namespace std;

typedef vector<int> IntVec;

int main(int argc, char *argv[])
{
	while (true) {
		string s;
		getline(cin, s);
		stringstream sa(s);
		int S = 0, K = 0;
		sa >> S >> K;
		if (S < 1) break;

		IntVec v;
		v.push_back(1);
		v.push_back(1);
		int i = 2 - K;
		int n = 2;
		while (n <= S) {
			v.push_back(n);
			n *= 2;
			if (i >= 0) {
				n -= v[i];
			}
			++i;
		}

		IntVec ans;
		IntVec::const_reverse_iterator it;
		for (it = v.rbegin(); it != v.rend(); ++it) {
			if (*it <= S) {
				ans.push_back(*it);
				S -= *it;
			}
		}
		if (ans.size() < 2) {
			ans.push_back(0);
		}
		sort(ans.begin(), ans.end());
		cout << ans.size() << endl;
		for (i = 0; i < ans.size(); ++i) {
			if (i) {
				cout << " ";
			}
			cout << ans[i];
		}
		cout << endl;
	}

	return 0;
}


// C. Barcode

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <sstream>

using namespace std;

typedef vector<int> IntVec;

int main(int argc, char *argv[])
{
	while (true) {
		int i, j, pos, color, sum;
		string s;
		getline(cin, s);
		stringstream sa(s);
		int N = 0, M = 0, X = 0, Y = 0;
		sa >> N >> M >> X >> Y;
		if (N < 1 || M < 1 || X < 1 || Y < 1) {
			break;
		}

		static int changecost[2][10];
		memset(changecost, 0, sizeof(changecost));
		for (i = 0; i < N; ++i) {
			getline(cin, s);
			for (j = 0; j < M; ++j) {
				changecost[0][j] += s[j] == '.';
				changecost[1][j] += s[j] != '.';
			}
		}

		static int dp[2][1001];
		memset(dp, 0x7f, sizeof(dp));
		dp[0][0] = 0;
		dp[1][0] = 0;
		for (pos = 0; pos <= M; ++pos) {
			for (color = 0; color < 2; ++color) {
				for (i = X; i <= Y; ++i) {
					if (pos < i) {
						continue;
					}
					sum = 0;
					for (j = 1; j <= i; ++j) {
						sum += changecost[color][pos-j];
					}
					dp[color][pos] = min(dp[color][pos], dp[color^1][pos-i] + sum);
				}
			}
		}

		int ans = min(dp[0][M], dp[1][M]);
		cout << ans << endl;
	}

	return 0;
}


// C. Barcode

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <sstream>

using namespace std;

typedef vector<int> IntVec;

int main(int argc, char *argv[])
{
	while (true) {
		int i, j, pos, color, sum;
		string s;
		getline(cin, s);
		stringstream sa(s);
		int N = 0, M = 0, X = 0, Y = 0;
		sa >> N >> M >> X >> Y;
		if (N < 1 || M < 1 || X < 1 || Y < 1) {
			break;
		}

		static int changecost[2][1000];
		memset(changecost, 0, sizeof(changecost));
		for (i = 0; i < N; ++i) {
			getline(cin, s);
			for (j = 0; j < M; ++j) {
				changecost[0][j] += s[j] == '.';
				changecost[1][j] += s[j] != '.';
			}
		}

		static int dp[2][1001];
		memset(dp, 0x7f, sizeof(dp));
		dp[0][0] = 0;
		dp[1][0] = 0;
		for (pos = 0; pos <= M; ++pos) {
			for (color = 0; color < 2; ++color) {
				for (i = X; i <= Y; ++i) {
					if (pos < i) {
						continue;
					}
					sum = 0;
					for (j = 1; j <= i; ++j) {
						sum += changecost[color][pos-j];
					}
					dp[color][pos] = min(dp[color][pos], dp[color^1][pos-i] + sum);
				}
			}
		}

		int ans = min(dp[0][M], dp[1][M]);
		cout << ans << endl;
	}

	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1100
#define INF 0x3f3f3f3f

using namespace std;

int n, m, x, y, a[maxn];
char map[maxn][maxn];
int dp[maxn][maxn];

int main(void)
{
	scanf("%d %d %d %d", &n, &m, &x, &y);
	memset(a, 0, sizeof(a));
	for (int i = 1; i <= n; i++)
	{
		getchar();
		for (int j = 1; j <= m; j++)
			scanf("%c", &map[i][j]);
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (map[i][j] == '#')
				a[j]++;
	for (int i = 1; i <= m; i++)
		a[i] += a[i - 1];
	memset(dp, 0x42, sizeof(dp));
	dp[0][0] = 0, dp[1][0] = 0;
	for (int i = 0; i <= m; i++)
	{
		for (int j = x; j <= y; j++)
		{
			if (x + y <= m)
			{
				dp[0][i + j] = min(dp[1][i] + a[i + j] - a[i], dp[0][i + j]);
				dp[1][i + j] = min(dp[0][i] + n * j - a[i + j] + a[i], dp[1][i + j]);
			}
		}
	}
	printf("%d\n", min(dp[0][m], dp[1][m]));
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1100
#define INF 0x3f3f3f3f
#define min(a, b) (a < b? a:b)
using namespace std;

int n, m, x, y, a[maxn];
char map[maxn][maxn];
int dp[maxn][maxn];

int main(void)
{
	scanf("%d %d %d %d", &n, &m, &x, &y);
	memset(a, 0, sizeof(a));
	for (int i = 1; i <= n; i++)
	{
		getchar();
		for (int j = 1; j <= m; j++)
			scanf("%c", &map[i][j]);
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (map[i][j] == '#')
				a[j]++;
	for (int i = 1; i <= m; i++)
		a[i] += a[i - 1];
	memset(dp, 0x42, sizeof(dp));
	dp[0][0] = 0, dp[1][0] = 0;
	for (int i = 0; i <= m; i++)
	{
		for (int j = x; j <= y && i + j <= m; j++)
		{
			dp[0][i + j] = min(dp[1][i] + a[i + j] - a[i], dp[0][i + j]);
			dp[1][i + j] = min(dp[0][i] + n * j - a[i + j] + a[i], dp[1][i + j]);
		}
	}
	printf("%d\n", min(dp[0][m], dp[1][m]));
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1100
#define INF 0x3f3f3f3f

using namespace std;

int n, m, x, y, a[maxn];
char map[maxn][maxn];
int dp[maxn][maxn];

int main(void)
{
	scanf("%d %d %d %d", &n, &m, &x, &y);
	memset(a, 0, sizeof(a));
	for (int i = 1; i <= n; i++)
	{
		getchar();
		for (int j = 1; j <= m; j++)
			scanf("%c", &map[i][j]);
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (map[i][j] == '#')
				a[j]++;
	for (int i = 1; i <= m; i++)
		a[i] += a[i - 1];
	memset(dp, 0x42, sizeof(dp));
	dp[0][0] = 0, dp[1][0] = 0;
	for (int i = 0; i <= m; i++)
	{
		for (int j = x; j <= y; j++)
		{
			if (i + j <= m)
			{
				dp[0][i + j] = min(dp[1][i] + a[i + j] - a[i], dp[0][i + j]);
				dp[1][i + j] = min(dp[0][i] + n * j - a[i + j] + a[i], dp[1][i + j]);
			}
		}
	}
	printf("%d\n", min(dp[0][m], dp[1][m]));
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1100
#define INF 0x3f3f3f3f

using namespace std;

int n, m, x, y, a[maxn];
char map[maxn][maxn];
int dp[maxn][maxn];

int main(void)
{
	scanf("%d %d %d %d", &n, &m, &x, &y);
	memset(a, 0, sizeof(a));
	for (int i = 1; i <= n; i++)
	{
		getchar();
		for (int j = 1; j <= m; j++)
			scanf("%c", &map[i][j]);
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (map[i][j] == '#')
				a[j]++;
	for (int i = 1; i <= m; i++)
		a[i] += a[i - 1];
	for (int i = 0; i < maxn; i++)
		for (int j = 0; j < maxn; j++)
			dp[i][j] = INF;
	dp[0][0] = 0, dp[1][0] = 0;
	for (int i = 0; i <= m; i++)
	{
		for (int j = x; j <= y; j++)
		{
			if (i + j <= m)
			{
				dp[0][i + j] = min(dp[1][i] + a[i + j] - a[i], dp[0][i + j]);
				dp[1][i + j] = min(dp[0][i] + n * j - a[i + j] + a[i], dp[1][i + j]);
			}
		}
	}
	printf("%d\n", min(dp[0][m], dp[1][m]));
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define eps 1e-9
#define N 1005
#define inf 0x3f3f3f3f

int A[N][N];
int color[N][2];
int dp[N][N][2];

int main()
{
    int n, m, x, y, i, j, k;
    char c;
    scanf("%d %d %d %d", &n, &m, &x, &y);
    for(i = 1; i <= n; i++)
        for(j = 1; j <= m; j++)
        {
            cin >> c;
            if(c == '#') A[i][j] = 1;
            color[j][0] += (A[i][j] != 0);
            color[j][1] += (A[i][j] != 1);
        }
    memset(dp, 63, sizeof(dp));
    dp[1][1][0] = color[1][0];
    dp[1][1][1] = color[1][1];
    for(i = 2; i <= m; i++)
        for(k = 0; k < 2; k++)
            for(j = 1; j < i; j++)
            {
                dp[i][j + 1][k] = min(dp[i][j + 1][k], dp[i - 1][i - j][k] + color[i][k]);
                dp[i][1][k] = min(dp[i][1][k], dp[i - 1][i - j][1 - k] + color[i][k]);
            }
    int res = inf;
    for(i = 1; i <= m; i++)
        for(k = 0; k < 2; k++)
            if(i >= x && i <= y)
                res = min(res, dp[m][i][k]);
    printf("%d\n", res);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define eps 1e-9
#define N 1005
#define inf 0x3f3f3f3f

int A[N][N];
int color[N][2];
int dp[N][N][2];

int main()
{
    int n, m, x, y, i, j, k;
    char c;
    scanf("%d %d %d %d", &n, &m, &x, &y);
    for(i = 1; i <= n; i++)
        for(j = 1; j <= m; j++)
        {
            cin >> c;
            if(c == '#') A[i][j] = 1;
            color[j][0] += (A[i][j] != 0);
            color[j][1] += (A[i][j] != 1);
        }
    memset(dp, 63, sizeof(dp));
    dp[1][1][0] = color[1][0];
    dp[1][1][1] = color[1][1];
    for(i = 2; i <= m; i++)
        for(k = 0; k < 2; k++)
            for(j = 1; j < i; j++)
            {
                if(j + 1 <= y)
                    dp[i][j + 1][k] = min(dp[i][j + 1][k], dp[i - 1][j][k] + color[i][k]);
                if(j >= x && j <= y)
                    dp[i][1][k] = min(dp[i][1][k], dp[i - 1][j][1 - k] + color[i][k]);
            }
    int res = inf;
    for(i = 1; i <= m; i++)
        for(k = 0; k < 2; k++)
            if(i >= x && i <= y)
                res = min(res, dp[m][i][k]);
    printf("%d\n", res);
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define eps 1e-9
#define N 1005
#define inf 0x3f3f3f3f

int A[N][N];
int color[N][2];
int dp[N][N][2];

int main()
{
    int n, m, x, y, i, j, k;
    char c;
    scanf("%d %d %d %d", &n, &m, &x, &y);
    for(i = 1; i <= n; i++)
        for(j = 1; j <= m; j++)
        {
            cin >> c;
            if(c == '#') A[i][j] = 1;
            color[j][0] += (A[i][j] != 0);
            color[j][1] += (A[i][j] != 1);
        }
    memset(dp, 63, sizeof(dp));
    dp[1][1][0] = color[1][0];
    dp[1][1][1] = color[1][1];
    for(i = 2; i <= m; i++)
        for(k = 0; k < 2; k++)
            for(j = 1; j < i; j++)
            {
                dp[i][j + 1][k] = min(dp[i][j + 1][k], dp[i - 1][i - j][k] + color[i][k]);
                if(j >= x && j <= y)
                    dp[i][1][k] = min(dp[i][1][k], dp[i - 1][i - j][1 - k] + color[i][k]);
            }
    int res = inf;
    for(i = 1; i <= m; i++)
        for(k = 0; k < 2; k++)
            if(i >= x && i <= y)
                res = min(res, dp[m][i][k]);
    printf("%d\n", res);
}


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

using namespace std;

#define max(a,b)   (((a) > (b)) ? (a) : (b))
#define min(a,b)   (((a) > (b)) ? (b) : (a))

typedef unsigned long long ULL;
int MOD = 1000000007;

int gcd(int a, int b)
{
	int c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int iabs(int x)
{
	if (x >= 0)
		return x;
	return -x;
}

void factor(ULL x, vector <ULL> &factors)
{
	for (ULL i = 2; i <= ceil(sqrt(1.0*x)) + 1; ++i)
	{
		while (x % i == 0)
		{
			factors.push_back(i);
			x /= i;
		}
	}

	if (x != 1){
		factors.push_back(x);
	}
}

bool cmp(pair <ULL, pair<ULL, ULL>>  A, pair <ULL, pair<ULL, ULL>>  B)
{
	return A.first < B.first;
}

bool less_cmp(pair <int, int>  A, pair <int, int> B)
{
	return A.first < B.first;
}

int main(void)
{
	int dbg = 1;

	if (dbg)
	 freopen("in.txt", "r", stdin);

    ////
	//string s;
	//vector <int> v;
	//vector <ULL> v;
	//vector <vector<int>> v;
	//ULL ans = 0;
	int n, m, x, y;
	vector <vector<int>> dp, a;

	cin >> n >> m >> x >> y;

	dp.resize(m);
	a.resize(n);

	for (int i = 0; i < n; ++i)
	{
		a[i].resize(m);
		for (int j = 0; j < m; ++j){
			char c;
			cin >> c;
			if (c == '#')
				a[i][j] = 1;
			else if (c == '.')
				a[i][j] = 0;
		}
	}

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

	vector <int> s;

	s.assign(m, 0);

	for (int j = 0; j < m; ++j)
	  for (int i = 0; i < n; ++i)
		s[j] += a[i][j];

	dp[0][0] = s[0];
	dp[0][1] = n - s[0];

	for (int i = 1; i < m; ++i)
	{
		dp[i][0] = dp[i-1][0];
		for (int j = x; j <= y; ++j)
			dp[i][0] = min(dp[i-1][j], dp[i][0]);
		dp[i][0] += s[i];
		for (int j = 1; j <= y; j++)
			dp[i][j] = dp[i-1][j-1] + n - s[i];
	}

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

	/*for (int i = 0; i < n; ++i){
		for (int j = 0; j < m; ++j)
			printf("%3i ", a[i][j]);
		printf("\n");
	}

	printf("\n");
	for (int j = 0; j < m; ++j)
		printf("%3i ", s[j]);
	printf("\n\n");

	for (int i = 0; i < m; ++i){
		for (int j = 0; j <= y; ++j)
			if (dp[i][j] == 1e9)
				printf("INF ");
			else
				printf("%3i ", dp[i][j]);
		printf("\n");
	}
	printf("\n");*/
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define max(a,b)   (((a) > (b)) ? (a) : (b))
#define min(a,b)   (((a) > (b)) ? (b) : (a))

typedef unsigned long long ULL;
int MOD = 1000000007;

int gcd(int a, int b)
{
	int c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int iabs(int x)
{
	if (x >= 0)
		return x;
	return -x;
}

void factor(ULL x, vector <ULL> &factors)
{
	for (ULL i = 2; i <= ceil(sqrt(1.0*x)) + 1; ++i)
	{
		while (x % i == 0)
		{
			factors.push_back(i);
			x /= i;
		}
	}

	if (x != 1){
		factors.push_back(x);
	}
}

bool cmp(pair <ULL, pair<ULL, ULL>>  A, pair <ULL, pair<ULL, ULL>>  B)
{
	return A.first < B.first;
}

bool less_cmp(pair <int, int>  A, pair <int, int> B)
{
	return A.first < B.first;
}

int main(void)
{
	int dbg = 0;

	if (dbg)
	 freopen("in.txt", "r", stdin);

    ////
	//string s;
	//vector <int> v;
	//vector <ULL> v;
	//vector <vector<int>> v;
	//ULL ans = 0;
	int n, m, x, y;
	vector <vector<int>> dp, a;

	cin >> n >> m >> x >> y;

	dp.resize(m);
	a.resize(n);

	for (int i = 0; i < n; ++i)
	{
		a[i].resize(m);
		for (int j = 0; j < m; ++j){
			char c;
			cin >> c;
			if (c == '#')
				a[i][j] = 1;
			else if (c == '.')
				a[i][j] = 0;
		}
	}

	for (int i = 0; i < m; ++i)
	  dp[i].assign(2*y, 1e9); // w: 1,...,y; b: 1,...,y

	vector <int> s;

	s.assign(m, 0);

	for (int j = 0; j < m; ++j)
	  for (int i = 0; i < n; ++i)
		s[j] += a[i][j];

	dp[0][0] = s[0];
	dp[0][y] = n - s[0];

	for (int i = 1; i < m; ++i)
	{
		//one current white column
		dp[i][0] = 1e9;
		for (int j = x-1; j < y; ++j)
			dp[i][0] = min(dp[i-1][y+j] + s[i], dp[i][0]);

		//two and more white columns
		for (int j = 1; j < y; ++j)
			dp[i][j] = min(dp[i-1][j-1] + s[i], 1e9);

		//one current black column
		dp[i][y] = 1e9;
		for (int j = x-1; j < y; ++j)
			dp[i][y] = min(dp[i-1][j] + n - s[i], dp[i][y]);

		//two and more black columns
		for (int j = 1; j < y; ++j)
			dp[i][j] = min(dp[i-1][y+j-1] + n - s[i], 1e9);
	}

	int ans = 1e9;
	for (int i = 0; i < 2*y; ++i)
		ans = min(ans, dp[m - 1][i]);

	/*for (int i = 0; i < n; ++i){
		for (int j = 0; j < m; ++j)
			printf("%3i ", a[i][j]);
		printf("\n");
	}

	printf("\n");
	for (int j = 0; j < m; ++j)
		printf("%3i ", s[j]);
	printf("\n\n");

	for (int i = 0; i < dp.size(); ++i){
		for (int j = 0; j < dp[i].size(); ++j)
			if (dp[i][j] == 1e9)
				printf("INF ");
			else
				printf("%3i ", dp[i][j]);
		printf("\n");
	}
	printf("\n");*/
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define max(a,b)   (((a) > (b)) ? (a) : (b))
#define min(a,b)   (((a) > (b)) ? (b) : (a))

typedef unsigned long long ULL;
int MOD = 1000000007;

int gcd(int a, int b)
{
	int c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int iabs(int x)
{
	if (x >= 0)
		return x;
	return -x;
}

void factor(ULL x, vector <ULL> &factors)
{
	for (ULL i = 2; i <= ceil(sqrt(1.0*x)) + 1; ++i)
	{
		while (x % i == 0)
		{
			factors.push_back(i);
			x /= i;
		}
	}

	if (x != 1){
		factors.push_back(x);
	}
}

bool cmp(pair <ULL, pair<ULL, ULL>>  A, pair <ULL, pair<ULL, ULL>>  B)
{
	return A.first < B.first;
}

bool less_cmp(pair <int, int>  A, pair <int, int> B)
{
	return A.first < B.first;
}

int main(void)
{
	int dbg = 0;

	if (dbg)
	 freopen("in.txt", "r", stdin);

    ////
	//string s;
	//vector <int> v;
	//vector <ULL> v;
	//vector <vector<int>> v;
	//ULL ans = 0;
	int n, m, x, y;
	vector <vector<int>> dp, a;

	cin >> n >> m >> x >> y;

	dp.resize(m);
	a.resize(n);

	for (int i = 0; i < n; ++i)
	{
		a[i].resize(m);
		for (int j = 0; j < m; ++j){
			char c;
			cin >> c;
			if (c == '#')
				a[i][j] = 1;
			else if (c == '.')
				a[i][j] = 0;
		}
	}

	for (int i = 0; i < m; ++i)
	  dp[i].assign(2*y, 1e9); // w: 1,...,y; b: 1,...,y

	vector <int> s;

	s.assign(m, 0);

	for (int j = 0; j < m; ++j)
	  for (int i = 0; i < n; ++i)
		s[j] += a[i][j];

	dp[0][0] = s[0];
	dp[0][y] = n - s[0];

	for (int i = 1; i < m; ++i)
	{
		//one current white column
		dp[i][0] = 1e9;
		for (int j = x-1; j < y; ++j)
			dp[i][0] = min(dp[i-1][y+j] + s[i], dp[i][0]);

		//two and more white columns
		for (int j = 1; j < y; ++j)
			dp[i][j] = min(dp[i-1][j-1] + s[i], 1e9);

		//one current black column
		dp[i][y] = 1e9;
		for (int j = x-1; j < y; ++j)
			dp[i][y] = min(dp[i-1][j] + n - s[i], dp[i][y]);

		//two and more black columns
		for (int j = 1; j < y; ++j)
			dp[i][y+j] = min(dp[i-1][y+j-1] + n - s[i], 1e9);
	}

	int ans = 1e9;
	for (int i = 0; i < 2*y; ++i)
		ans = min(ans, dp[m - 1][i]);
	/*
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < m; ++j)
			printf("%3i ", a[i][j]);
		printf("\n");
	}

	printf("\n");
	for (int j = 0; j < m; ++j)
		printf("%3i ", s[j]);
	printf("\n\n");

	for (int i = 0; i < dp.size(); ++i){
		for (int j = 0; j < dp[i].size(); ++j)
			if (dp[i][j] == 1e9)
				printf("INF ");
			else
				printf("%3i ", dp[i][j]);
		printf("\n");
	}
	printf("\n");*/
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define max(a,b)   (((a) > (b)) ? (a) : (b))
#define min(a,b)   (((a) > (b)) ? (b) : (a))

typedef unsigned long long ULL;
int MOD = 1000000007;

int gcd(int a, int b)
{
	int c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int iabs(int x)
{
	if (x >= 0)
		return x;
	return -x;
}

void factor(ULL x, vector <ULL> &factors)
{
	for (ULL i = 2; i <= ceil(sqrt(1.0*x)) + 1; ++i)
	{
		while (x % i == 0)
		{
			factors.push_back(i);
			x /= i;
		}
	}

	if (x != 1){
		factors.push_back(x);
	}
}

bool cmp(pair <ULL, pair<ULL, ULL>>  A, pair <ULL, pair<ULL, ULL>>  B)
{
	return A.first < B.first;
}

bool less_cmp(pair <int, int>  A, pair <int, int> B)
{
	return A.first < B.first;
}

int main(void)
{
	int dbg = 0;

	if (dbg)
	 freopen("in.txt", "r", stdin);

    ////
	//string s;
	//vector <int> v;
	//vector <ULL> v;
	//vector <vector<int>> v;
	//ULL ans = 0;
	int n, m, x, y;
	vector <vector<int>> dp, a;

	cin >> n >> m >> x >> y;

	dp.resize(m);
	a.resize(n);

	for (int i = 0; i < n; ++i)
	{
		a[i].resize(m);
		for (int j = 0; j < m; ++j){
			char c;
			cin >> c;
			if (c == '#')
				a[i][j] = 1;
			else if (c == '.')
				a[i][j] = 0;
		}
	}

	for (int i = 0; i < m; ++i)
	  dp[i].assign(2*y, 1e9); // w: 1,...,y; b: 1,...,y

	vector <int> s;

	s.assign(m, 0);

	for (int j = 0; j < m; ++j)
	  for (int i = 0; i < n; ++i)
		s[j] += a[i][j];

	dp[0][0] = s[0];
	dp[0][y] = n - s[0];

	for (int i = 1; i < m; ++i)
	{
		//one current white column
		dp[i][0] = 1e9;
		for (int j = x-1; j < y; ++j)
			dp[i][0] = min(dp[i-1][y+j] + s[i], dp[i][0]);

		//two and more white columns
		for (int j = 1; j < y; ++j)
			dp[i][j] = min(dp[i-1][j-1] + s[i], 1e9);

		//one current black column
		dp[i][y] = 1e9;
		for (int j = x-1; j < y; ++j)
			dp[i][y] = min(dp[i-1][j] + n - s[i], dp[i][y]);

		//two and more black columns
		for (int j = 1; j < y; ++j)
			dp[i][y+j] = min(dp[i-1][y+j-1] + n - s[i], 1e9);
	}

	int ans = 1e9;
	for (int i = x - 1; i < y; ++i)
		ans = min(ans, min(dp[m - 1][y + i], dp[m - 1][i]));
	/*
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < m; ++j)
			printf("%3i ", a[i][j]);
		printf("\n");
	}

	printf("\n");
	for (int j = 0; j < m; ++j)
		printf("%3i ", s[j]);
	printf("\n\n");

	for (int i = 0; i < dp.size(); ++i){
		for (int j = 0; j < dp[i].size(); ++j)
			if (dp[i][j] == 1e9)
				printf("INF ");
			else
				printf("%3i ", dp[i][j]);
		printf("\n");
	}
	printf("\n");*/
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define max(a,b)   (((a) > (b)) ? (a) : (b))
#define min(a,b)   (((a) > (b)) ? (b) : (a))

typedef unsigned long long ULL;
int MOD = 1000000007;

int gcd(int a, int b)
{
	int c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int iabs(int x)
{
	if (x >= 0)
		return x;
	return -x;
}

void factor(ULL x, vector <ULL> &factors)
{
	for (ULL i = 2; i <= ceil(sqrt(1.0*x)) + 1; ++i)
	{
		while (x % i == 0)
		{
			factors.push_back(i);
			x /= i;
		}
	}

	if (x != 1){
		factors.push_back(x);
	}
}

bool cmp(pair <ULL, pair<ULL, ULL>>  A, pair <ULL, pair<ULL, ULL>>  B)
{
	return A.first < B.first;
}

bool less_cmp(pair <int, int>  A, pair <int, int> B)
{
	return A.first < B.first;
}

int main(void)
{
	int dbg = 0;

	if (dbg)
	 freopen("in.txt", "r", stdin);

    ////
	//string s;
	//vector <int> v;
	//vector <ULL> v;
	//vector <vector<int>> v;
	//ULL ans = 0;
	int n, m, x, y;
	vector <vector<int>> dp, a;

	cin >> n >> m >> x >> y;

	dp.resize(m);
	a.resize(n);

	for (int i = 0; i < n; ++i)
	{
		a[i].resize(m);
		for (int j = 0; j < m; ++j){
			char c;
			cin >> c;
			if (c == '#')
				a[i][j] = 1;
			else if (c == '.')
				a[i][j] = 0;
		}
	}

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

	vector <int> s;

	s.assign(m, 0);

	for (int j = 0; j < m; ++j)
	  for (int i = 0; i < n; ++i)
		s[j] += a[i][j];

	dp[0][0] = s[0];
	dp[0][1] = n - s[0];

	for (int i = 1; i < m; ++i)
	{
		dp[i][0] = dp[i-1][0];
		for (int j = x; j <= y; ++j)
			dp[i][0] = min(dp[i-1][j], dp[i][0]);
		dp[i][0] += s[i];
		for (int j = 1; j <= y; j++)
			dp[i][j] = dp[i-1][j-1] + n - s[i];
	}

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

	/*for (int i = 0; i < n; ++i){
		for (int j = 0; j < m; ++j)
			printf("%3i ", a[i][j]);
		printf("\n");
	}

	printf("\n");
	for (int j = 0; j < m; ++j)
		printf("%3i ", s[j]);
	printf("\n\n");

	for (int i = 0; i < m; ++i){
		for (int j = 0; j <= y; ++j)
			if (dp[i][j] == 1e9)
				printf("INF ");
			else
				printf("%3i ", dp[i][j]);
		printf("\n");
	}
	printf("\n");*/
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <numeric>

#if !defined(__GNUC__)
#include <hash_set>
#include <hash_map>

typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed long int32_t;
typedef unsigned long uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

typedef stdext::hash_set<size_t>    hash_set_size_t;
#else // !defined(__GNUC__)

#endif // !defined(__GNUC__)

typedef long double double_t;
typedef std::string string8_t;

typedef std::vector<size_t> vector_size_t;
typedef std::vector<int32_t> vector_int32_t;
typedef std::vector<uint32_t> vector_uint32_t;
typedef std::vector<vector_uint32_t> vector_2d_uint32_t;
typedef std::set<size_t> set_size_t;
typedef std::multiset<size_t> multiset_size_t;

typedef std::vector<string8_t> vector_string8_t;
typedef std::set<string8_t> set_string8_t;
typedef std::multiset<std::string> multiset_string8_t;

// Auxiliary functions definition
//
template<typename T> inline T Abs(const T a) { return a < 0 ? -a : a; }
template<typename T> inline T Min(const T a, const T b) {return a < b ? a : b;}
template<typename T> inline T Max(const T a, const T b) {return a > b ? a : b;}

static const double_t eps = 1.0e-09;
template<typename T> inline bool IsEqual(const T a, const T b) { return Abs(a - b) < eps; }
template<typename T> inline bool IsGreater(const T a, const T b) { return a > b + eps; }
template<typename T> inline bool IsLess(const T a, const T b) { return a + eps < b; }

template<typename T> inline string8_t ToStr(const T& val) { std::ostringstream ostr; ostr << val; return ostr.str(); }
template<typename T> inline bool FromStr(const string8_t& str, T& val) {std::istringstream istr(str); istr >> val; return !!istr; }

#if defined(ONLINE_JUDGE) || defined(__GNUC__)
template<size_t id> class StopWatch { };
#else //defined(ONLINE_JUDGE)
#include <library/lib_stopwatch.h>
#endif //defined(ONLINE_JUDGE)

template<typename T>
void UpdateMin(T& m, const T& v) { m = Min<T>(m, v); }

const uint32_t Undefined = ULONG_MAX/2;

struct RecSolution
{
    RecSolution(
        size_t m_, size_t x_, size_t y_,
        const vector_uint32_t& bc_, const vector_uint32_t& wc_, vector_2d_uint32_t& dbWB_, vector_2d_uint32_t& dpBW_)
        : m(m_), x(x_), y(y_), bc(bc_), wc(wc_), dpWB(dbWB_), dpBW(dpBW_),
        defined(m+1)
    {

    }

    void operator()(const size_t t)
    {
        if (defined[t])
            return;

        if (t == 0)
        {
            for (size_t d = 0; d <= y; d++)
            {
                dpWB[0][d] = 0;
                dpBW[0][d] = 0;
            }
            defined[0] = 1;
            return;
        }

        (*this)(t-1);
        for (size_t d = y; d != 0; d--)
        {
            if (t >= d)
            {
                UpdateMin(dpWB[t][d], dpWB[t-1][d-1] + wc[t]);
                UpdateMin(dpBW[t][d], dpBW[t-1][d-1] + bc[t]);
            }
        }

        for (size_t p = x; p <= y; p++)
        {
            UpdateMin(dpBW[t][0], dpWB[t][p]);
            UpdateMin(dpWB[t][0], dpBW[t][p]);
        }

        defined[t] = 1;
    }

    const size_t m;
    const size_t x;
    const size_t y;
    const vector_uint32_t& bc;
    const vector_uint32_t& wc;
    vector_2d_uint32_t& dpWB;
    vector_2d_uint32_t& dpBW;
    vector_uint32_t defined;
};

bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
    StopWatch<1> sw;

    size_t n, m;
    ist >> n >> m;

    if (multipleTestMode && !ist)
        return false;

    uint32_t x, y;
    ist >> x >> y;

    vector_string8_t f(n);
    for (size_t i = 0; i < n; i++)
        ist >> f[i];

    vector_uint32_t bc(m+1);
    vector_uint32_t wc(m+1);
    for (size_t i = 0; i < m; i++)
    {
        uint32_t b = 0;
        for (size_t j = 0; j < n; j++)
        {
            if (f[j][i] == '#')
                b++;
        }
        bc[i+1] = b;
        wc[i+1] = (uint32_t)n - b;
    }

    vector_2d_uint32_t dpWB(m+1, vector_uint32_t(y+1, Undefined));
    vector_2d_uint32_t dpBW(m+1, vector_uint32_t(y+1, Undefined));

    RecSolution rec(m, x, y, bc, wc, dpWB, dpBW);
    rec(m);

    uint32_t minAns = Undefined;
    for (size_t i = x; i <= y; i++)
    {
        minAns = Min(minAns, dpWB[m][i]);
        minAns = Min(minAns, dpBW[m][i]);
    }

    ost << minAns << std::endl;

    return multipleTestMode;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::istream& ist = std::cin;
    std::ostream& ost = std::cout;
#if defined(ONLINE_JUDGE)
    Solve(ist, ost, false);
#else
    while(Solve(ist, ost, true)) {};
#endif
}


#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <numeric>

#if !defined(__GNUC__)
#include <hash_set>
#include <hash_map>

typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed long int32_t;
typedef unsigned long uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

typedef stdext::hash_set<size_t>    hash_set_size_t;
#else // !defined(__GNUC__)

#endif // !defined(__GNUC__)

typedef long double double_t;
typedef std::string string8_t;

typedef std::vector<size_t> vector_size_t;
typedef std::vector<int32_t> vector_int32_t;
typedef std::vector<uint32_t> vector_uint32_t;
typedef std::vector<vector_uint32_t> vector_2d_uint32_t;
typedef std::set<size_t> set_size_t;
typedef std::multiset<size_t> multiset_size_t;

typedef std::vector<string8_t> vector_string8_t;
typedef std::set<string8_t> set_string8_t;
typedef std::multiset<std::string> multiset_string8_t;

// Auxiliary functions definition
//
template<typename T> inline T Abs(const T a) { return a < 0 ? -a : a; }
template<typename T> inline T Min(const T a, const T b) {return a < b ? a : b;}
template<typename T> inline T Max(const T a, const T b) {return a > b ? a : b;}

static const double_t eps = 1.0e-09;
template<typename T> inline bool IsEqual(const T a, const T b) { return Abs(a - b) < eps; }
template<typename T> inline bool IsGreater(const T a, const T b) { return a > b + eps; }
template<typename T> inline bool IsLess(const T a, const T b) { return a + eps < b; }

template<typename T> inline string8_t ToStr(const T& val) { std::ostringstream ostr; ostr << val; return ostr.str(); }
template<typename T> inline bool FromStr(const string8_t& str, T& val) {std::istringstream istr(str); istr >> val; return !!istr; }

#if defined(ONLINE_JUDGE) || defined(__GNUC__)
template<size_t id> class StopWatch { };
#else //defined(ONLINE_JUDGE)
#include <library/lib_stopwatch.h>
#endif //defined(ONLINE_JUDGE)

#define UpdateMin(m, v) m = Min(m, v)

bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
    StopWatch<1> sw;

    size_t n, m;
    ist >> n >> m;

    if (multipleTestMode && !ist)
        return false;

    uint32_t x, y;
    ist >> x >> y;

    vector_string8_t f(n);
    for (size_t i = 0; i < n; i++)
        ist >> f[i];

    vector_uint32_t wc(m+1);
    vector_uint32_t bc(m+1);
    for (size_t i = 0; i < m; i++)
    {
        uint32_t b = 0;
        for (size_t j = 0; j < n; j++)
        {
            if (f[j][i] == '#')
                b++;
        }
        bc[i+1] = b;
        wc[i+1] = (uint32_t)n - b;
    }

    vector_2d_uint32_t dp0(m+1, vector_uint32_t(y+1, ULONG_MAX));
    vector_2d_uint32_t dp1(m+1, vector_uint32_t(y+1, ULONG_MAX));

    for (size_t i = 0; i <= y; i++)
    {
        dp0[0][i] = 0;
        dp1[0][i] = 0;
    }

    for (uint32_t w = 1; w <= m; w++)
    {
        for (uint32_t ad = 1; ad <= y; ad++)
        {
            const uint32_t d = y + 1 - ad;
            if (w < d)
                continue;

            UpdateMin(dp0[w][d], dp0[w-1][d-1] + wc[w]);
            UpdateMin(dp1[w][d], dp1[w-1][d-1] + bc[w]);
        }

        for (uint32_t d = x; d <= y; d++)
        {
            if (d <= w)
            {
                UpdateMin(dp0[w][0], dp1[w][d]);
                UpdateMin(dp1[w][0], dp0[w][d]);
            }
        }
    }

    uint32_t minAns = ULONG_MAX;
    for (size_t i = x; i <= y; i++)
    {
        minAns = Min(minAns, dp0[m][i]);
        minAns = Min(minAns, dp1[m][i]);
    }

    ost << minAns << std::endl;

    return multipleTestMode;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::istream& ist = std::cin;
    std::ostream& ost = std::cout;
#if defined(ONLINE_JUDGE)
    Solve(ist, ost, false);
#else
    while(Solve(ist, ost, true)) {};
#endif
}


#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <numeric>

#if !defined(__GNUC__)
#include <hash_set>
#include <hash_map>

typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed long int32_t;
typedef unsigned long uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

typedef stdext::hash_set<size_t>    hash_set_size_t;
#else // !defined(__GNUC__)

#endif // !defined(__GNUC__)

typedef long double double_t;
typedef std::string string8_t;

typedef std::vector<size_t> vector_size_t;
typedef std::vector<int32_t> vector_int32_t;
typedef std::vector<uint32_t> vector_uint32_t;
typedef std::vector<vector_uint32_t> vector_2d_uint32_t;
typedef std::set<size_t> set_size_t;
typedef std::multiset<size_t> multiset_size_t;

typedef std::vector<string8_t> vector_string8_t;
typedef std::set<string8_t> set_string8_t;
typedef std::multiset<std::string> multiset_string8_t;

// Auxiliary functions definition
//
template<typename T> inline T Abs(const T a) { return a < 0 ? -a : a; }
template<typename T> inline T Min(const T a, const T b) {return a < b ? a : b;}
template<typename T> inline T Max(const T a, const T b) {return a > b ? a : b;}

static const double_t eps = 1.0e-09;
template<typename T> inline bool IsEqual(const T a, const T b) { return Abs(a - b) < eps; }
template<typename T> inline bool IsGreater(const T a, const T b) { return a > b + eps; }
template<typename T> inline bool IsLess(const T a, const T b) { return a + eps < b; }

template<typename T> inline string8_t ToStr(const T& val) { std::ostringstream ostr; ostr << val; return ostr.str(); }
template<typename T> inline bool FromStr(const string8_t& str, T& val) {std::istringstream istr(str); istr >> val; return !!istr; }

#if defined(ONLINE_JUDGE) || defined(__GNUC__)
template<size_t id> class StopWatch { };
#else //defined(ONLINE_JUDGE)
#include <library/lib_stopwatch.h>
#endif //defined(ONLINE_JUDGE)

template<typename T>
void UpdateMin(T& m, const T& v) { m = Min<T>(m, v); }

const uint32_t Undefined = ULONG_MAX/2;

bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
    StopWatch<1> sw;

    size_t n, m;
    ist >> n >> m;

    if (multipleTestMode && !ist)
        return false;

    uint32_t x, y;
    ist >> x >> y;

    vector_string8_t f(n);
    for (size_t i = 0; i < n; i++)
        ist >> f[i];

    vector_uint32_t wc(m+1);
    vector_uint32_t bc(m+1);
    for (size_t i = 0; i < m; i++)
    {
        uint32_t b = 0;
        for (size_t j = 0; j < n; j++)
        {
            if (f[j][i] == '#')
                b++;
        }
        bc[i+1] = b;
        wc[i+1] = (uint32_t)n - b;
    }

    vector_2d_uint32_t dpWB(m+1, vector_uint32_t(y+1, Undefined));
    vector_2d_uint32_t dpBW(m+1, vector_uint32_t(y+1, Undefined));

    for (size_t i = 0; i <= y; i++)
    {
        dpWB[0][i] = 0;
        dpBW[0][i] = 0;
    }

    for (uint32_t t = 1; t <= m; t++)
    {
        for (uint32_t d = y; d != 0; d--)
        {
            if (t < d)
                continue;

            UpdateMin(dpWB[t][d], dpWB[t-1][d-1] + wc[t]);
            UpdateMin(dpBW[t][d], dpBW[t-1][d-1] + bc[t]);
        }

        for (uint32_t e = x; e <= y; e++)
        {
            if (e <= t)
            {
                UpdateMin(dpWB[t][0], dpBW[t][e]);
                UpdateMin(dpBW[t][0], dpWB[t][e]);
            }
        }
    }

    uint32_t minAns = Undefined;
    for (size_t i = x; i <= y; i++)
    {
        minAns = Min(minAns, dpWB[m][i]);
        minAns = Min(minAns, dpBW[m][i]);
    }

    ost << minAns << std::endl;

    return multipleTestMode;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::istream& ist = std::cin;
    std::ostream& ost = std::cout;
#if defined(ONLINE_JUDGE)
    Solve(ist, ost, false);
#else
    while(Solve(ist, ost, true)) {};
#endif
}


#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <numeric>

#if !defined(__GNUC__)
#include <hash_set>
#include <hash_map>

typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed long int32_t;
typedef unsigned long uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

typedef stdext::hash_set<size_t>    hash_set_size_t;
#else // !defined(__GNUC__)

#endif // !defined(__GNUC__)

typedef long double double_t;
typedef std::string string8_t;

typedef std::vector<size_t> vector_size_t;
typedef std::vector<int32_t> vector_int32_t;
typedef std::vector<uint32_t> vector_uint32_t;
typedef std::vector<vector_uint32_t> vector_2d_uint32_t;
typedef std::set<size_t> set_size_t;
typedef std::multiset<size_t> multiset_size_t;

typedef std::vector<string8_t> vector_string8_t;
typedef std::set<string8_t> set_string8_t;
typedef std::multiset<std::string> multiset_string8_t;

// Auxiliary functions definition
//
template<typename T> inline T Abs(const T a) { return a < 0 ? -a : a; }
template<typename T> inline T Min(const T a, const T b) {return a < b ? a : b;}
template<typename T> inline T Max(const T a, const T b) {return a > b ? a : b;}

static const double_t eps = 1.0e-09;
template<typename T> inline bool IsEqual(const T a, const T b) { return Abs(a - b) < eps; }
template<typename T> inline bool IsGreater(const T a, const T b) { return a > b + eps; }
template<typename T> inline bool IsLess(const T a, const T b) { return a + eps < b; }

template<typename T> inline string8_t ToStr(const T& val) { std::ostringstream ostr; ostr << val; return ostr.str(); }
template<typename T> inline bool FromStr(const string8_t& str, T& val) {std::istringstream istr(str); istr >> val; return !!istr; }

#if defined(ONLINE_JUDGE) || defined(__GNUC__)
template<size_t id> class StopWatch { };
#else //defined(ONLINE_JUDGE)
#include <library/lib_stopwatch.h>
#endif //defined(ONLINE_JUDGE)

template<typename T>
void UpdateMin(T& m, const T& v) { m = Min<T>(m, v); }

const uint32_t Undefined = ULONG_MAX/2;

bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
    StopWatch<1> sw;

    size_t n, m;
    ist >> n >> m;

    if (multipleTestMode && !ist)
        return false;

    uint32_t x, y;
    ist >> x >> y;

    vector_string8_t f(n);
    for (size_t i = 0; i < n; i++)
        ist >> f[i];

    vector_uint32_t bc(m+1);
    vector_uint32_t wc(m+1);
    for (size_t i = 0; i < m; i++)
    {
        uint32_t b = 0;
        for (size_t j = 0; j < n; j++)
        {
            if (f[j][i] == '#')
                b++;
        }
        bc[i+1] = bc[i] + b;
        wc[i+1] = wc[i] + (uint32_t)n - b;
    }

    vector_uint32_t dpB(m+1, Undefined);
    vector_uint32_t dpW(m+1, Undefined);

    dpW[0] = 0;
    dpB[0] = 0;

    for (size_t w = 0; w < m; w++)
    {
        for (size_t d = x; d <= y; d++)
        {
            if (w + d <= m)
            {
                UpdateMin(dpW[w+d], dpB[w] + bc[w+d] - bc[w]);
                UpdateMin(dpB[w+d], dpW[w] + wc[w+d] - wc[w]);
            }
        }
    }

    uint32_t minAns = Undefined;
    for (size_t i = x; i <= y; i++)
    {
        minAns = Min(minAns, dpW[m]);
        minAns = Min(minAns, dpB[m]);
    }

    ost << minAns << std::endl;

    return multipleTestMode;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::istream& ist = std::cin;
    std::ostream& ost = std::cout;
#if defined(ONLINE_JUDGE)
    Solve(ist, ost, false);
#else
    while(Solve(ist, ost, true)) {};
#endif
}


#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <numeric>

#if !defined(__GNUC__)
#include <hash_set>
#include <hash_map>

typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed long int32_t;
typedef unsigned long uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

typedef stdext::hash_set<size_t>    hash_set_size_t;
#else // !defined(__GNUC__)

#endif // !defined(__GNUC__)

typedef long double double_t;
typedef std::string string8_t;

typedef std::vector<size_t> vector_size_t;
typedef std::vector<int32_t> vector_int32_t;
typedef std::vector<uint32_t> vector_uint32_t;
typedef std::vector<vector_uint32_t> vector_2d_uint32_t;
typedef std::set<size_t> set_size_t;
typedef std::multiset<size_t> multiset_size_t;

typedef std::vector<string8_t> vector_string8_t;
typedef std::set<string8_t> set_string8_t;
typedef std::multiset<std::string> multiset_string8_t;

// Auxiliary functions definition
//
template<typename T> inline T Abs(const T a) { return a < 0 ? -a : a; }
template<typename T> inline T Min(const T a, const T b) {return a < b ? a : b;}
template<typename T> inline T Max(const T a, const T b) {return a > b ? a : b;}

static const double_t eps = 1.0e-09;
template<typename T> inline bool IsEqual(const T a, const T b) { return Abs(a - b) < eps; }
template<typename T> inline bool IsGreater(const T a, const T b) { return a > b + eps; }
template<typename T> inline bool IsLess(const T a, const T b) { return a + eps < b; }

template<typename T> inline string8_t ToStr(const T& val) { std::ostringstream ostr; ostr << val; return ostr.str(); }
template<typename T> inline bool FromStr(const string8_t& str, T& val) {std::istringstream istr(str); istr >> val; return !!istr; }

#if defined(ONLINE_JUDGE) || defined(__GNUC__)
template<size_t id> class StopWatch { };
#else //defined(ONLINE_JUDGE)
#include <library/lib_stopwatch.h>
#endif //defined(ONLINE_JUDGE)

template<typename T>
void UpdateMin(T& m, const T& v) { m = Min<T>(m, v); }

const uint32_t Undefined = ULONG_MAX/2;

struct RecSolution
{
    RecSolution(
        size_t m_, size_t x_, size_t y_,
        const vector_uint32_t& bc_, const vector_uint32_t& wc_, vector_2d_uint32_t& dbWB_, vector_2d_uint32_t& dpBW_)
        : m(m_), x(x_), y(y_), bc(bc_), wc(wc_), dpWB(dbWB_), dpBW(dpBW_)
    {

    }

    bool IsDefined(const size_t t, const size_t d)
    {
        if (dpBW[t][d] < Undefined && dpWB[t][d] < Undefined)
            return true;
        else if (dpBW[t][d] > Undefined || dpWB[t][d] > Undefined)
            _CrtDbgBreak();
        return false;
    }

    void operator()(const size_t t, const size_t d)
    {
        if (IsDefined(t, d))
            return;

        if (t == 0)
        {
            dpWB[t][d] = 0;
            dpBW[t][d] = 0;
            return;
        }

        if (d == 0)
        {
            for (size_t p = x; p <= y; p++)
            {
                (*this)(t, p);
                UpdateMin(dpBW[t][0], dpWB[t][p]);
                UpdateMin(dpWB[t][0], dpBW[t][p]);
            }
            return;
        }

        if (d > 0)
        {
            (*this)(t-1, d-1);
            UpdateMin(dpWB[t][d], dpWB[t-1][d-1] + wc[t]);
            UpdateMin(dpBW[t][d], dpBW[t-1][d-1] + bc[t]);
            return;
        }
    }

    const size_t m;
    const size_t x;
    const size_t y;
    const vector_uint32_t& bc;
    const vector_uint32_t& wc;
    vector_2d_uint32_t& dpWB;
    vector_2d_uint32_t& dpBW;
};

bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
    StopWatch<1> sw;

    size_t n, m;
    ist >> n >> m;

    if (multipleTestMode && !ist)
        return false;

    uint32_t x, y;
    ist >> x >> y;

    vector_string8_t f(n);
    for (size_t i = 0; i < n; i++)
        ist >> f[i];

    vector_uint32_t bc(m+1);
    vector_uint32_t wc(m+1);
    for (size_t i = 0; i < m; i++)
    {
        uint32_t b = 0;
        for (size_t j = 0; j < n; j++)
        {
            if (f[j][i] == '#')
                b++;
        }
        bc[i+1] = b;
        wc[i+1] = (uint32_t)n - b;
    }

    vector_2d_uint32_t dpWB(m+1, vector_uint32_t(y+1, Undefined));
    vector_2d_uint32_t dpBW(m+1, vector_uint32_t(y+1, Undefined));

#if 1
    RecSolution rec(m, x, y, bc, wc, dpWB, dpBW);
    rec(m, y);
#else
    for (size_t i = 0; i <= y; i++)
    {
        dpWB[0][i] = 0;
        dpBW[0][i] = 0;
    }

    for (uint32_t t = 1; t <= m; t++)
    {
        for (uint32_t d = y; d != 0; d--)
        {
            if (t < d)
                continue;

            UpdateMin(dpWB[t][d], dpWB[t-1][d-1] + wc[t]);
            UpdateMin(dpBW[t][d], dpBW[t-1][d-1] + bc[t]);
        }

        for (uint32_t e = x; e <= y; e++)
        {
            if (e <= t)
            {
                UpdateMin(dpWB[t][0], dpBW[t][e]);
                UpdateMin(dpBW[t][0], dpWB[t][e]);
            }
        }
    }
#endif

    uint32_t minAns = Undefined;
    for (size_t i = x; i <= y; i++)
    {
        minAns = Min(minAns, dpWB[m][i]);
        minAns = Min(minAns, dpBW[m][i]);
    }

    ost << minAns << std::endl;

    return multipleTestMode;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::istream& ist = std::cin;
    std::ostream& ost = std::cout;
#if defined(ONLINE_JUDGE)
    Solve(ist, ost, false);
#else
    while(Solve(ist, ost, true)) {};
#endif
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sd second

#define inf 1000000007
#define nmax 500010
#define mmax 100010
#define eps 1e-7

using namespace std;

int W[1010], SW[1010];
int B[1010], SB[1010];
int n, m, x, y, F[1010][2];
char s[1010][1010];

int main()
{
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	cin >> n >> m >> x >> y;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
		{
			cin >> s[i][j];
			if(s[i][j] == '#')
				W[j]++;
			else
				B[j]++;
		}
	for(int i = 1; i <= m; ++i)
		SW[i] = W[i] + SW[i - 1], SB[i] = B[i] + SB[i - 1], F[i][0] = F[i][1] = (int)1e7;
	for(int i = 0; i < m; ++i)
		for(int j = x; j <= y; ++j)
			if(i + j <= m)
			{
				F[i + j][0] = min(F[i + j][0], F[i][1] + SW[i + j] - SW[i]);
				F[i + j][1] = min(F[i + j][1], F[i][0] + SB[i + j] - SB[i]);
			}
	cout << min(F[m][0], F[m][1]) << endl;
	//while(1);
}


#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <set>
#include <map>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sd second

#define inf 1000000007
#define nmax 500010
#define mmax 100010
#define eps 1e-7

using namespace std;

int W[1010], SW[1010];
int B[1010], SB[1010];
int n, m, x, y, F[2][1010];
char s[1010][1010];

int main()
{
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	cin >> n >> m >> x >> y;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
		{
			cin >> s[i][j];
			if(s[i][j] == '#')
				W[j]++;
			else
				B[j]++;
		}
	for(int i = 1; i <= m; ++i)
		SW[i] = W[i] + SW[i - 1], SB[i] = B[i] + SB[i - 1], F[i][0] = F[i][1] = (int)1e7;
	for(int i = 0; i < m; ++i)
		for(int j = x; j <= y; ++j)
			if(i + j <= m)
			{
				F[i + j][0] = min(F[i + j][0], F[i][1] + SW[i + j] - SW[i]);
				F[i + j][1] = min(F[i + j][1], F[i][0] + SB[i + j] - SB[i]);
			}
	cout << min(F[m][0], F[m][1]) << endl;
	//while(1);
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <map>
#include <set>
#pragma comment(linker,"/STACK:16777216")
using namespace std;

//Loops
#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define rep(i,n) for (int (i) = 0; (i) < (n); ++(i))
#define fe(i,a) for (int (i) = 0; (i) < int((a).size()); ++(i))
#define MEMSET(a) memset((a),0,sizeof(a))

//Constants
#define inf 1000000000
#define pi 2*acos(0.0)
#define N 1010
#define eps 1e-9

//Functions
#define pb push_back
#define ppb pop_back
#define all(c) (c).begin(), (c).end()
#define sz(x) int((x).size())
#define sqr(a) (a)*(a)

//Pairs
#define mp(a,b) make_pair((a), (b))
#define X first
#define Y second

//Input-Output
#define FREOPEN(a,b) freopen(a,"r",stdin); freopen(b,"w",stdout);

typedef vector<int> vint;
typedef long long ll;
typedef pair<int, int> pii;

char s[N]={0};
int col[N]={0};
int dp[N][2];
int a[N],b[N];
int main()
{
    //FREOPEN("input.txt","output.txt");
    int i,n,m,j,x,y,k;
    scanf("%d%d%d%d\n",&n,&m,&x,&y);
    rep(i,n)
    {
        gets(s);
        rep(j,m)a[j]+=(s[j]=='#');
    }
    rep(i,m)b[i]=n-a[i];
    rep(i,m+1)
        rep(j,2)dp[i][j]=inf;

    dp[0][0]=dp[0][1]=0;
    rep(i,m)
    {
        rep(f,2)
        {
          if(dp[i][f] < inf)
          {
              k=0;
              for(j=i;j<m;j++)
              {
                  if(f==0)k+=b[j]; else k+=a[j];

                  if(j-i+1>=x && j-i+1<=y)
                  {
                      if(dp[i][f] + k < dp[j+1][1-f])dp[j+1][1-f]=dp[i][f]+k;
                  }
              }
          }
        }
    }
    printf("%d\n",min(dp[m][0],dp[m][1]));
    return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <map>
#include <set>
#pragma comment(linker,"/STACK:16777216")
using namespace std;

//Loops
#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define rep(i,n) for (int (i) = 0; (i) < (n); ++(i))
#define fe(i,a) for (int (i) = 0; (i) < int((a).size()); ++(i))
#define MEMSET(a) memset((a),0,sizeof(a))

//Constants
#define inf 1000000000
#define pi 2*acos(0.0)
#define N 1010
#define eps 1e-9

//Functions
#define pb push_back
#define ppb pop_back
#define all(c) (c).begin(), (c).end()
#define sz(x) int((x).size())
#define sqr(a) (a)*(a)

//Pairs
#define mp(a,b) make_pair((a), (b))
#define X first
#define Y second

//Input-Output
#define FREOPEN(a,b) freopen(a,"r",stdin); freopen(b,"w",stdout);

typedef vector<int> vint;
typedef long long ll;
typedef pair<int, int> pii;

char s[N]={0};
int col[N]={0};
int dp[N][2];
int a[N],b[N];
int main()
{
    //FREOPEN("input.txt","output.txt");
    int i,n,m,j,x,y,k;
    scanf("%d%d%d%d\n",&n,&m,&x,&y);
    rep(i,n)
    {
        gets(s);
        puts(s);
        rep(j,m)a[j]+=(s[j]=='#');
    }
    rep(i,m)b[i]=n-a[i];
    rep(i,m+1)
        rep(j,2)dp[i][j]=inf;

    dp[0][0]=dp[0][1]=0;
    rep(i,m)
    {
        rep(f,2)
        {
          if(dp[i][f] < inf)
          {
              k=0;
              for(j=i;j<m;j++)
              {
                  if(f==0)k+=b[j]; else k+=a[j];

                  if(j-i+1>=x && j-i+1<=y)
                  {
                      if(dp[i][f] + k < dp[j+1][1-f])dp[j+1][1-f]=dp[i][f]+k;
                  }
              }
          }
        }
    }
    printf("%d\n",min(dp[m][0],dp[m][1]));
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<sstream>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<string.h>
#include<string>
#include<map>
#include<algorithm>
#include<time.h>
#include<set>
#include<vector>
#include<numeric>
#include<iomanip>
using namespace std;

#define All(a) a.begin(), a.end()
#define _2d(a,row,col,type) type**a=new type*[row]; for (int i=0;i<row;i++) a[i]=new type[col];
#define rep(i,n) for(int i=0;i<int(n);i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define repi(i,a,n) for(int i=int(a);i<int(n);i++)
#define scn(a,n) rep(i,n) cin>>a[i];
#define scn2(a,row,col) rep(i,row) rep(j,col) cin>>a[i][j];
#define prn(a,n) rep(i,n-1) cout<<a[i]<<" "; cout<<a[n-1]<<endl;
#define prn2(a,row,col) rep(i,row){rep(j,col-1) cout<<a[i][j]<<" "; cout<<a[i][col-1]<<endl;}
#define mp(a, b) make_pair(a, b)
#define Odd(x) x%2!=0
#define Even(x) x%2==0
#define Pi 3.14
#define INF 2000000000 // 2 billion

typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef pair<int, string> is;
typedef vector<ii> vii;

#define FilesX
#define TimeX

/*---------------------------*/

int n, m, x, y;
ll memo[1001][1001][2];
vi a(1001, 0);

ll solve(int i, int num, int c){
	if (i == m)
		return 0;

	ll &ret = memo[i][num][c];
	if (ret != -1)
		return ret;

	if (num < x)
		if (c) return ret = a[i] + solve(i+1, num+1, c);
		else return ret = n - a[i] + solve(i+1, num+1, c);

	if (num < y)
		if (c) return ret = min(a[i] + solve(i+1, num+1, 1), n - a[i] + solve(i+1, 0, 0));
		else return ret = min(n - a[i] + solve(i+1, num+1, 0), a[i] + solve(i+1, 0, 1));
	return solve(i, 0, !c);
}

void solution(){
	memset(memo, -1, sizeof(memo));
	cin>>n>>m>>x>>y;
	//vs s(n);
	string temp;
	rep(i, n){
		cin>>temp;
		//s.push_back(temp);
		rep(j, m){
			if (temp[j] == '.') a[j]++;
		}
	}

	cout<<min(solve(0, 0, 1), solve(0, 0, 0));
}

/*---------------------------*/
int main(){
	#ifdef Files
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	double beg=clock();

	ios::sync_with_stdio;
	solution();

	#ifdef Time
	cout << endl;
	double end=clock();
	printf("*** Total time = %.3f sec ***", (end - beg) / CLOCKS_PER_SEC);
	#endif
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<sstream>
#include<queue>
#include<math.h>
#include<stdlib.h>
#include<stack>
#include<string.h>
#include<string>
#include<map>
#include<algorithm>
#include<time.h>
#include<set>
#include<vector>
#include<numeric>
#include<iomanip>
using namespace std;

#define All(a) a.begin(), a.end()
#define _2d(a,row,col,type) type**a=new type*[row]; for (int i=0;i<row;i++) a[i]=new type[col];
#define rep(i,n) for(int i=0;i<int(n);i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define repi(i,a,n) for(int i=int(a);i<int(n);i++)
#define scn(a,n) rep(i,n) cin>>a[i];
#define scn2(a,row,col) rep(i,row) rep(j,col) cin>>a[i][j];
#define prn(a,n) rep(i,n-1) cout<<a[i]<<" "; cout<<a[n-1]<<endl;
#define prn2(a,row,col) rep(i,row){rep(j,col-1) cout<<a[i][j]<<" "; cout<<a[i][col-1]<<endl;}
#define mp(a, b) make_pair(a, b)
#define Odd(x) x%2!=0
#define Even(x) x%2==0
#define Pi 3.14
#define INF 2000000000 // 2 billion

typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef pair<int, string> is;
typedef vector<ii> vii;

#define FilesX
#define TimeX

/*---------------------------*/

int n, m, x, y;
ll memo[1001][1001][2];
vi a(1001, 0);

ll solve(int i, int num, int c){
	if (i == m){
		if (num < x)	return INF;
		return 0;
	}

	ll &ret = memo[i][num][c];
	if (ret != -1)
		return ret;

	if (num < x)
		if (c) return ret = a[i] + solve(i+1, num+1, c);
		else return ret = n - a[i] + solve(i+1, num+1, c);

	if (num < y)
		if (c) return ret = min(a[i] + solve(i+1, num+1, 1), n - a[i] + solve(i+1, 1, 0));
		else return ret = min(n - a[i] + solve(i+1, num+1, 0), a[i] + solve(i+1, 1, 1));
	return solve(i, 0, !c);
}

void solution(){
	memset(memo, -1, sizeof(memo));
	cin>>n>>m>>x>>y;
	//vs s(n);
	string temp;
	rep(i, n){
		cin>>temp;
		//s.push_back(temp);
		rep(j, m){
			if (temp[j] == '.') a[j]++;
		}
	}

	cout<<min(solve(0, 0, 1), solve(0, 0, 0));
}

/*---------------------------*/
int main(){
	#ifdef Files
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	double beg=clock();

	ios::sync_with_stdio;
	solution();

	#ifdef Time
	cout << endl;
	double end=clock();
	printf("*** Total time = %.3f sec ***", (end - beg) / CLOCKS_PER_SEC);
	#endif
	return 0;
}


#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <memory.h>
#include <map>
using namespace std;

typedef long long lli;
typedef pair<int,int> pii;
typedef unsigned long long llu;
typedef vector<int> vi;
typedef vector<pii> vpi;

int n,m;
int mn,mx;
char a[1001][1001] = {0};

int b[1001] = {0};

lli c[2000][2] = {0};

int main() {
	scanf("%d%d%d%d\n",&n,&m,&mn,&mx);
	int i,j;
	for(i = 0; i < n; i++) {
		for(j = 0; j < m; j++)
			scanf("%c",&a[i][j]);
		scanf("\n");
	}

	for(i = 0; i < m; i++)
		for(j = 0; j < n; j++)
			if(a[j][i] == '#')
				b[i]++;

	for(i = 0; i < 2000; i++)
		c[i][0] = c[i][1] = 1e9;

	c[0][0] = c[0][1] = 0;
	for(i = 1; i < mn; i++)
		c[i][0] = c[i][1] = 1e9;

	for(i = mn ; i <= m; i++) {
		lli tmpw = 0;
		lli tmpb = 0;
		for(j = 0; j < mn; j++) {
			tmpw += n - b[i - j - 1];
			tmpb += b[i - j - 1];
		}

		for(; j <= mx && i - j >= 0; j++) {
			c[i][0] = min(tmpw + c[i - j][1], c[i][0]);
			c[i][1] = min(tmpb + c[i - j][0], c[i][1]);
			tmpw += n - b[i - j - 1];
			tmpb += b[i - j - 1];
		}
	}

	printf("%lld\n",min(c[m][0],c[m][1]));

	return 0;
}


#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <memory.h>
#include <map>
using namespace std;

typedef long long lli;
typedef pair<int,int> pii;
typedef unsigned long long llu;
typedef vector<int> vi;
typedef vector<pii> vpi;

int n,m;
int mn,mx;
char a[1001][1001] = {0};

int b[1001] = {0};

lli c[2000][2] = {0};

int main() {
	scanf("%d%d%d%d\n",&n,&m,&mn,&mx);
	int i,j;
	for(i = 0; i < n; i++) {
		for(j = 0; j < m; j++)
			scanf("%c",&a[i][j]);
		scanf("\n");
	}

	for(i = 0; i < m; i++)
		for(j = 0; j < n; j++)
			if(a[j][i] == '#')
				b[i]++;

	for(i = 0; i < 2000; i++)
		c[i][0] = c[i][1] = 1e9;

	c[0][0] = c[0][1] = 0;
	for(i = 1; i < mn; i++)
		c[i][0] = c[i][1] = 1e9;

	for(i = mn ; i <= m; i++) {
		int tmpw = 0;
		int tmpb = 0;
		for(j = 0; j < mn; j++) {
			tmpw += n - b[i - j - 1];
			tmpb += b[i - j - 1];
		}

		for(; j <= mx; j++) {
			c[i][0] = min(tmpw + c[i - j][1], c[i][0]);
			c[i][1] = min(tmpb + c[i - j][0], c[i][1]);
			tmpw += n - b[i - j - 1];
			tmpb += b[i - j - 1];
		}
	}

	printf("%d\n",min(c[m][0],c[m][1]));

	return 0;
}


#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <memory.h>
#include <map>
using namespace std;

typedef long long lli;
typedef pair<int,int> pii;
typedef unsigned long long llu;
typedef vector<int> vi;
typedef vector<pii> vpi;

int n,m;
int mn,mx;
char a[1001][1001] = {0};

int b[1001] = {0};

lli c[2000][2] = {0};

int main() {
	scanf("%d%d%d%d\n",&n,&m,&mn,&mx);
	int i,j;
	for(i = 0; i < n; i++) {
		for(j = 0; j < m; j++)
			scanf("%c",&a[i][j]);
		scanf("\n");
	}

	for(i = 0; i < m; i++)
		for(j = 0; j < n; j++)
			if(a[j][i] == '#')
				b[i]++;

	for(i = 0; i < 2000; i++)
		c[i][0] = c[i][1] = 1e9;

	c[0][0] = c[0][1] = 0;
	for(i = 1; i < mn; i++)
		c[i][0] = c[i][1] = 1e9;

	for(i = mn ; i <= m; i++) {
		lli tmpw = 0;
		lli tmpb = 0;
		for(j = 0; j < mn; j++) {
			tmpw += n - b[i - j - 1];
			tmpb += b[i - j - 1];
		}

		for(; j <= mx; j++) {
			c[i][0] = min(tmpw + c[i - j][1], c[i][0]);
			c[i][1] = min(tmpb + c[i - j][0], c[i][1]);
			tmpw += n - b[i - j - 1];
			tmpb += b[i - j - 1];
		}
	}

	printf("%lld\n",min(c[m][0],c[m][1]));

	return 0;
}


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

#define MP make_pair
#define VI vector<int>
#define INF 1 << 30
#define PI 3.14159265358979
#define LL long long
#define PII pair<int,int>
using namespace std;

#pragma warning(disable:4996)

int n, m, x, y;
char szMap[1010][1010];
int nSB[1010], nSW[1010];
int num[2][1010];

int main()
{
#if _MSC_VER == 1500
	freopen("in.txt", "r", stdin);
#endif
	scanf("%d%d%d%d", &n, &m, &x, &y);
	for(int i = 1; i <= n; ++ i)
		scanf("%s", szMap[i] + 1);
	for(int j = 1; j <= m; ++ j)
	{
		int b = 0;
		for(int i = 1; i <= n; ++ i)
			if(szMap[i][j] == '#')
				b ++;
		nSB[j] = nSB[j - 1] + n - b;
		nSW[j] = nSW[j - 1] + b;
	}
	num[0][0] = num[1][0] = 0;
	for(int i = 1; i <= m; ++ i)
	{
		num[1][i] = num[0][i] = INF;
		for(int k = i - y; k <= i - x; ++ k)
		{
			if(k >= 0 && k < n)
			{
				num[0][i] = min(num[0][i], num[1][k] + nSB[i] - nSB[k]);
				num[1][i] = min(num[1][i], num[0][k] + nSW[i] - nSW[k]);
				//printf("%d %d\n", num[1][i], i);
			}
		}
	}
	printf("%d\n", min(num[0][m], num[1][m]));
	return 0;
}


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

#define MP make_pair
#define VI vector<int>
#define INF 1 << 30
#define PI 3.14159265358979
#define LL long long
#define PII pair<int,int>
using namespace std;

#pragma warning(disable:4996)

int n, m, x, y;
char szMap[1010][1010];
int nSB[1010], nSW[1010];
int num[2][1010];

int main()
{
#if _MSC_VER == 1500
	freopen("in.txt", "r", stdin);
#endif
	scanf("%d%d%d%d", &n, &m, &x, &y);
	for(int i = 1; i <= n; ++ i)
		scanf("%s", szMap[i] + 1);
	for(int j = 1; j <= m; ++ j)
	{
		int b = 0;
		for(int i = 1; i <= n; ++ i)
			if(szMap[i][j] == '#')
				b ++;
		nSB[j] = nSB[j - 1] + n - b;
		nSW[j] = nSW[j - 1] + b;
	}
	num[0][0] = num[1][0] = 0;
	for(int i = 1; i <= m; ++ i)
	{
		num[1][i] = num[0][i] = INF;
		for(int k = i - y; k <= i - x; ++ k)
		{
			if(k >= 0 && k < m)
			{
				num[0][i] = min(num[0][i], num[1][k] + nSB[i] - nSB[k]);
				num[1][i] = min(num[1][i], num[0][k] + nSW[i] - nSW[k]);
				//printf("%d %d\n", num[1][i], i);
			}
		}
	}
	printf("%d\n", min(num[0][m], num[1][m]));
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>

using namespace std;

const int N = 1011;
char a[N][N];
int dp[N][2];
int sum[N];
int ssum[N];

// 0 - '.'; 1 - '#'

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            cin >> a[i][j];

    for(int i = 1; i <= m; ++i)
        for(int j = 1; j <= n; ++j)
            sum[i] += (a[j][i] == '.');

    for(int i = 1; i <= m; ++i)
        ssum[i] = ssum[i-1] + sum[i];

    for(int i = 1; i <= m; ++i)
    {
        if(i >= x && i <= y)
        {
            dp[i][1] = ssum[i];
            dp[i][0] = (i * n) - ssum[i];
        }
        else
        {
            dp[i][1] = 1000000000;
            dp[i][0] = 1000000000;
        }
        for(int j = 1; j <= i; ++j)
        {
            if(i-j >= x && i - j <= y)
                dp[i][0] = min(dp[i][0], dp[j][1] + (i-j)*n-ssum[i]+ssum[j]);
            if(i-j >= x && i - j <= y)
                dp[i][1] = min(dp[i][1], dp[j][0] + ssum[i]-ssum[j]);
        }
    }
    cout << min(dp[m][0], dp[m][1]);

}
/*
2 2 1 1
##
..
*/


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>

using namespace std;

const int N = 1011;
char a[N][N];
int dp[N][2];
int sum[N];
int ssum[N];

// 0 - '.'; 1 - '#'

int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			cin >> a[i][j];

	for(int i = 1; i <= m; ++i)
		for(int j = 1; j <= n; ++j)
			sum[i] += (a[j][i] == '.');

	for(int i = 1; i <= m; ++i)
		ssum[i] = ssum[i-1] + sum[i];

	for(int i = 1; i <= n; ++i)
	{
		if(i >= x && i <= y)
		{
			dp[i][1] = ssum[i];
			dp[i][0] = (i * n) - ssum[i];
		}
		else
		{
			dp[i][1] = 1000000000;
			dp[i][0] = 1000000000;
		}
		for(int j = 1; j <= i; ++j)
		{
			if(i-j >= x && i - j <= y)
				dp[i][0] = min(dp[i][0], dp[j][1] + (i-j)*n-ssum[i]+ssum[j]);
			if(i-j >= x && i - j <= y)
				dp[i][1] = min(dp[i][1], dp[j][0] + ssum[i]-ssum[j]);
		}
	}
	cout << min(dp[m][0], dp[m][1]);

}
/*
2 2 1 1
##
..
*/


#include<stdio.h>

void part(int x[],int y[],int min,int mid,int max,int  n){
    int i,j,k,l;
    int tmp[n],tmp1[n];
    i=min;
    j=mid+1;
    for(k=min;i<=mid&&j<=max;k++){
        if(x[i]>x[j]){
            tmp[k]=x[j];
            tmp1[k]=y[j];
            j++;
        }
        else{
            tmp[k]=x[i];
            tmp1[k]=y[i];
            i++;
        }
    }
    for(l=i;l<=mid;l++){
        tmp[k]=x[l];
        tmp1[k]=y[l];
        k++;
    }
    for(l=j;l<=max;l++){
        tmp[k]=x[l];
        tmp1[k]=y[l];
        k++;
    }
    for(i=min;i<=max;i++)
    {
        x[i]=tmp[i];
        y[i]=tmp1[i];
    }
}
void sort(int x[],int y[],int min,int max,int n){
    int mid;
    mid=(min+max)/2;
    if(min<max){
        sort(x,y,min,mid,n);
        sort(x,y,mid+1,max,n);
        part(x,y,min,mid,max,n);
    }
}
int main(){
    int n,k,i,c,min,max;
    scanf("%d%d",&n,&k);
    int x[n],y[n],a[k],b[k];
    for(i=0;i<n;i++){
        scanf("%d",&x[i]);
        y[i]=i+1;
    }
    sort(x,y,0,n-1,n);
/*  for(i=0;i<n;i++){
        printf("%d %d\n",x[i],y[i]);

    }
    */
    min=x[0];
    max=x[n-1];
    c=0;
    while(min!=max&&c<k){
        x[0]++;
        x[n-1]--;
        a[c]=y[0];
        b[c]=y[n-1];
        c++;
        sort(x,y,0,n-1,n);
        min=x[0];
        max=x[n-1];
    }
    printf("%d %d\n",x[n-1]-x[0],c);
    for(i=0;i<c;i++){
        printf("%d %d\n",b[i],a[i]);
    }

    return 0;
}


#include<stdio.h>

void part(int x[],int y[],int min,int mid,int max,int  n){
    int i,j,k,l;
    int tmp[n],tmp1[n];
    i=min;
    j=mid+1;
    for(k=min;i<=mid&&j<=max;k++){
        if(x[i]>x[j]){
            tmp[k]=x[j];
            tmp1[k]=y[j];
            j++;
        }
        else{
            tmp[k]=x[i];
            tmp1[k]=y[i];
            i++;
        }
    }
    for(l=i;l<=mid;l++){
        tmp[k]=x[l];
        tmp1[k]=y[l];
        k++;
    }
    for(l=j;l<=max;l++){
        tmp[k]=x[l];
        tmp1[k]=y[l];
        k++;
    }
    for(i=min;i<=max;i++)
    {
        x[i]=tmp[i];
        y[i]=tmp1[i];
    }
}
void sort(int x[],int y[],int min,int max,int n){
    int mid;
    mid=(min+max)/2;
    if(min<max){
        sort(x,y,min,mid,n);
        sort(x,y,mid+1,max,n);
        part(x,y,min,mid,max,n);
    }
}
int main(){
    int n,k,i,c,min,max;
    scanf("%d%d",&n,&k);
    int x[n],y[n],a[n],b[n];
    for(i=0;i<n;i++){
        scanf("%d",&x[i]);
        y[i]=i+1;
    }
    sort(x,y,0,n-1,n);
/*  for(i=0;i<n;i++){
        //printf("%d %d\n",x[i],y[i]);

    }*/
    min=x[0];
    max=x[n-1];
    c=0;
    while(min!=max&&c<k){
        x[0]++;
        x[n-1]--;
        a[c]=y[0];
        b[c]=y[n-1];
        c++;
        sort(x,y,0,n-1,n);
        min=x[0];
        max=x[n-1];
    }
    printf("%d %d\n",x[n-1]-x[0],c);
    for(i=0;i<c;i++){
        printf("%d %d\n",b[i],a[i]);
    }
    return 0;
}


#include<stdio.h>
typedef unsigned long long int ll;
ll a[100];
int n;
int isempty(const ll *a){
	int i;
	for(i=0;i<n;i++){
		if(a[i]!=max(a)&&a[i]!=min(a))
		   return 1;
	}
	return 0;
}
int max(const ll *a){
	int i,max=0;
	for(i=0;i<n;i++){
		if(a[i]>a[max])
		    max=i;
	}
	return max;
}
int min(const ll *a){
	int i,min=0;
	for(i=0;i<n;i++){
		if(a[i]<a[min])
		    min=i;
	}
	return min;
}
int main(void){
	int k,i,j,min2,sum,x,y,z;
	scanf("%d%d",&n,&k);
    for(x=0;x<n;x++)
        scanf("%ld",&a[x]);
    int b[k],c[k];
    for(y=0;y<k;y++){
    	if(a[max(a)]-a[min(a)]==0||(isempty(a)&&a[max(a)]-a[min(a)]==1))
    	    break;
    	b[y]=max(a);
    	c[y]=min(a);
    	a[max(a)]--;
    	a[min(a)]++;
    }
	printf("%d %d\n",a[max(a)]-a[min(a)],y);
	for(i=0;i<y;i++){
		printf("%d %d\n",b[i]+1,c[i]+1);
	}
    return 0;
}


#include<stdio.h>
typedef unsigned long long int ll;
ll a[100];
int n;
int isempty(const ll *a){
	int i;
	for(i=0;i<n;i++){
		if(a[i]!=max(a)&&a[i]!=min(a))
		   return 1;
	}
	return 0;
}
int max(const ll *a){
	int i,max=0;
	for(i=0;i<n;i++){
		if(a[i]>a[max])
		    max=i;
	}
	return max;
}
int min(const ll *a){
	int i,min=0;
	for(i=0;i<n;i++){
		if(a[i]<a[min])
		    min=i;
	}
	return min;
}
int main(void){
	int k,i,x,y;
	scanf("%d%d",&n,&k);
    for(x=0;x<n;x++)
        scanf("%ld",&a[x]);
    int b[k],c[k];
    for(y=0;y<k;y++){
    	if(a[max(a)]-a[min(a)]==0||(isempty(a)&&a[max(a)]-a[min(a)]==1))
    	    break;
    	b[y]=max(a);
    	c[y]=min(a);
    	a[max(a)]--;
    	a[min(a)]++;
    }
	printf("%d %d ",a[max(a)]-a[min(a)],y);
	for(i=0;i<y;i++){
		printf("\n");
		printf("%d %d ",b[i]+1,c[i]+1);
	}
    return 0;
}


#include<stdio.h>
typedef unsigned long long int ll;
ll a[100];
int n;
int isempty(const ll *a){
	int i;
	for(i=0;i<n;i++){
		if(a[i]!=max(a)&&a[i]!=min(a))
		   return 1;
	}
	return 0;
}
int max(const ll *a){
	int i,max=0;
	for(i=0;i<n;i++){
		if(a[i]>a[max])
		    max=i;
	}
	return max;
}
int min(const ll *a){
	int i,min=0;
	for(i=0;i<n;i++){
		if(a[i]<a[min])
		    min=i;
	}
	return min;
}
int main(void){
	int k,i,x,y;
	scanf("%d%d",&n,&k);
    for(x=0;x<n;x++)
        scanf("%ld",&a[x]);
    int b[k],c[k];
    for(y=0;y<k;y++){
    	if(a[max(a)]-a[min(a)]==0||(isempty(a)&&a[max(a)]-a[min(a)]==1))
    	    break;
    	b[y]=max(a);
    	c[y]=min(a);
    	a[max(a)]--;
    	a[min(a)]++;
    }
	printf("%d %d",a[max(a)]-a[min(a)],y);
	for(i=0;i<y;i++){
		printf("\n");
		printf("%d %d",b[i]+1,c[i]+1);
	}
    return 0;
}


#include<stdio.h>
int a[100];
int n;
int isempty(const int *a){
	int i;
	for(i=0;i<n;i++){
		if(a[i]!=max(a)&&a[i]!=min(a))
		   return 1;
	}
	return 0;
}
int max(const int *a){
	int i,max=0;
	for(i=0;i<n;i++){
		if(a[i]>a[max])
		    max=i;
	}
	return max;
}
int min(const int *a){
	int i,min=0;
	for(i=0;i<n;i++){
		if(a[i]<a[min])
		    min=i;
	}
	return min;
}
int main(void){
	int k,i,x,y;
	scanf("%d%d",&n,&k);
    for(x=0;x<n;x++)
        scanf("%d",&a[x]);
    int b[k],c[k];
    for(y=0;y<k;y++){
    	if(a[max(a)]-a[min(a)]==0||(isempty(a)&&a[max(a)]-a[min(a)]==1))
    	    break;
    	b[y]=max(a);
    	c[y]=min(a);
    	a[max(a)]--;
    	a[min(a)]++;
    }
	printf("%d %d",a[max(a)]-a[min(a)],y);
	for(i=0;i<y;i++){
		printf("\n");
		printf("%d %d ",b[i]+1,c[i]+1);
	}
    return 0;
}


#include<stdio.h>
typedef unsigned long long int ll;
ll a[100];
int n;
int isempty(const ll *a){
	int i;
	for(i=0;i<n;i++){
		if(a[i]!=max(a)&&a[i]!=min(a))
		   return 1;
	}
	return 0;
}
int max(const ll *a){
	int i,max=0;
	for(i=0;i<n;i++){
		if(a[i]>a[max])
		    max=i;
	}
	return max;
}
int min(const ll *a){
	int i,min=0;
	for(i=0;i<n;i++){
		if(a[i]<a[min])
		    min=i;
	}
	return min;
}
int main(void){
	int k,i,j,min2,sum,x,y,z;
	scanf("%d%d",&n,&k);
    for(x=0;x<n;x++)
        scanf("%ld",&a[x]);
    int b[k],c[k];
    for(y=0;y<k;y++){
    	if(a[max(a)]-a[min(a)]==0||(isempty(a)&&a[max(a)]-a[min(a)]==1))
    	    break;
    	b[y]=max(a);
    	c[y]=min(a);
    	a[max(a)]--;
    	a[min(a)]++;
    }
	printf("%d %d \n",a[max(a)]-a[min(a)],y);
	for(i=0;i<y;i++){
		printf("%d %d \n",b[i]+1,c[i]+1);
	}
    return 0;
}


#include<stdio.h>
typedef unsigned long long int ll;
ll a[100];
int n;
int isempty(const ll *a){
	int i;
	for(i=0;i<n;i++){
		if(a[i]!=max(a)&&a[i]!=min(a))
		   return 1;
	}
	return 0;
}
int max(const ll *a){
	int i,max=0;
	for(i=0;i<n;i++){
		if(a[i]>a[max])
		    max=i;
	}
	return max;
}
int min(const ll *a){
	int i,min=0;
	for(i=0;i<n;i++){
		if(a[i]<a[min])
		    min=i;
	}
	return min;
}
int main(void){
	int k,i,x,y;
	scanf("%d%d",&n,&k);
    for(x=0;x<n;x++)
        scanf("%ld",&a[x]);
    int b[k],c[k];
    for(y=0;y<k;y++){
    	if(a[max(a)]-a[min(a)]==0||(isempty(a)&&a[max(a)]-a[min(a)]==1))
    	    break;
    	b[y]=max(a);
    	c[y]=min(a);
    	a[max(a)]--;
    	a[min(a)]++;
    }
	printf("%d %d",a[max(a)]-a[min(a)],y);
	for(i=0;i<y;i++){
		printf("\n");
		printf("%d %d ",b[i]+1,c[i]+1);
	}
    return 0;
}


#include <stdio.h>

int main()
{
    int i, j, n, k, t, tt, sum=0, result, count=0;
    int a[10001]={0};
    int b[10001]={0};
    int c[10001]={0};

    scanf("%d %d", &n, &k);
    for(i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
    }

    int max=0, min=10000;

for(j=1; j<=k; j++)
{
    for(i=1; i<=n; i++)
    {
        if(a[i] >=max)
        {
            max = a[i];
            t = i;
        }
    }

    for(i=1; i<=n; i++)
    {
        if(a[i] <= min)
        {
            min = a[i];
            tt = i;
        }
    }

    result = max - min;

    if(result <= 1) break;

    count++;
    a[t] = a[t]-1;
    a[tt] = a[tt]+1;
    b[j]=t; c[j]=tt;
    if(j==k) break;
    max = 0;    min = 10000;
}
    result = max - min;
    printf("\n%d %d\n", result, count);

    for(i=1; i<=count; i++)
        printf("%d %d\n", b[i], c[i]);

    //system("PAUSE");

return 0;
}


#include <stdio.h>

int main()
{
    int i, j, n, k, t, tt, sum=0, result, count=0;
    int a[10001]={0};
    int b[10001]={0};
    int c[10001]={0};

    scanf("%d %d", &n, &k);
    for(i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
    }

    int max, min;

for(j=1; j<=k; j++)
{   max = 0; min = 10000;
    for(i=1; i<=n; i++)
    {
        if(a[i] >=max)
        {
            max = a[i];
            t = i;
        }
    }

    for(i=1; i<=n; i++)
    {
        if(a[i] <= min)
        {
            min = a[i];
            tt = i;
        }
    }

    result = max - min;

    if(result <= 1)     break;
    count++;
    a[t] = a[t]-1;
    a[tt] = a[tt]+1;
    b[j]=t; c[j]=tt;
}

max = 0; min = 10000;

    for(i=1; i<=n; i++)
    {
        if(a[i] >=max)
        {
            max = a[i];
        }
    }

    for(i=1; i<=n; i++)
    {
        if(a[i] <= min)
        {
            min = a[i];
        }
    }

    result = max - min;
    printf("\n%d %d\n", result, count);

    for(i=1; i<=count; i++)
        printf("%d %d\n", b[i], c[i]);

    system("PAUSE");

return 0;
}


#include <stdio.h>

int main()
{
    int i, j, n, k, t, tt, sum=0, result, count=0;
    int a[10001]={0};
    int b[10001]={0};
    int c[10001]={0};

    scanf("%d %d", &n, &k);
    for(i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
    }

    int max=0, min=10000;

for(j=1; j<=k; j++)
{
    for(i=1; i<=n; i++)
    {
        if(a[i] >=max)
        {
            max = a[i];
            t = i;
        }
    }

    for(i=1; i<=n; i++)
    {
        if(a[i] <= min)
        {
            min = a[i];
            tt = i;
        }
    }

    result = max - min;

    if(result <= 1) break;

    count++;
    a[t] = a[t]-1;
    a[tt] = a[tt]+1;
    b[j]=t; c[j]=tt;
    max = 0;    min = 10000;
}
    result = a[t] - a[tt];

    printf("\n%d %d\n", result, count);

    for(i=1; i<=count; i++)
        printf("%d %d\n", b[i], c[i]);

//    system("PAUSE");

return 0;
}


#include <stdio.h>

int main()
{
    int i, j, n, k, t, tt, sum=0, result, count=0;
    int a[10001]={0};
    int b[10001]={0};
    int c[10001]={0};

    scanf("%d %d", &n, &k);
    for(i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
    }

    int max=0, min=10000;

for(j=1; j<=k; j++)
{
    for(i=1; i<=n; i++)
    {
        if(a[i] >=max)
        {
            max = a[i];
            t = i;
        }
    }

    for(i=1; i<=n; i++)
    {
        if(a[i] <= min)
        {
            min = a[i];
            tt = i;
        }
    }

    result = max - min;
    if(result <= 1) break;

    count++;
    a[t]--;
    a[tt]++;
    b[j]=t; c[j]=tt;
    max = 0;    min = 10000;
}
    printf("\n%d %d\n", result, count);

    for(i=1; i<=count; i++)
        printf("%d %d\n", b[i], c[i]);

//    system("PAUSE");

return 0;
}


#include <stdio.h>

int main()
{
    int i, j, n, k, t, tt, sum=0, result, count=0;
    int a[10001]={0};
    int b[10001]={0};
    int c[10001]={0};

    scanf("%d %d", &n, &k);
    for(i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
    }

    int max, min;

for(j=1; j<=k; j++)
{   max = 0; min = 10000;
    for(i=1; i<=n; i++)
    {
        if(a[i] >=max)
        {
            max = a[i];
            t = i;
        }
    }

    for(i=1; i<=n; i++)
    {
        if(a[i] <= min)
        {
            min = a[i];
            tt = i;
        }
    }

    result = max - min;

    if(result <= 1)     break;
    count++;
    a[t] = a[t]-1;
    a[tt] = a[tt]+1;
    b[j]=t; c[j]=tt;
}

max = 0; min = 10000;

    for(i=1; i<=n; i++)
    {
        if(a[i] >=max)
        {
            max = a[i];
        }
    }

    for(i=1; i<=n; i++)
    {
        if(a[i] <= min)
        {
            min = a[i];
        }
    }

    result = max - min;
    printf("\n%d %d\n", result, count);

    for(i=1; i<=count; i++)
        printf("%d %d\n", b[i], c[i]);

    //system("PAUSE");

return 0;
}


#include<stdio.h>
#include<math.h>

int a[10000],q,w;
int max()
{
    int z=a[0],ret=0,i;
    for(i=1;i<w;i++)
    {
        if(a[i]>z)
        {
            z=a[i];
            ret=i;
        }
    }
    return ret;
}
int min()
{
    int z=a[0],ret=0,i;
    for(i=1;i<w;i++)
    {
        if(a[i]<z)
        {
            z=a[i];
            ret=i;
        }
    }
    return ret;
}

int main()
{
    int i;
    scanf("%d%d",&w,&q);
    for(i=0;i<w;i++)
        scanf("%d",&a[i]);
    int z[10000],zp=0;
    int M=max();
    int m=min();
    int d=a[M]-a[m];
    if(d==1 || d==0)
    {
        printf("%d 0\n",d);
        return 0;
    }
    int ite=0;
    for(ite=0;ite<q;ite++)
    {
        M=max();
        m=min();
        d=a[M]-a[m];
        if(d<2)
            break;
        a[M]--;
        a[m]++;
        z[zp++]=M;
        z[zp++]=m;
    }
        M=max();
        m=min();
        d=a[M]-a[m];

    printf("%d %d\n",d,zp/2);
    for(i=0;i<zp;i+=2)
    {
        printf("%d %d\n",z[i]+1,z[i+1]+1);
    }
    return 0;
}


// Towers.c
#include <stdio.h>

#define MAXN 100
#define MAXK 1000

int n, k;
int a [MAXN+1];
int p [MAXN+1];
int m;
int u [MAXK+1];
int v [MAXK+1];

void swap (int *a,int *b) {
	int t = *a;
	*a = *b;
	*b = t;
}

void input (void) {
	scanf( "%d%d", &n, &k );
	int i;
	for (i=1; i<=n; i++) {
		scanf( "%d", &a[i] );
		p[i] = i;
	}
}

void bubble_sort (void) {
	int i, j;
	for (i=n; i>1; i--)
		for (j=i-1; j>=1; j--)
			if (a[p[j]]>a[p[i]])
				swap( &p[i], &p[j] );
}

void output (void) {
	bubble_sort();
	int i;
	int m = 0;
	while (k-->0) {
		if (a[p[n]]-a[p[1]]<=1)
			break;
		a[p[1]]++;
		a[p[n]]--;
		m++;
		u[m] = p[n];
		v[m] = p[1];
		i = 1;
		while (a[p[i]]>a[p[i+1]]) {
			swap( &p[i], &p[i+1] );
			i++;
		}
		i = n;
		while (a[p[i]]<a[p[i-1]]) {
			swap( &p[i], &p[i-1] );
			i--;
		}
	}
	int s = a[p[n]]-a[p[1]];
	printf( "%d %d\n", s, m );
	for (i=1; i<=m; i++)
		printf( "%d %d\n", u[i], v[i] );
}

int main (void) {
	input();
	output();
	return 0;
}


#include<stdio.h>
#include<string.h>
int a[110],max,min,mink,maxk,b[110],n;
int d()
{
	int flag=0,i;
    max=min=a[1];
	for(i=2;i<=n;i++)
	{
		if(a[i]>max)
		max=a[i];
		if(a[i]<min)
		min=a[i];
	}
	if((max-min==0)||(max-min==1))
	flag=1;
	return flag;
}
int cmp()
{
	int i;
    max=min=a[1];
    mink=maxk=1;
	for(i=2;i<=n;i++)
	{
		if(a[i]>max)
		{
			max=a[i];
			maxk=i;
		}
		if(a[i]<min)
		{
			min=a[i];
			mink=i;
		}
	}
}
int cmp1()
{
	int i;
    max=min=b[1];
	mink=maxk=1;
	for(i=2;i<=n;i++)
	{
		if(b[i]>max)
		{
			max=b[i];
			maxk=i;
		}
		if(b[i]<min)
		{
			min=b[i];
			mink=i;
		}
	}
}
int main()
{
   int k,i,j,count;
   while(scanf("%d%d",&n,&k)!=EOF)
   {
      count=0;
      memset(a,0,sizeof(a));
      memset(b,0,sizeof(b));
   	  for(i=1;i<=n;i++)
   	  {
   	    scanf("%d",&a[i]);
   	    b[i]=a[i];
   	  }
   	  for(j=0;j<k;j++)
   	  {
   	  	if((d()==1)||(count==k))
   	  	break;
   	  	cmp();
   	  	a[maxk]--;
   	  	a[mink]++;
   	  	count=count+1;
   	  }
   	  cmp();
   	  printf("%d %d\n",max-min,count);
   	  for(j=0;j<count;j++)
   	  {
   	  	cmp1();
   	  	printf("%d %d\n",maxk,mink);
   	  	b[maxk]--;
   	  	b[mink]++;
   	  }
   }
   return 0;
}


#include<stdio.h>
#include<string.h>
int a[110],max,min,mink,maxk,b[110],n;
int d()
{
	int flag=0,i;
    max=min=a[1];
	for(i=2;i<=n;i++)
	{
		if(a[i]>max)
		max=a[i];
		if(a[i]<min)
		min=a[i];
	}
	if((max-min==0)||(max-min==1))
	flag=1;
	return flag;
}
int cmp()
{
	int i;
    max=min=a[1];
    mink=maxk=1;
	for(i=2;i<=n;i++)
	{
		if(a[i]>max)
		{
			max=a[i];
			maxk=i;
		}
		if(a[i]<min)
		{
			min=a[i];
			mink=i;
		}
	}
}
int cmp1()
{
	int i;
    max=min=b[1];
	mink=maxk=1;
	for(i=2;i<=n;i++)
	{
		if(b[i]>max)
		{
			max=b[i];
			maxk=i;
		}
		if(b[i]<min)
		{
			min=b[i];
			mink=i;
		}
	}
}
int main()
{
   int k,i,j,count;
   while(scanf("%d%d",&n,&k)!=EOF)
   {
      count=0;
      memset(a,0,sizeof(a));
      memset(b,0,sizeof(b));
   	  for(i=1;i<=n;i++)
   	  {
   	    scanf("%d",&a[i]);
   	    b[i]=a[i];
   	  }
   	  for(j=0;j<k;j++)
   	  {
   	  	if((d()==1)||(count==k))
   	  	break;
   	  	cmp();
   	  	a[maxk]--;
   	  	a[mink]++;
   	  	count=count+1;

   	  }
   	  printf("%d %d\n",max-min,count);
   	  for(j=0;j<count;j++)
   	  {
   	  	cmp1();
   	  	printf("%d %d\n",maxk,mink);
   	  	b[maxk]--;
   	  	b[mink]++;
   	  }
   }
   return 0;
}


#include<stdio.h>
#include<string.h>
int a[110],max,min,mink,maxk,b[110],n;
int d()
{
	int flag=0,i;
    max=min=a[1];
	for(i=2;i<=n;i++)
	{
		if(a[i]>max)
		max=a[i];
		if(a[i]<min)
		min=a[i];
	}
	if((max-min==0)||(max-min==1))
	flag=1;
	return flag;
}
int cmp()
{
	int i;
    max=min=a[1];
    mink=maxk=1;
	for(i=2;i<=n;i++)
	{
		if(a[i]>max)
		{
			max=a[i];
			maxk=i;
		}
		if(a[i]<min)
		{
			min=a[i];
			mink=i;
		}
	}
}
int cmp1()
{
	int i;
    max=min=b[1];
	mink=maxk=1;
	for(i=2;i<=n;i++)
	{
		if(b[i]>max)
		{
			max=b[i];
			maxk=i;
		}
		if(b[i]<min)
		{
			min=b[i];
			mink=i;
		}
	}
}
int main()
{
   int k,i,j,count;
   while(scanf("%d%d",&n,&k)!=EOF)
   {
      count=0;
      memset(a,0,sizeof(a));
      memset(b,0,sizeof(b));
   	  for(i=1;i<=n;i++)
   	  {
   	    scanf("%d",&a[i]);
   	    b[i]=a[i];
   	  }
   	  for(j=0;j<k;j++)
   	  {
   	  	cmp();
   	  	a[maxk]--;
   	  	a[mink]++;
   	  	count=count+1;
   	  	if((d()==1)||(count==k))
   	  	break;
   	  }
   	  printf("%d %d\n",max-min,count);
   	  for(j=0;j<count;j++)
   	  {
   	  	cmp1();
   	  	printf("%d %d\n",maxk,mink);
   	  	b[maxk]--;
   	  	b[mink]++;
   	  }
   }
   return 0;
}


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

int Max(a, b)
{
    return ((a >= b) ? (a) : (b));
}

int main()
{
    int n, k, i, mx = 0, mn = 100000, count = 0, cur_mx, cur_mn;
    scanf("%d%d", &n, &k);
    int a[n], ans[k][2];
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        if (a[i] < mn){
            mn = a[i];
            cur_mn = i;
        }
        if (a[i] > mx){
            mx = a[i];
            cur_mx = i;
        }
    }

    while (count < k && (mx - mn) > 0)
    {
        cur_mx = 0;
        cur_mn = 0;
        for (i = 0; i < n; i++)
        {
            if (a[i] < a[cur_mn])
                cur_mn = i;
            if (a[i] > a[cur_mx])
                cur_mx = i;
        }
        a[cur_mx]--;
        a[cur_mn]++;

        ans[count][1] = cur_mx;
        ans[count][2] = cur_mn;
        count++;

        mx = 0;
        mn = 100000;
        for (i = 0; i < n; i++)
        {
            if (a[i] < mn)
                mn = a[i];
            if (a[i] > mx)
                mx = a[i];
        }
    }

    printf("%d %d\n", mx - mn, count);
    for (i = 0; i < count; i++)
    {
        printf("%d %d\n", ans[i][1] + 1, ans[i][2] + 1);
    }
    return 0;
}