#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6 + 5;
char s[maxn];
int sum[maxn];
int k[maxn];
vector<int> D;
vector<int> C;
int n;
ll slove(int k) {
    if (C.empty() || D.empty())
        return 0;
    ll ans=0;
    int j = 0;
    queue<int> q;
    int a, b;
    ll temp=0;
    for (int i = 0; i < D.size(); i++) {
        //将所有C的贡献调整
        if(i>0)
            temp-=(ll)q.size()*(sum[D[i]]-sum[D[i-1]]);
        //将跳过的C贡献调整
        if(!q.empty()) {
            int ft=q.front();
            while(ft<=D[i]) {
                temp+=sum[D[i]]-sum[D[i-1]];
                temp-=sum[ft]-sum[D[i-1]];
                q.pop();
                if(q.empty())
                    break;
                ft=q.front();
            }
        }
        //将无用的C排除
        while(j < C.size() &&C[j]<D[i]){
            j++;
        }
        //增加新的C
        while (j < C.size() && C[j] - D[i] < k) {
            q.push(C[j]);
            temp+=sum[C[j]]-sum[D[i]];
            j++;
        }
        ans+=temp;
    }
    return ans;
}
int main() {
    scanf("%d", &n);
    scanf("%s", s + 1);
    int q;
    scanf("%d", &q);
    for (int i = 1; i <= q; i++)
        scanf("%d", &k[i]);
    for (int i = 1; i <= n; i++) {
        if (s[i] == 'D')
            D.push_back(i);
        if (s[i] == 'C')
            C.push_back(i);
        if (s[i] == 'M')
            sum[i] = sum[i - 1] + 1;
        else
            sum[i] = sum[i - 1];
    }
//    cout<<"D";
//    for(auto x:D)cout<<x<<" ";cout<<endl;
//    cout<<"C";
//    for(auto x:C)cout<<x<<" ";cout<<endl;
    for (int i = 1; i <= q; i++) {
        printf("%lld\n", slove(k[i]));
    }
}

#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
#define all(x) begin((x)), end((x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}

vector<ll> a;
ll n,m,v,p;
bool chk(int idx) {
    if (a[idx]+m<a[n-p]) {
        return false;
    }
    ll cnt = 0;
    rep(i,n) {
        if (i>n-p||i<=idx) {
            cnt += m;
        }
        else {
            cnt += max(0LL, a[idx]+m-a[i]);
        }
    }
    return cnt >= m*v;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m>>v>>p;
    a.assign(n,0);
    rep(i,n) cin>>a[i];
    sort(all(a));
    ll l=0,r=n-1;
    while(r>l) {
        ll mid = (l+r)/2;
        if (chk(mid)) {
            r = mid;
        } else {
            l = mid;
        }
        if (l+1==r) {
            if (chk(l)) {
                r = l;
            } else {
                l = r;
            }
        }
    }
    cout << n-l << endl;
    return 0;
}
