#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, k;
  long long int d, sum = 0;
  cin >> n >> k >> d;
  long long int m = n * k;
  long long int arr[100001];
  for (long int i = 0; i < (m); i++) cin >> arr[i];
  sort(arr, arr + (m));
  if (arr[n - 1] - arr[0] > d)
    cout << 0;
  else {
    long long int sum1 = 0;
    vector<long long int> vec;
    for (int i = 0; i < m; i++) {
      if (arr[i] - arr[0] <= d) {
        vec.push_back(arr[i]);
        sum1 += arr[i];
      } else
        break;
    }
    if (vec.size() == n)
      cout << sum1;
    else {
      long long int ans = 0;
      long long int n1 = m - vec.size();
      long long int n2 = n1 % (k - 1);
      long long int n3 = n1 / (k - 1);
      long int ctr = 0, index;
      for (long int i = vec.size() - 1; i >= 0; i--) {
        if (ctr < n3) {
          ans += vec[i];
          ctr++;
        } else {
          index = i;
          break;
        }
      }
      long long int stop;
      if (n2 != 0) {
        stop = index + 1 - (k - n2);
        ans += vec[index - (k - n2) + 1];
      } else
        stop = index;
      for (long int i = 0; i < stop; i = i + k) ans += vec[i];
      cout << ans;
    }
  }
}
