#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long n, K, m, tot, a[N];
int main() {
  n = read();
  K = read();
  m = read();
  tot = n * K;
  for (long long i = 1; i <= tot; i++) a[i] = read();
  sort(a + 1, a + tot + 1);
  long long r = 1, cnt = 1;
  while (r < tot && a[r + 1] - a[1] <= m) r++;
  if (r < n) {
    puts("0");
    return 0;
  }
  cnt = r - n;
  long long k1 = 0, k2 = 0;
  if (K > 1) k1 = cnt / (K - 1), k2 = cnt % (K - 1);
  long long ans = 0;
  for (long long i = 0; i < k1; i++) {
    ans += a[i * K + 1];
  }
  if (k2) ans += a[k1 * K + 1];
  long long st = k1 * K + k2;
  if (k2)
    st += 2;
  else
    st++;
  for (long long i = st; i <= r; i++) ans += a[i];
  cout << ans << endl;
  return 0;
}
