#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const int MAX = 200000, SENTINEL = 2100000000;
int L[MAX / 2 + 2], R[MAX / 2 + 2];

ll merge(int A[], int n, int left, int mid, int right) {
    ll cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

ll msort(int A[], int n, int left, int right) {
    ll res = 0;
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        res += msort(A, n, left, mid);
        res += msort(A, n, mid, right);
        res += merge(A, n, left, mid, right);
    }
    return res;
}


int main(void) {
    int n, A[MAX];

    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];

    cout << msort(A, n, 0, n) << endl;

    return 0;
}
#include <cstdio>
#include <vector>
#include <algorithm>

int main()
{
  int n,v,p;
  long long m;
  scanf("%d%lld%d%d",&n,&m,&v,&p);
  std::vector<long long> A(n);
  for(int i=0;i<n;i++){
    scanf("%lld",&A[i]);
  }
  std::sort(A.begin(),A.end());
  int l=-1,r=n-p;
  while(l+1<r){
    int d=(l+r)/2;
    bool F=true;
    if(A[d]+m<A[n-p]){
      F=false;
    }
    else{
      long long S=0ll;
      for(int i=d+1;i<=n-p;i++){
	S+=A[d]+m-A[i];
      }
      if(S>=std::max(v-p-d,0)*m){
	F=true;
      }
      else{
	F=false;
      }
    }
    if(F){
      r=d;
    }
    else{
      l=d;
    }
  }
  printf("%d\n",n-r);
  return 0;
}
