#include <bits/stdc++.h>
#define int long long
using namespace std;
struct info {
int x, y;
};
int m, n, d, k;
vector<info> market;
vector<info> house;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("KHUDANCU.INP", "r", stdin);
freopen("KHUDANCU.OUT", "w", stdout);
cin >> m >> n >> d >> k;
for (int i = 1; i <= m; i += 1) {
for (int j = 1; j <= n; j += 1) {
char c;
cin >> c;
if (c == 'P') house.push_back({i, j});
if (c == 'M') market.push_back({i, j});
}
}
int res = 0;
for (info a : house) {
int check = 0;
for (info b : market) {
if (abs(a.x - b.x) <= d && abs(a.y - b.y) <= d) {
check += 1;
if (check >= k) {
res += 1;
break;
}
}
}
}
cout << res;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZwoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBpbmZvIHsKICAgIGludCB4LCB5Owp9OwoKaW50IG0sIG4sIGQsIGs7CnZlY3RvcjxpbmZvPiBtYXJrZXQ7CnZlY3RvcjxpbmZvPiBob3VzZTsKCgppbnQzMl90IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CgogICAgZnJlb3BlbigiS0hVREFOQ1UuSU5QIiwgInIiLCBzdGRpbik7CiAgICBmcmVvcGVuKCJLSFVEQU5DVS5PVVQiLCAidyIsIHN0ZG91dCk7CgogICAgY2luID4+IG0gPj4gbiA+PiBkID4+IGs7CgogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbTsgaSArPSAxKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDE7IGogPD0gbjsgaiArPSAxKSB7CiAgICAgICAgICAgIGNoYXIgYzsKICAgICAgICAgICAgY2luID4+IGM7CiAgICAgICAgICAgIGlmIChjID09ICdQJykgaG91c2UucHVzaF9iYWNrKHtpLCBqfSk7CiAgICAgICAgICAgIGlmIChjID09ICdNJykgbWFya2V0LnB1c2hfYmFjayh7aSwgan0pOwogICAgICAgIH0KICAgIH0KCiAgICBpbnQgcmVzID0gMDsKICAgIGZvciAoaW5mbyBhIDogaG91c2UpIHsKICAgICAgICBpbnQgY2hlY2sgPSAwOwoKICAgICAgICBmb3IgKGluZm8gYiA6IG1hcmtldCkgewogICAgICAgICAgICBpZiAoYWJzKGEueCAtIGIueCkgPD0gZCAmJiBhYnMoYS55IC0gYi55KSA8PSBkKSB7CiAgICAgICAgICAgICAgICBjaGVjayArPSAxOwogICAgICAgICAgICAgICAgaWYgKGNoZWNrID49IGspIHsKICAgICAgICAgICAgICAgICAgICByZXMgKz0gMTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBjb3V0IDw8IHJlczsKCiAgICByZXR1cm4gMDsKfQo=