#include<bits/stdc++.h>
using namespace std;
int n,m,d,k;
vector<pair<int,int>> sprink, mush;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m>>d>>k;
vector<vector<char>> mat(n+1,vector<char>(m+1));
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
cin>>mat[i][j];
if(mat[i][j] == 'S') mush.push_back({j,i});
if(mat[i][j] == 'M') sprink.push_back({j+d,i});
}
}
sort(mush.begin(),mush.end());
sort(sprink.begin(),sprink.end());
int add = 0;
int rem = 0;
set<pair<int,int>> s;
int res = 0;
for(auto [x,y] : sprink)
{
while(add < mush.size() && mush[add].first <= x) s.insert({mush[add].second,mush[add].first}),add++;
while(rem < mush.size() && mush[rem].first < x-2*d) s.erase({mush[rem].second,mush[rem].first}),rem++;
int cnt = 0;
for(auto itr = s.lower_bound({y-d,-1e9}); itr != s.end() && itr->first <= y+d; itr++) cnt++;
if(cnt >= k) res++;
}
cout<<res;
}