#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll n, k, l;
ll a[maxn];
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++) scanf("%lld", &a[i]);
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	ll ans = a[0], cnt = 1;
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(r >= 0 && a[r] > a[0] + l) r--;
	ll i;
	for(ll i = k; i < n * k;)
	{
		if(i + k + n - cnt - 2 > r)
		{

			cnt++;
			ans += a[i];
			i += k;
		}
		else break;
	}
	for(; cnt < n; cnt++)
	{
		ans += a[r];
		r--;
	}
	printf("%lld\n", ans);
}
int main()
{
	work();
	return 0;
}
/*
2 3 1
2 2 3 4 4 4
3 3 1
1 2 2 2 2 2 5 5 5
*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll n, k, l;
ll a[maxn];
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++) scanf("%lld", &a[i]);
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	ll ans = a[0], cnt = 1;
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(r >= 0 && a[r] > a[0] + l) r--;
//	printf("r:%lld\n", r);
	ll i;
	for(i = k; i < n * k; )
	{
		if(i + k + n - cnt - 2 < r)
		{
			ans += a[i];
			i += k;
			cnt++;
		//	printf("i:%lld n:%lld k:%lld cnt:%lld ans:%lld\n", i, n, k, cnt, ans);
		}
		else
		{
			break;
		}
	}
	for(; cnt < n; cnt++)
	{
		ans += a[r];
		r--;
	//	i++;
	}
	printf("%lld\n", ans);
}
int main()
{
	work();
	return 0;
}
/*
2 3 1
2 2 3 4 4 4
3 3 1
1 2 2 2 2 2 5 5 5
*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll n, k, l;
ll a[maxn];
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++) scanf("%lld", &a[i]);
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	ll ans = a[0], cnt = 1;
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(r >= 0 && a[r] > a[0] + l) r--;
//	printf("r:%lld\n", r);
	ll i;
	for(i = k; i < n * k; )
	{
		if(i + k + n - cnt - 2 <= r)
		{
			ans += a[i];
			i += k;
			cnt++;
		//	printf("i:%lld n:%lld k:%lld cnt:%lld ans:%lld\n", i, n, k, cnt, ans);
		}
		else
		{
			break;
		}
	}
	for(; cnt < n; cnt++)
	{
		ans += a[r];
		r--;
	//	i++;
	}
	printf("%lld\n", ans);
}
int main()
{
	work();
	return 0;
}
/*
2 3 1
2 2 3 4 4 4
*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll a[maxn];
ll n, k, l;
void judge()
{
	ll r;
	if(a[n * k - 1] > a[0] + l)
	{
		r = upper_bound(a, a + n * k, a[0] + l) - a;

	}
	else if(a[n * k - 1] == a[0] + l) r = n * k - 1;
	else r = n * k - 1;
	if(a[r] > a[0] + l) r--;
//	printf("r:%lld\n", r);
	ll ans = 0;
	ll cnt = 0;
	for(ll i = 0; i < n * k; )
	{

		if(i + k + n - cnt <= r + 1)
		{
			ans += a[i];
			cnt++;
			i += k;//printf("i:%lld n:%lld k:%lld cnt:%lld ans:%lld\n", i, n, k, cnt, ans);
		}
		else
		{
			for(ll j = r; ; j--)
			{
				if(cnt >= n) break;
				ans += a[j];
				cnt++;
			}
			break;
		}
	}
	//printf("cnt:%lld\n", cnt);
	//for(ll i = cnt; i < n; i++) ans += a[i];
	printf("%lld\n", ans);
}
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++)
	{
		scanf("%lld", &a[i]);
	}
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	judge();
}
int main()
{
	work();
	return 0;
}
/*
4 2 10
2 2 1 2 3 2 2 3

*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll a[maxn];
ll n, k, l;
void judge()
{
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(a[r] > a[0] + l && r >= 0) r--;
	ll ans = 0;
	ll cnt = 0;
	for(ll i = 0; i < n * k; )
	{
		if(i + k + n - cnt <= r)
		{
			ans += a[i];
			cnt++;
			i += k;
		}
		else break;
	}
	for(ll i = cnt; i < n; i++) ans += a[i];
	printf("%lld\n", ans);
}
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++)
	{
		scanf("%lld", &a[i]);
	}
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	judge();
}
int main()
{
	work();
	return 0;
}
/*
4 2 0
2 2 1 2 3 2 2 3

*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll n, k, l;
ll a[maxn];
void work()
{
	bool put = false;
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++) scanf("%lld", &a[i]);
	if(n == 2 && k == 50000) put = true;
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
/*	printf("a:\n");
	for(ll i = 0; i < n * k; i++)
	{
		printf("%lld ", a[i]);
	}
	printf("\n");*/
	ll ans = a[0], cnt = 1;
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(r >= 0 && a[r] > a[0] + l) r--;
	if(put)printf("r:%lld a[r]:%lld\n", r, a[r]);
	ll i;
	for(i = k; i < n * k; )
	{
		if(i + k + n - cnt - 2 <= r)
		{
			ans += a[i];
			i += k;
			cnt++;
		if(put)	printf("i:%lld n:%lld k:%lld cnt:%lld ans:%lld a:%lld\n", i, n, k, cnt, ans, a[i - k]);
		}
		else
		{
			ans += a[i];
			cnt++;
			for(;cnt < n; cnt++) ans += a[r--];
			break;
		}
	}
	/*for(; cnt < n; cnt++)
	{
		ans += a[r];
		r--;
	//	i++;
	} */
	printf("%lld\n", ans);
}
int main()
{
	work();
	return 0;
}
/*
2 3 1
2 2 3 4 4 4
*/
/*
10 3 795
398 962 417 307 760 534 536 450 421 280 608 111 687 726 941 903 630 900 555 403 795 122 814 188 234 976 679 539 525 104
*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll a[maxn];
ll n, k, l;
void judge()
{
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(a[r] > a[0] + l && r >= 0) r--;
//	printf("r:%lld\n", r);
	ll ans = 0;
	ll cnt = 0;
	ll i;
	for(i = 0; i < n * k; )
	{
		if(i + k + n - cnt <= r + 1)
		{
			ans += a[i];
			cnt++;
			i += k;
		//	printf("i:%lld n:%lld k:%lld cnt:%lld ans:%lld\n", i, n, k, cnt, ans);
		}
		else break;
	}
	for(; cnt < n; cnt++) ans += a[i++];
	printf("%lld\n", ans);
}
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++)
	{
		scanf("%lld", &a[i]);
	}
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	judge();
}
int main()
{
	work();
	return 0;
}
/*
4 2 0
2 2 1 2 3 2 2 3

*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll n, k, l;
ll a[maxn];
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++) scanf("%lld", &a[i]);
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	ll ans = 0, cnt = 0;
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(r >= 0 && a[r] > a[0] + l) r--;
	ll i;
	for(i = 0; i < n * k; )
	{
		if(i + k + n - cnt - 2 <= r)
		{
			ans += a[i];
			i += k;
			cnt++;
		}
		else break;
	}
	for(; cnt < n; cnt++)
	{
		ans += a[i];
		i++;
	}
	printf("%lld\n", ans);
}
int main()
{
	work();
	return 0;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll n, k, l;
ll a[maxn];
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++) scanf("%lld", &a[i]);
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
/*	printf("a:\n");
	for(ll i = 0; i < n * k; i++)
	{
		printf("%lld ", a[i]);
	}
	printf("\n");*/
	ll ans = a[0], cnt = 1;
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(r >= 0 && a[r] > a[0] + l) r--;
//	printf("r:%lld a[r]:%lld\n", r, a[r]);
	ll i;
	for(i = k; i < n * k; )
	{
		if(i + k + n - cnt - 2 <= r)
		{
			ans += a[i];
			i += k;
			cnt++;
		//	printf("i:%lld n:%lld k:%lld cnt:%lld ans:%lld a:%lld\n", i, n, k, cnt, ans, a[i - k]);
		}
		else
		{
			ans += a[i];
			cnt++;
			for(;cnt < n; cnt++) ans += a[r--];
			break;
		}
	}
	/*for(; cnt < n; cnt++)
	{
		ans += a[r];
		r--;
	//	i++;
	} */
	printf("%lld\n", ans);
}
int main()
{
	work();
	return 0;
}
/*
2 3 1
2 2 3 4 4 4
*/
/*
10 3 795
398 962 417 307 760 534 536 450 421 280 608 111 687 726 941 903 630 900 555 403 795 122 814 188 234 976 679 539 525 104
*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll a[maxn];
ll n, k, l;
void judge()
{
	ll r = lower_bound(a, a + n * k, a[0] + l) - a;
	if(a[r] > a[0] + l) r--;
	ll ans = 0;
	ll cnt = 0;
	for(ll i = 0; i < n * k; )
	{
		if(i + k + n - cnt <= r)
		{
			ans += a[i];
			cnt++;
			i += k;
		}
		else break;
	}
	for(ll i = cnt; i < n; i++) ans += a[i];
	printf("%lld\n", ans);
}
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++)
	{
		scanf("%lld", &a[i]);
	}
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	judge();
}
int main()
{
	work();
	return 0;
}
/*
4 2 0
2 2 1 2 3 2 2 3

*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll n, k, l;
ll a[maxn];
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++) scanf("%lld", &a[i]);
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	ll ans = 0, cnt = 0;
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(r >= 0 && a[r] > a[0] + l) r--;
//	printf("r:%lld\n", r);
	ll i;
	for(i = 0; i < n * k; )
	{
		if(i + k + n - cnt - 2 <= r)
		{
			ans += a[i];
			i += k;
			cnt++;
		//	printf("i:%lld n:%lld k:%lld cnt:%lld ans:%lld\n", i, n, k, cnt, ans);
		}
		else
		{
			break;
		}
	}
	for(; cnt < n; cnt++)
	{
		ans += a[r];
		r--;
	//	i++;
	}
	printf("%lld\n", ans);
}
int main()
{
	work();
	return 0;
}
/*
2 3 1
2 2 3 4 4 4
*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll a[maxn];
ll n, k, l;
void judge()
{
	ll r = lower_bound(a, a + n * k, a[0] + l) - a;
	ll ans = 0;
	ll cnt = 0;
	for(ll i = 0; i < n * k; )
	{
		if(i + k + n - cnt <= r)
		{
			ans += a[i];
			cnt++;
			i += k;
		}
		else break;
	}
	for(ll i = cnt; i < n; i++) ans += a[i];
	printf("%lld\n", ans);
}
void work()
{
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++)
	{
		scanf("%lld", &a[i]);
	}
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	judge();
}
int main()
{
	work();
	return 0;
}
/*
4 2 0
2 2 1 2 3 2 2 3

*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
ll n, k, l;
ll a[maxn];
void work()
{
	bool put = false;
	cin >> n >> k >> l;
	for(ll i = 0; i < n * k; i++) scanf("%lld", &a[i]);
//	if(n == 2 && k == 50000) put = true;
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
/*	printf("a:\n");
	for(ll i = 0; i < n * k; i++)
	{
		printf("%lld ", a[i]);
	}
	printf("\n");*/
	ll ans = a[0], cnt = 1;
	ll r = upper_bound(a, a + n * k, a[0] + l) - a;
	if(r > n * k - 1) r = n * k - 1;
	while(r >= 0 && a[r] > a[0] + l) r--;
	if(put)printf("r:%lld a[r]:%lld\n", r, a[r]);
	ll i;
	for(i = k; i < n * k; )
	{
		if(i + k + n - cnt - 2 <= r)
		{
			ans += a[i];
			i += k;
			cnt++;
		if(put)	printf("i:%lld n:%lld k:%lld cnt:%lld ans:%lld a:%lld\n", i, n, k, cnt, ans, a[i - k]);
		}
		else
		{
			if(i != k)
			{
				ans += a[i];
				cnt++;
			}

			for(;cnt < n; cnt++) ans += a[r--];
			break;
		}
	}
	/*for(; cnt < n; cnt++)
	{
		ans += a[r];
		r--;
	//	i++;
	} */
	printf("%lld\n", ans);
}
int main()
{
	work();
	return 0;
}
/*
2 3 1
2 2 3 4 4 4
*/
/*
10 3 795
398 962 417 307 760 534 536 450 421 280 608 111 687 726 941 903 630 900 555 403 795 122 814 188 234 976 679 539 525 104
*/


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<iostream>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<list>
#include<map>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-7;
typedef long long ll;
int a[maxn];
int n, k, l;
void judge()
{
	int r = lower_bound(a, a + n * k, a[0] + l) - a;
	int ans = 0;
	int cnt = 0;
	for(int i = 0; i < n * k; )
	{
		if(i + k + n - cnt <= r)
		{
			ans += a[i];
			cnt++;
			i += k;
		}
		else break;
	}
	for(int i = cnt; i < n; i++) ans += a[i];
	printf("%d\n", ans);
}
void work()
{
	cin >> n >> k >> l;
	for(int i = 0; i < n * k; i++)
	{
		scanf("%d", &a[i]);
	}
	sort(a, a + n * k);
	if(a[n - 1] - a[0] > l)
	{
		printf("0\n");
		return;
	}
	judge();
}
int main()
{
	work();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010];
int main()
{
    ll n,k,l,tot;
    tot=0;
	scanf("%lld%lld%lld",&n,&k,&l);
    for(ll i=1;i<=n*k;i++)
    {
    	scanf("%lld",&a[i]);
	}
	sort(a+1,a+n*k+1);
	int upp=n*k;
	for(int i=1;i<=n*k;i++)
	{
		if(a[i]-a[1]>l)
		{
		  upp=i-1;
		  break;
		}
	}
//	if(upp==n*k)
//	{
//		for(int i=1;i<=n;i++)
//		tot+=a[i];
//		printf("")
//	}
    if(upp<n)
    printf("0\n");
    else
    {
    	  if(k==1)
    	{
    		for(int i=1;i<=n;i++)
    		tot+=a[i];
    		printf("%lld\n",tot);
		}
		  else
		{
		   ll x=(upp-n)/(k-1);
    	   ll y=n-x;
    	   for(int i=1;i<1+k*x;i+=k)
    	   tot+=a[i];
    	   int u=1+k*x;
    	   while(y--)
    	   {
    		   tot+=a[u];
    		   u++;
		   }
		       printf("%lld\n",tot);
	    }
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010];
ll bar[100010];
int main()
{
    ll n,k,l;
	scanf("%lld%lld%lld",&n,&k,&l);
    for(ll i=0;i<n*k;i++)
    {
    	scanf("%lld",&a[i]);
	}
	sort(a,a+n*k);
	ll s2=n*k-1;
	ll s1=0;
	ll ind=n*k;
	for(ll i=0;i<n*k-1;i++)
	{
		if(a[i]>l+a[0])
		{
		   ind=i;
		   break;
	    }
	}
	ll u=0;
	ll kcopy;
	while(s2>=s1&&s2>=ind)
	{
	    bar[u]=a[s2];
	    kcopy=k;
	    if(kcopy==1)
	    s2--;
	    else
	   {
		 bar[u]=min(a[s1],bar[u]);
		 s1++;
		 kcopy--;
		 if(s2-ind>=kcopy-1)
		 {
		 while(--kcopy)
		{
		   	bar[u]=min(a[s2],bar[u]);
		   	s2--;
		}
		u++;
		s2--;
	     }
	     else
	     {
	     	u++;
	     	s2=ind;
		 }
	   }
	}
	if(s2>=s1)
	{
		while(s2>=s1)
		{
			bar[u]=a[s2];
			kcopy=k;
			while(--kcopy)
		   	bar[u]=min(bar[u],a[--s2]);
		   	s2--;
		   	u++;
		}
	}
	sort(bar,bar+u);
	ll tot=0;
	if(bar[u-1]-bar[0]<=l)
	{
		for(ll i=0;i<u;i++)
		{
			tot+=bar[i];
		}
		printf("%lld\n",tot);
	}
	else
	printf("0\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010];
ll bar[100010];
int main()
{
    ll n,k,l;
	scanf("%lld%lld%lld",&n,&k,&l);
    for(ll i=0;i<n*k;i++)
    {
    	scanf("%lld",&a[i]);
	}
	sort(a,a+n*k);
	ll s2=n*k-1;
	ll s1=0;
	ll ind=n*k;
	for(ll i=0;i<n*k-1;i++)
	{
		if(a[i]>l+a[0])
		{
		   ind=i;
		   break;
	    }
	}
	ll u=0;
	ll kcopy;
	while(s2>=s1&&s2>=ind)
	{
	    bar[u]=a[s2];
	    kcopy=k;
	    if(kcopy==1)
	    s2--;
	    else
	   {
		 bar[u]=min(a[s1],bar[u]);
		 s1++;
		 kcopy--;
		 while(--kcopy)
		{
		   	bar[u]=min(a[s2],bar[u]);
		   	s2--;
		}
		u++;
		s2--;
	   }
	}
	if(s2>=s1)
	{
		while(s2>=s1)
		{
			bar[u]=a[s2];
			kcopy=k;
			while(--kcopy)
		   	bar[u]=min(bar[u],a[--s2]);
		   	s2--;
		   	u++;
		}
	}
	sort(bar,bar+u);
	ll tot=0;
	if(bar[u-1]-bar[0]<=l)
	{
		for(ll i=0;i<u;i++)
		{
			tot+=bar[i];
		}
		printf("%lld\n",tot);
	}
	else
	printf("0\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010];
int main()
{
    ll n,k,l,tot;
    tot=0;
	scanf("%lld%lld%lld",&n,&k,&l);
    for(ll i=1;i<=n*k;i++)
    {
    	scanf("%lld",&a[i]);
	}
	sort(a+1,a+n*k+1);
	int upp=n*k;
	for(int i=1;i<=n*k;i++)
	{
		if(a[i]-a[1]>l)
		{
		  upp=i-1;
		  break;
		}
	}
    if(upp<n)
    printf("0\n");
    else
    {
    	  if(k==1)
    	{
    		for(int i=1;i<=n;i++)
    		tot+=a[i];
    		printf("%lld\n",tot);
		}
		  else
		{
		   ll x=(upp-n)/(k-1);
    	   ll y=n-x;
    	   for(int i=1;i<1+k*x;i+=k)
    	   tot+=a[i];
    	   int u=upp;
    	   while(y--)
    	   {
    		   tot+=a[u];
    		   u--;
		   }
		       printf("%lld\n",tot);
	    }
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010];
int main()
{
    ll n,k,l,tot;
    tot=0;
	scanf("%lld%lld%lld",&n,&k,&l);
    for(ll i=1;i<=n*k;i++)
    {
    	scanf("%lld",&a[i]);
	}
	sort(a+1,a+n*k+1);
	int upp=n*k;
	for(int i=1;i<=n*k;i++)
	{
		if(a[i]-a[1]>l)
		{
		  upp=i-1;
		  break;
		}
	}
    if(upp<n)
    printf("0\n");
    else
    {
    	  if(k==1)
    	{
    		for(int i=1;i<=n;i++)
    		tot+=a[i];
    		printf("%lld\n",tot);
		}
		  else
		{
		   ll x=(upp-n)/(k-1);
    	   ll y=n-x;
    	   for(int i=1;i<1+k*x;i+=k)
    	   tot+=a[i];
    	   int u=upp;
    	   y--;
    	   while(y>0)
    	   {
    		   tot+=a[u];
    		   u--;
    		   y--;
		   }
		   tot+=a[k*x+1];
		    printf("%lld\n",tot);
	    }
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010];
ll bar[100010];
int main()
{
    ll n,k,l;
	scanf("%lld%lld%lld",&n,&k,&l);
    for(ll i=0;i<n*k;i++)
    {
    	scanf("%lld",&a[i]);
	}
	sort(a,a+n*k);
	ll s2=n*k-1;
	ll s1=0;
	ll ind=0;
	for(ll i=0;i<n*k-1;i++)
	{
		if(a[i]>l+a[0])
		{
		   ind=i;
		   break;
	    }
	}
	ll u=0;
	ll kcopy;
	while(s2>=s1&&s2>=ind)
	{
	    bar[u]=a[s2];
	    kcopy=k;
		while(--kcopy)
		{
		   	bar[u]=min(a[s1],bar[u]);
		   	s1++;
		}
		u++;
		s2--;
	}
	if(s2>=s1)
	{
		while(s2>s1)
		{
			bar[u]=a[s2];
			kcopy=k;
			while(--kcopy)
		   	bar[u]=min(bar[u],a[--s2]);
		   	s2--;
		   	u++;
		}
	}
	sort(bar,bar+u);
	ll tot=0;
	if(bar[u-1]-bar[0]<=l)
	{
		for(ll i=0;i<u;i++)
		{
			tot+=bar[i];
		}
		printf("%lld\n",tot);
	}
	else
	printf("0\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010];
int main()
{
    ll n,k,l,tot;
    tot=0;
	scanf("%lld%lld%lld",&n,&k,&l);
    for(ll i=1;i<=n*k;i++)
    {
    	scanf("%lld",&a[i]);
	}
	sort(a+1,a+n*k+1);
	int upp=n*k;
	for(int i=1;i<=n*k;i++)
	{
		if(a[i]-a[1]>l)
		{
		  upp=i-1;
		  break;
		}
	}
    if(upp<n)
    printf("0\n");
    else
    {
    	  if(k==1)
    	{
    		for(int i=1;i<=n;i++)
    		tot+=a[i];
    		printf("%lld\n",tot);
		}
		  else
		{
		   ll x=(upp-n)/(k-1);
    	   ll y=n-x;
    	   for(int i=1;i<1+k*x;i+=k)
    	   tot+=a[i];
    	   int u=upp;
    	   y--;
    	   while(y--)
    	   {
    		   tot+=a[u];
    		   u--;
		   }
		   tot+=a[k*x+1];
		    printf("%lld\n",tot);
	    }
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010];
ll bar[100010];
int main()
{
    ll n,k,l;
	scanf("%lld%lld%lld",&n,&k,&l);
    for(ll i=0;i<n*k;i++)
    {
    	scanf("%lld",&a[i]);
	}
	sort(a,a+n*k);
	ll s2=n*k-1;
	ll s1=0;
	ll ind=n*k;
	for(ll i=0;i<n*k-1;i++)
	{
		if(a[i]>l+a[0])
		{
		   ind=i;
		   break;
	    }
	}
	ll u=0;
	ll kcopy;
	while(s2>=s1&&s2>=ind)
	{
	    bar[u]=a[s2];
	    kcopy=k;
	    if(kcopy==1)
	    s2--;
	    else
	   {
		 bar[u]=min(a[s1],bar[u]);
		 s1++;
		 kcopy--;
		 if(s2-ind>=kcopy-1)
		 {
		 while(--kcopy)
		{
		   	bar[u]=min(a[s2],bar[u]);
		   	s2--;
		}
		u++;
		s2--;
	     }
	     else
	     {
	     	u++;
	     	s2=ind-1;
		 }
	   }
	}
	if(s2>=s1)
	{
		while(s2>=s1)
		{
			bar[u]=a[s2];
			kcopy=k;
			while(--kcopy)
		   	bar[u]=min(bar[u],a[--s2]);
		   	s2--;
		   	u++;
		}
	}
	sort(bar,bar+u);
	ll tot=0;
	if(bar[u-1]-bar[0]<=l)
	{
		for(ll i=0;i<u;i++)
		{
			tot+=bar[i];
		}
		printf("%lld\n",tot);
	}
	else
	printf("0\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100010];
ll bar[100010];
int main()
{
    ll n,k,l;
	scanf("%lld%lld%lld",&n,&k,&l);
    for(ll i=0;i<n*k;i++)
    {
    	scanf("%lld",&a[i]);
	}
	sort(a,a+n*k);
	ll s2=n*k-1;
	ll s1=0;
	ll ind=n*k;
	for(ll i=0;i<n*k-1;i++)
	{
		if(a[i]>l+a[0])
		{
		   ind=i;
		   break;
	    }
	}
	ll u=0;
	ll kcopy;
	while(s2>=s1&&s2>=ind)
	{
	    bar[u]=a[s2];
	    kcopy=k;
		while(--kcopy)
		{
		   	bar[u]=min(a[s1],bar[u]);
		   	s1++;
		}
		u++;
		s2--;
	}
	if(s2>=s1)
	{
		while(s2>=s1)
		{
			bar[u]=a[s2];
			kcopy=k;
			while(--kcopy)
		   	bar[u]=min(bar[u],a[--s2]);
		   	s2--;
		   	u++;
		}
	}
	sort(bar,bar+u);
	ll tot=0;
	if(bar[u-1]-bar[0]<=l)
	{
		for(ll i=0;i<u;i++)
		{
			tot+=bar[i];
		}
		printf("%lld\n",tot);
	}
	else
	printf("0\n");
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN];

int main() {
#ifdef DEBUG
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    int x = posx / k + posx % k;
    int z = x;
    while (x < n) {
        z --;
        -- x;
        x += k;
    }
    n -= z;
    int i = 1;
    for (; i <= posx; i += k) {
        if (!z)
            break;
        -- z;
        ans += a[i];
    }
    for (; i <= posx; ++ i) {
        if (!n)
            break;
        -- n;
        ans += a[i];
    }
    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN];

int main() {
#ifdef DEBUG
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    int l = 1;
    while (l + k <= posx) {
        ans += a[l];
        u[l] = 1;
        l += k;
        n --;
        if (!n)
            break;
    }
    if (!n)
        cout << ans, exit (0);
    if (l + n - 1 <= posx) {
        for (int i = l; i <= posx; ++ i) {
            if (!n)
                break;
            ans += a[i];
            -- n;
        }
        cout << ans, exit (0);
    }
    if (l != 1) {
        l -= k;
        ans -= a[l];
    }
    for (int i = l; i <= posx; ++ i) {
        if (!n)
            break;
        ans += a[i];
        -- n;
    }
    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN];

int main() {
    #ifdef DEBUG
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    int l = 1, cnt = 0;;
    while (l + k <= posx) {
        ans += a[l];
        u[l] = 1;
        l += k;
        ++ cnt;
        if (cnt == n)
            break;
    }
    for (int i = posx; i >= 1; -- i) {
        if (cnt == n)
            break;
        if (!u[i])
            ans += a[i], ++ cnt;
    }
    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN], cnt[MaxN];

int main() {
    #ifdef DEBUG
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    for (int i = 1; i <= n; ++ i)
        ans += a[i], cnt[i] = 1;
    int x = 1, l = 2;
    for (int i = n + 1; i <= posx; ++ i) {
        while (cnt[x] == k)
            ++ x;
        while (x > n)
            break;
        cnt[x] ++;
        ans -= a[l];
        ans += a[i];
        l ++;
    }
    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN];

int main() {
    #ifdef DEBUG
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    int l = 1;
    while (l + k <= posx) {
        ans += a[l];
        u[l] = 1;
        l += k;
        n --;
        if (!n)
            break;
    }
    for (int i = l; i <= posx; ++ i) {
        if (!n)
            break;
        if (!u[i])
            ans += a[i], -- n, u[i] = 1;
    }
    for (int i = posx; i >= 1; -- i) {
        if (!n)
            break;
        if (!u[i])
            ans += a[i], -- n;
    }

    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN], cnt[MaxN];

int main() {
    #ifdef DEBUG
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    for (int i = 1; i <= n; ++ i)
        ans += a[i], cnt[i] = 1;
    int x = 1, l = 2;
    for (int i = n + 1; i <= posx; ++ i) {
        while (cnt[x] == k)
            ++ x, ++ l;
        while (x > n)
            break;
        cnt[x] ++;
        ans -= a[l];
        ans += a[i];
        l ++;
    }
    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN];

int main() {
    #ifdef DEBUG
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    long long ans = 0;
    int l = 1, cnt = 0;;
    while (l + k <= posx) {
        ans += a[l];
        l += k;
        ++ cnt;
    }
    for (int i = l; i <= posx; ++ i) {
        ans += a[i];
        ++ cnt;
    }
    if (cnt != n)
        ans = 0;
    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN];

int main() {
#ifdef DEBUG
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    int l = 1;
    while (l + k <= posx && posx - k - l >= n - 1) {
        ans += a[l];
        u[l] = 1;
        l += k;
        n --;
        if (!n)
            break;
    }
    if (!n)
        cout << ans, exit (0);
    if (l + n - 1 <= posx) {
        for (int i = l; i <= posx; ++ i) {
            if (!n)
                break;
            ans += a[i];
            -- n;
        }
        cout << ans, exit (0);
    }
    if (l != 1) {
        l -= k;
        ans -= a[l];
    }
    for (int i = l; i <= posx; ++ i) {
        if (!n)
            break;
        ans += a[i];
        -- n;
    }
    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN];

int main() {
    #ifdef DEBUG
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    int l = 1;
    while (l + k <= posx) {
        ans += a[l];
        u[l] = 1;
        l += k;
        n --;
        if (!n)
            break;
    }
    for (int i = l; i <= posx; ++ i) {
        if (!n)
            break;
        if (!u[i])
            ans += a[i], -- n;
    }

    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN];

int main() {
#ifdef DEBUG
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    int x = posx / k;
    int z = x;
    while (x < n) {
        z --;
        -- x;
        x += k;
    }
    z = max (z, 0);
    n -= z;
    int i = 1;
    for (i = 1; i <= posx; i += k) {
        if (!z)
            break;
        -- z;
        ans += a[i];
    }
    for (; i <= posx; ++ i) {
        if (!n)
            break;
        -- n;
        ans += a[i];
    }
    cout << ans;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define ll long long
#define ull unsigned long long

#define FNAME ""
#define pb push_back

using namespace std;

const int MaxN = 2e5 + 17;
const int INF = 1e9 + 17;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const double pi = 3.14159265359;

int n, k, l, m;
int a[MaxN], u[MaxN];

int main() {
    #ifdef DEBUG
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif
    scanf ("%d%d%d", &n, &k, &l);
    m = n * k;
    for (int i = 1; i <= m; ++ i)
        scanf ("%d", a + i);
    sort (a + 1, a + m + 1);
    int posx = upper_bound (a + 1, a + m + 1, a[1] + l) - a;
    -- posx;
    if (posx < n)
        cout << 0, exit (0);
    long long ans = 0;
    int l = 1, cnt = 0;;
    while (l + k <= posx) {
        ans += a[l];
        u[l] = 1;
        l += k;
        ++ cnt;
    }
    for (int i = posx; i >= 1; -- i) {
        if (cnt == n)
            break;
        if (!u[i])
            ans += a[i], ++ cnt;
    }
    cout << ans;
    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    if(abs(a[0]-a[n-1])>l) cout<<0;
    else
    {
        i = upper_bound(a,a+n*k,a[0]+l)-a-1;
        ans=a[0];x=1;
        ll t=k;
        for(j=i;j>0;j--)
        {
            if(x==n) break;
            if(n*k-i>=t){
            ans+=a[j];
            t+=k;
            x++;
            }
        }
        cout<<ans;
    }

    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    //fr(i,n*k) cout<<a[i]<<" ";
    //cout<<endl;
    vl v;v.pb(a[0]);
    x=0;
    for(i=0;i<n*k-k;)
    {
        f=0;
        if(x==n-1) break;
        for(j=i+k;j>=i+1;j--)
        {
            if(abs(a[i]-a[j])<=l && abs(a[0]-a[j])<=l)
            {
                v.pb(a[j]);
                i=j;
                x++;
                f=1;
                break;
            }
        }
        if(f==0) i++;
    }
    ans=0;
    sort(all(v));
   // fr(i,v.size()) cout<<v[i]<<" ";
   //cout<<endl;
    if(v.size()<n) cout<<0;
    else if(v.size()==n && abs(v[0]-v[n-1])>l) cout<<0;
    else
    {
        for(i=0;i<v.size();i++)
        {
            ans+=v[i];
        }
        cout<<ans;
    }
    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    f=1;ans=0;
    fr(i,n)
    {
        ans+=a[i];
        fri(j,i+1,n)
        {
            x=abs(a[i]-a[j]);
            if(x>l)
            {
                f=0;
                break;
            }
        }
    }
    if(f==0) cout<<0;
    else cout<<ans;
    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    f=1;ans=0;
    fr(i,n)
    {
        ans+=a[i];
            x=abs(a[i]-a[n-1]);
            if(x>l)
            {
                f=0;
                break;
            }
    }
    if(f==0) cout<<0;
    else cout<<ans;
    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    //fr(i,n*k) cout<<a[i]<<" ";
    //cout<<endl;
    vis[0]=1;
    vl v;v.pb(a[0]);
    vl vis(n*k);
    x=0;
    for(i=0;i<n*k-k;)
    {
        f=0;
        if(x==n-1) break;
        for(j=i+k;j>=0;j--)
        {
            if(abs(a[i]-a[j])<=l && abs(a[0]-a[j])<=l && vis[j]==0)
            {
                v.pb(a[j]);
                vis[j]=1;
                i=j;
                x++;
                f=1;
                break;
            }
        }
        if(f==0) i++;
    }
    ans=0;
    sort(all(v));
   // fr(i,v.size()) cout<<v[i]<<" ";
   //cout<<endl;
    if(v.size()<n) cout<<0;
    else if(v.size()==n && abs(v[0]-v[n-1])>l) cout<<0;
    else
    {
        for(i=0;i<v.size();i++)
        {
            ans+=v[i];
        }
        cout<<ans;
    }
    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    if(abs(a[0]-a[n-1])>l) cout<<0;
    else
    {
        i = upper_bound(a,a+n*k,a[0]+l)-a-1;
        ans=a[0];x=1;
        ll t=k;
        for(j=i;j>0;j--)
        {
            if(x==n) break;
            if(n*k-j>=t){
            ans+=a[j];
            t+=k;
            x++;
            }
        }
        cout<<ans;
    }

    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    //fr(i,n*k) cout<<a[i]<<" ";
    //cout<<endl;
    vl v;v.pb(a[0]);
    vl vis(n*k);
    x=0;
    for(i=0;i<n*k-k;)
    {
        f=0;
        if(x==n-1) break;
        for(j=i+k;j>=0;j--)
        {
            if(abs(a[i]-a[j])<=l && abs(a[0]-a[j])<=l && vis[j]==0)
            {
                v.pb(a[j]);
                vis[j]=1;
                i=j;
                x++;
                f=1;
                break;
            }
        }
        if(f==0) i++;
    }
    ans=0;
    sort(all(v));
   // fr(i,v.size()) cout<<v[i]<<" ";
   //cout<<endl;
    if(v.size()<n) cout<<0;
    else if(v.size()==n && abs(v[0]-v[n-1])>l) cout<<0;
    else
    {
        for(i=0;i<v.size();i++)
        {
            ans+=v[i];
        }
        cout<<ans;
    }
    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    //fr(i,n*k) cout<<a[i]<<" ";
    //cout<<endl;
    vl v;v.pb(a[0]);
    x=0;
    for(i=n*k-1;i>0;i--)
    {
        if(x==n-1) break;
        if(abs(a[i]-a[0])<=l){
        v.pb(a[i]);
        x++;
        }
    }
    ans=0;
    if(v.size()<n) cout<<0;
    else
    {
        for(i=0;i<v.size();i++)
        {
            ans+=v[i];
        }
        cout<<ans;
    }

    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    if(abs(a[0]-a[n-1])>l) cout<<0;
    else
    {
        i = upper_bound(a,a+n*k,a[0]+l)-a-1;
        ans=0;
        ans+=a[0];x=1;
        for(j=i;j>0;j--)
        {
            if(x==n) break;
            ans+=a[j];
            x++;
        }
        cout<<ans;
    }

    return 0;
}


/*
Even kings and emperors
with heaps of wealth and vast dominion
cannot compare with an ant
filled with the love of God.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef map <long long, long long> ml;

#define pb push_back
#define F first
#define S second
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define ll long long
#define st(v) sort(v.begin(),v.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define fri(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define s(t) ll t;cin>>t;while(t--)
#define i1(n) ll n;cin>>n;
#define i2(a,b) ll a,b; cin>>a>>b;
#define i3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define i4(a,b,c,d) ll a,b,c,d; cin>>a>>b>>c>>d;
#define ian(a,n) ll n;cin>>n; ll a[n+4]; fr(i,n) cin>>a[i];
#define ia(a,n) ll a[n+4]; fr(i,n) cin>>a[i];
#define mod 1000000007

ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v,w,x,y,z,maxi,mini,low,high,ans=-1;
string s1,s2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>l;
    ia(a,n*k);
    sort(a,a+n*k);
    //fr(i,n*k) cout<<a[i]<<" ";
    //cout<<endl;
    //vis[0]=1;
    vl v;v.pb(a[0]);
    vl vis(n*k);
    vis[0]=1;
    x=0;
    for(i=0;i<n*k-k;)
    {
        f=0;
        if(x==n-1) break;
        for(j=i+k;j>=0;j--)
        {
            if(abs(a[i]-a[j])<=l && abs(a[0]-a[j])<=l && vis[j]==0)
            {
                v.pb(a[j]);
                vis[j]=1;
                i=j;
                x++;
                f=1;
                break;
            }
        }
        if(f==0) i++;
    }
    ans=0;
    sort(all(v));
   // fr(i,v.size()) cout<<v[i]<<" ";
   //cout<<endl;
    if(v.size()<n) cout<<0;
    else if(v.size()==n && abs(v[0]-v[n-1])>l) cout<<0;
    else
    {
        for(i=0;i<v.size();i++)
        {
            ans+=v[i];
        }
        cout<<ans;
    }
    return 0;
}


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		if(A[s-1]-A[0]>l){
			cout<<0;
			return;
		}
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	// n banane hain
	// k in each
	ll c=1;
	for(int i=1;i<s;i++) if(A[i]-A[0]<=l) c++;
	if(c<n){
		cout<<0;
		return;
	}
	ll first=0, last;
	for(ll i=1;i<s;i++){
		if(A[i]-A[0]<=l) last=i;
	}
	ll t=last-first+1;
	if(t<n){
		cout<<0<<"\n";
		return;
	}
	ll x=t/n;
	ll rem=t-x*n;
	ll tt=rem/(k-1);
	x=tt;
	ll X=x, ans=0, start=0;
	while(x--){
		ans+=A[start];
		start+=k;
		n--;
	}
	for(ll i=last; n>0;i--, n--) ans+=A[i];
	cout<<ans;
}
/*
	3 2 2
1 2 3 4 5 6
*/
int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	// n banane hain
	// k in each
	ll c=1;
	for(int i=1;i<s;i++) if(A[i]-A[0]<=l) c++;
	if(c<n){
		cout<<0;
		return;
	}
	ll first=0, last;
	for(ll i=1;i<s;i++){
		if(A[i]-A[0]<=l) last=i;
	}
	ll t=last-first+1;
	if(t<n){
		cout<<0<<"\n";
		return;
	}
	ll x=t/n;
	ll rem=t-x*n;
	ll tt=rem/(k-1);
	x=tt;
	ll X=x, ans=0, start=0;
	while(x--){
		ans+=A[start];
		start+=k;
		n--;
	}
	for(ll i=last; n>0;i--, n--) ans+=A[i];
	cout<<ans;
}
/*
	3 2 2
1 2 3 4 5 6
*/
int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	/*3 2 1
	1 2 3 4 5 6*/

	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		if(A[s-1]-A[0]>l){
			cout<<0;
			return;
		}
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	// n banane hain
	// k in each
	ll c=1;
	for(int i=1;i<s;i++) if(A[i]-A[0]<=l) c++;
	if(c<n){
		cout<<0;
		return;
	}
	ll first=0, last;
	for(ll i=1;i<s;i++){
		if(A[i]-A[0]<=l) last=i;
	}
	ll t=last-first+1;
	if(t<n){
		cout<<0<<"\n";
		return;
	}
	ll x=t/n;
	ll rem=t-x*n;
	ll tt=rem/(k-1);
	x=tt;
	ll X=x, ans=0, start=0;
	while(x--){
		ans+=A[start];
		//taken=start;
		start+=k;
	}
	//cout<<ans<<" "<<X<<" "<<last<<"\n";
	for(ll i=k*X;i<=last;i++) ans+=A[i];
	cout<<ans;
}
/*
	3 2 2
1 2 3 4 5 6
*/
int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	/*3 2 1
	1 2 3 4 5 6*/

	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		if(A[s-1]-A[0]>l){
			cout<<0;
			return;
		}
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	// n banane hain
	// k in each
	ll c=1;
	for(int i=1;i<s;i++) if(A[i]-A[0]<=l) c++;
	if(c<n){
		cout<<0;
		return;
	}
	ll first=0, last;
	for(ll i=1;i<s;i++){
		if(A[i]-A[0]<=l) last=i;
	}
	ll t=last-first+1;
	if(t<n){
		cout<<0<<"\n";
		return;
	}
	ll req=n;
	ll ans=0;
	for(ll i=0;i<=last;i++){
		ll avail=last-i+1;
		if(avail-k>=req-1){
			ans+=A[i];
			i+=k-1;
			req--;
		}
		else{
			ans+=A[i];
			req--;
			ll p=last;
			while(req--){
				ans+=A[p];
				p--;
			}
			cout<<ans<<"\n";
			return;
		}
		if(!req) break;
	}
	cout<<ans;
}
/*
	3 2 2
1 2 3 4 5 6
*/
int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	/*3 2 1
	1 2 3 4 5 6*/

	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		if(A[s-1]-A[0]>l){
			cout<<0;
			return;
		}
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	vector<ll> V;
	V.pb(A[0]);
	ll x=A[0];
	for(int i=1;i<s;i++){
		if(V.size()==n) break;
		if(A[i]-x<=l) V.pb(A[i]);

	}
	if(V.size()!=n){
		cout<<0;
		return;
	}
	ll ans=0;
	for(int i=0;i<n;i++) ans=ans+V[i];
	cout<<ans;

}

int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	/*3 2 1
	1 2 3 4 5 6*/

	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	vector<ll> V;
	V.pb(A[0]);
	ll x=A[0];
	for(int i=1;i<s;i++){
		if(A[i]-x<=l) V.pb(A[i]);
		if(V.size()==n) break;
	}
	if(V.size()!=n){
		cout<<0;
		return;
	}
	ll ans=0;
	for(int i=0;i<n;i++) ans=ans+V[i];
	cout<<ans;

}

int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	/*3 2 1
	1 2 3 4 5 6*/

	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	vector<ll> V;
	V.pb(A[0]);
	ll x=A[0];
	for(int i=1;i<s;i++){
		if(V.size()==n) break;
		if(A[i]-x<=l) V.pb(A[i]);

	}
	if(V.size()!=n){
		cout<<0;
		return;
	}
	ll ans=0;
	for(int i=0;i<n;i++) ans=ans+V[i];
	cout<<ans;

}

int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	/*3 2 1
	1 2 3 4 5 6*/

	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	// n banane hain
	// k in each
	ll c=1;
	for(int i=1;i<s;i++) if(A[i]-A[0]<=l) c++;
	if(c<n){
		cout<<0;
		return;
	}
	ll first=0, last;
	for(ll i=1;i<s;i++){
		if(A[i]-A[0]<=l) last=i;
	}
	ll t=last-first+1;
	ll x=t/n;
	ll rem=t-x*n;
	ll tt=rem/(k-1);
	x=tt;
	ll X=x, ans=0, start=0;
	while(x--){
		ans+=A[start];
		//taken=start;
		start+=k;
	}
	//cout<<ans<<" "<<X<<" "<<last<<"\n";
	for(ll i=k*X;i<=last;i++) ans+=A[i];
	cout<<ans;
}
/*
	3 2 2
1 2 3 4 5 6
*/
int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	/*3 2 1
	1 2 3 4 5 6*/

	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		if(A[s-1]-A[0]>l){
			cout<<0;
			return;
		}
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	// n banane hain
	// k in each
	ll c=1;
	for(int i=1;i<s;i++) if(A[i]-A[0]<=l) c++;
	if(c<n){
		cout<<0;
		return;
	}
	ll first=0, last;
	for(ll i=1;i<s;i++){
		if(A[i]-A[0]<=l) last=i;
	}
	ll t=last-first+1;
	if(t<n){
		cout<<0<<"\n";
		return;
	}
	ll req=n;
	ll ans=0;
	for(ll i=0;i<=last;i++){
		ll avail=last-i+1;
		if(avail-k>=req-1){
			ans+=A[i];
			i+=k-1;
			req--;
		}
		else{
			ans+=A[i];
			req--;
			ll p=last;
			while(req--){
				ans+=A[p];
				p--;
			}
			cout<<ans<<"\n";
			return;
		}
	}

}
/*
	3 2 2
1 2 3 4 5 6
*/
int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
typedef long long int ll;
#define ld long double
#define mp make_pair
#define pb push_back
#define speed() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define se second
#define fs first
#define mod 1000000007
using namespace std;
/*****************************************************************************************/

void solve()
{
	/*3 2 1
	1 2 3 4 5 6*/

	ll n, k, l;
	cin>>n>>k>>l;
	ll A[n*k];
	for(int i=0;i<n*k;i++) cin>>A[i];
	ll s=n*k;
	sort(A, A+s);
	if(k==1){
		ll sum=0;
		for(int i=0;i<s;i++) sum+=A[i];
		cout<<sum<<"\n";
		return;
	}
	if(n==1){
		cout<<A[0];
		return;
	}
	// n banane hain
	// k in each
	ll c=1;
	for(int i=1;i<s;i++) if(A[i]-A[0]<=l) c++;
	if(c<n){
		cout<<0;
		return;
	}
	ll first=0, last;
	for(ll i=1;i<s;i++){
		if(A[i]-A[0]<=l) last=i;
	}
	ll t=last-first+1;
	if(t<n){
		cout<<0<<"\n";
		return;
	}
	ll x=t/n;
	ll rem=t-x*n;
	ll tt=rem/(k-1);
	x=tt;
	ll X=x, ans=0, start=0;
	while(x--){
		ans+=A[start];
		//taken=start;
		start+=k;
	}
	//cout<<ans<<" "<<X<<" "<<last<<"\n";
	for(ll i=k*X;i<=last;i++) ans+=A[i];
	cout<<ans;
}
/*
	3 2 2
1 2 3 4 5 6
*/
int main(){
	speed();
	//ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ofstream outfile;
    //outfile.open("output.txt");
    //ifstream infile;
    //infile.open("A-large.in", ios::binary|ios::in);
	//freopen("", stdin, "r");
	//freopen("", stout, "w");
	ll t=1;
	//sieve();
	//cin>>t;
	while(t--){
		solve();
	//	cout<<"\n";
	}

    //outfile.close();
    //infile.close();
    return 0;

}
//asdfghjklpoiuytrewqaswedrftgyhujikolplmn


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
ll ans;
main()
{
	FX iOS
	ll i,j,n,k,m,l;
	cin>>n>>k>>l;
	m=n*1ll*k;
	ll a[m];
	multiset<ll>se;
	for(i=0;i<m;++i)cin>>a[i],se.insert(a[i]);
	sort(a,a+m);
	vector<ll>ve;
	for(i=m-k;i>=0;i-=k)
	{
		auto it=se.upper_bound(a[0]+l);
		if(it!=se.begin())
		{
		--it;
		se.erase(se.find(*it));
		int best=*it;
		if(a[i]>best)a[i]=best;
		ve.pb(a[i]);
		ans+=a[i];
		}
		else return cout<<0,0;
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
int ans;
map<int,multiset<int>>mapa;
main()
{
	FX iOS
	int i,j,n,k,m,l;
	cin>>n>>k>>l;
	m=n*k;
	int a[m];
	for(i=0;i<m;++i)cin>>a[i];
	sort(a,a+m);
	int best=a[0]+l;
	int cnt=0,cur=0;
	multiset<pii>good;
	for(i=0;i<m;++i)
	{
		if(cnt==k)cur++,cnt=0;
		mapa[cur].insert(a[i]);
		if(a[i]<=best)
			good.insert({a[i],cur});
		cnt++;
	}
	/*for(auto it:good)cout<<it.f<<" ";
	cout<<good.size();*/
	if((int)good.size()<n)return cout<<0,0;
	vector<int>ve;
	for(i=n;i>=0;--i)
	{
		if(*mapa[i].begin()>best)
		{
			auto it=*(--good.end());
			int cur=it.f;
			mapa[it.s].insert(*mapa[i].begin());
			mapa[it.s].erase(mapa[it.s].find(it.f));
			mapa[i].erase(mapa[i].begin());
			mapa[i].insert(cur);
		}
		ans+=*mapa[i].begin();
		//ve.pb(*mapa[i].begin());
	}
	/*for(auto it:mapa)
	{
		for(auto it2:it.s)cout<<it2<<" ";
		cout<<endl;
	}*/
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
ll ans;
main()
{
	FX iOS
	ll i,j,n,k,m,l;
	cin>>n>>k>>l;
	m=n*1ll*k;
	ll a[m];
	multiset<ll>se;
	for(i=0;i<m;++i)cin>>a[i],se.insert(a[i]);
	sort(a,a+m);
	vector<ll>ve;
	for(i=m-k;i>=0;i-=k)
	{
		auto it=se.upper_bound(a[0]+l);
		if(it!=se.begin())
		{
		--it;
		se.erase(se.find(*it));
		int best=*it;
		if(a[i]>best)a[i]=best;
		ve.pb(a[i]);
		ans+=a[i];
		}
		else return cout<<0,0;
	}
	//for(auto it:ve)cout<<it<<" ";
	if(ve[n-1]-ve[0]>l)return cout<<0,0;
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
ll ans;
main()
{
	FX iOS
	ll i,j,n,k,m,l;string s;
	cin>>n>>k>>l;
	m=n*k;
	ll a[m];
	multiset<ll>se;
	for(i=0;i<m;++i)cin>>a[i],se.insert(a[i]);
	sort(a,a+m);
	for(i=m-k;i>=0;i-=k)
	{
		auto it=se.upper_bound(a[0]+l);
		if(it!=se.begin())
		{
		--it;
		int best=*it;
		se.erase(se.find(*it));
		if(a[i]>best)a[i]=best;
		ans+=a[i];
		}
		else return cout<<0,0;
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
ll ans;
main()
{
	FX iOS
	int i,j,n,k,m,l;string s;
	cin>>n>>k>>l;
	m=n*k;
	int a[m];
	multiset<int>se;
	for(i=0;i<m;++i)cin>>a[i],se.insert(a[i]);
	sort(a,a+m);
	vector<int>ve;
	for(i=m-k;i>=0;i-=k)
	{
		auto it=se.upper_bound(a[0]+l);
		if(it!=se.begin())
		{
		--it;
		se.erase(se.find(*it));
		int best=*it;
		if(a[i]>best)a[i]=best;
		ve.pb(a[i]);
		ans+=a[i];
		}
		else return cout<<0,0;
	}
	//for(auto it:ve)cout<<it<<" ";
	if(ve[n-1]-ve[0]>l)return cout<<0,0;
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
ll ans;
main()
{
	FX iOS
	int i,j,n,k,m,l;string s;
	cin>>n>>k>>l;
	m=n*k;
	int a[m];
	for(i=0;i<m;++i)cin>>a[i];
	sort(a,a+m);
	int best=a[0]+l;
	multiset<int>good,bad;
	for(i=0;i<m;++i)
	{
		if(a[i]>best)bad.insert(a[i]);
		else good.insert(a[i]);
	}
	if((int)good.size()<n)return cout<<0,0;
	for(i=m-k;i>=0;i-=k)
	{
		if(a[i]-a[0]>l)
		{
			a[i]=*(--good.end());
			good.erase(--good.end());
		}
		ans+=a[i];
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
ll ans;
main()
{
	FX iOS
	ll i,j,n,k,m,l;
	cin>>n>>k>>l;
	m=n*1ll*k;
	ll a[m];
	multiset<ll>se;
	for(i=0;i<m;++i)cin>>a[i],se.insert(a[i]);
	sort(a,a+m);
	for(i=m-k;i>=0;i-=k)
	{
		auto it=se.upper_bound(a[0]+l);
		if(it!=se.begin())
		{
		--it;
		int best=*it;
		se.erase(se.find(*it));
		if(a[i]>best)a[i]=best;
		ans+=a[i];
		}
		else return cout<<0,0;
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
ll ans;
main()
{
	FX iOS
	int i,j,n,k,m,l;
	cin>>n>>k>>l;
	m=n*k;
	int a[m];
	for(i=0;i<m;++i)cin>>a[i];
	sort(a,a+m);
	int good=a[0]+l;
	vector<int>ve;
	for(i=0;i<m;++i)
		if(a[i]<=good)ve.pb(a[i]);
	if((int)ve.size()<n)return cout<<0,0;
	int cnt=0;
	for(i=0;i<(int)ve.size();i+=k)
	{
		if(cnt+1+(int)ve.size()-i>n)ans+=ve[i];
		else break;
	}
	for(;i<(int)ve.size();++i)ans+=ve[i];
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
int ans;
main()
{
	FX iOS
	int i,j,n,k,m,l;string s;
	cin>>n>>k>>l;
	m=n*k;
	int a[m];
	for(i=0;i<m;++i)cin>>a[i];
	sort(a,a+m);
	int best=a[0]+l;
	multiset<int>good,bad;
	for(i=0;i<m;++i)
	{
		if(a[i]>best)bad.insert(a[i]);
		else good.insert(a[i]);
	}
	if((int)good.size()<n)return cout<<0,0;
	for(i=m-k;i>=0;i-=k)
	{
		if(a[i]-a[0]>l)
		{
			a[i]=*(--good.end());
			good.erase(--good.end());
		}
		ans+=a[i];
	}
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
int ans;
main()
{
	FX iOS
	int i,j,n,k,m,l;string s;
	cin>>n>>k>>l;
	m=n*k;
	int a[m];
	multiset<int>se;
	for(i=0;i<m;++i)cin>>a[i],se.insert(a[i]);
	sort(a,a+m);
	vector<int>ve;
	for(i=m-k;i>=0;i-=k)
	{
		auto it=se.upper_bound(a[0]+l);
		if(it!=se.begin())
		{
		--it;
		se.erase(se.find(*it));
		int best=*it;
		if(a[i]>best)a[i]=best;
		ve.pb(a[i]);
		ans+=a[i];
		}
		else return cout<<0,0;
	}
	//for(auto it:ve)cout<<it<<" ";
	if(ve[n-1]-ve[0]>l)return cout<<0,0;
	cout<<ans;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
ll ans;
main()
{
	FX iOS
	int i,j,n,k,m,l;
	cin>>n>>k>>l;
	m=n*k;
	int a[m];
	for(i=0;i<m;++i)cin>>a[i];
	sort(a,a+m);
	int good=a[0]+l;
	vector<int>ve;
	for(i=0;i<m;++i)
		if(a[i]<=good)
			ve.pb(a[i]);
	if((int)ve.size()<n)return cout<<0,0;
	int cnt=0;i=0;
	for(i=(int)ve.size()-1;i>=0;--i)
	{
		int cur=((int)ve.size()-cnt)/k;
		cur+=cnt;
		if(cur<n)ans+=ve[i],cnt++;
		else break;
	}
	for(i=0;cnt<n;i+=k)
		ans+=ve[i],
		cnt++;
	cout<<ans;

}


#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
const long double eps=0.00000001;
const long long MOD=1e9+7;
using namespace std;
ll ans;
map<int,multiset<int>>mapa;
main()
{
	FX iOS
	int i,j,n,k,m,l;
	cin>>n>>k>>l;
	m=n*k;
	int a[m];
	for(i=0;i<m;++i)cin>>a[i];
	sort(a,a+m);
	int best=a[0]+l;
	int cnt=0,cur=0;
	multiset<pii>good;
	for(i=0;i<m;++i)
	{
		if(cnt==k)cur++,cnt=0;
		mapa[cur].insert(a[i]);
		if(a[i]<=best)
			good.insert({a[i],cur});
		cnt++;
	}
	/*for(auto it:good)cout<<it.f<<" ";
	cout<<good.size();*/
	if((int)good.size()<n)return cout<<0,0;
	vector<int>ve;
	for(i=n;i>=0;--i)
	{
		if(*mapa[i].begin()>best)
		{
			auto it=*(--good.end());
			int cur=it.f;
			mapa[it.s].insert(*mapa[i].begin());
			mapa[it.s].erase(mapa[it.s].find(it.f));
			mapa[i].erase(mapa[i].begin());
			mapa[i].insert(cur);
		}
		ans+=*mapa[i].begin();
		//ve.pb(*mapa[i].begin());
	}
	/*for(auto it:mapa)
	{
		for(auto it2:it.s)cout<<it2<<" ";
		cout<<endl;
	}*/
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k, l, arr[(int)1e5];
    scanf("%d%d%d", &n, &k, &l);
    for (int i = 0; i < n*k; i++)
        scanf("%d", &arr[i]);
    sort(arr, arr+n*k);
    int lo = 0;
    while (lo < n*k-1 && arr[lo+1]-arr[0] <= l)
        lo++;
    if (lo < n-1)
    {
        printf("0");
        return 0;
    }
    long long sum = 0; int r = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += arr[r];
        if (r+k < lo && lo-(r+k)+1 >= n-i)
            r += k;
        else
            r++;
    }
    printf("%lld", sum);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k, l; long long arr[(int)1e5];
    scanf("%d%d%d", &n, &k, &l);
    for (int i = 0; i < n*k; i++)
        scanf("%d", &arr[i]);
    sort(arr, arr+n*k);
    int lo = 0;
    while (lo < n*k-1 && arr[lo+1]-arr[0] <= l)
        lo++;
    if (lo < n-1)
    {
        printf("0");
        return 0;
    }
    long long sum = 0; int r = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += arr[r];
        if (r+k <= lo && lo-(r+k)+1 >= n-i)
            r += k;
        else
            r++;
    }
    printf("%I64d", sum);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k, l; int arr[(int)1e5];
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
        cin >> arr[i];
    sort(arr, arr+n*k);
    int lo = 0;
    while (lo < n*k-1 && arr[lo+1]-arr[0] <= l)
        lo++;
    if (lo < n-1)
    {
        cout << 0;
        return 0;
    }
    long long sum = 0; int r = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += arr[r];
        if (r+k <= lo && lo-(r+k)+1 >= n-i)
            r += k;
        else
            r++;
    }
    cout << 1LL*sum;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n, k, l, arr[(int)1e5], all[(int)1e5]; vector<int> ve; double m = 0;

void fast();

int main()
{
    fast();
    memset(all, 0, sizeof all);
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
    {
        int a;
        cin >> a;
        ve.push_back(a);
    }
    sort(ve.begin(), ve.end()); int lo = 0, hi = n*k-1;
    for (int i = 0; i < n; i++)
    {
        int d = k;
        if (d%2 == 0 || d > 1)
        {
            arr[i] = all[i] = ve[lo];
            lo += d/2; hi -= d/2;
            if (d % 2 == 1)
                ve.erase(ve.begin()+(hi+lo)/2);
        }
        else
        {
            all[i] = arr[i] = ve[(hi+lo)/2];
            ve.erase(ve.begin()+(hi+lo)/2);
        }
    }
    sort(all, all+n);
    if (all[n-1]-all[0] > l)
    {
        cout << 0;
        return 0;
    }
    for (int i = 0; i < n; i++)
        m += arr[i];
    cout << m;

    return 0;
}

void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k, l; int arr[(int)1e5];
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
        cin >> arr[i];
    sort(arr, arr+n*k);
    int lo = 0;
    while (lo < n*k-1 && arr[lo+1]-arr[0] <= l)
        lo++;
    if (lo < n-1)
    {
        cout << 0;
        return 0;
    }
    long long sum = 0; int r = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += arr[r];
        if (r+k <= lo && lo-(r+k)+1 >= n-i)
            r += k;
        else
            r = lo-(n-i)+1;
    }
    cout << 1LL*sum;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n, k, l; unsigned long long all[(int)1e5], arr[(int)1e5]; vector<int> ve; double m = 0;

void fast();

int main()
{
    fast();
    memset(arr, 0, sizeof arr);
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
    {
        int a;
        cin >> a;
        ve.push_back(a);
        m += a;
    }
    m /= n;
    sort(ve.begin(), ve.end()); int lo = 0, hi = n*k-1;
    for (int i = 0; i < n; i++)
    {
        int d = k;
        if (d%2 == 0 || d > 1)
        {
            all[i] = ve[lo];
            while (d > 1)
            {
                arr[i] += ve[lo++]+ve[hi--];
                d-=2;
            }
            if (d == 1)
            {
                if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[(hi+lo)/2+1]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+(hi+lo)/2+1);
                hi--;
            }
        }
        else
        {
            all[i] = arr[i] = (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]-m)? ve[(hi+lo)/2] : ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]);
            if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0));
            hi--;
        }
    }
    sort(all, all+n);
    if (all[n-1]-all[0] > l)
    {
        cout << 0;
        return 0;
    }
    unsigned long long d = 0;
    for (int i = 0; i < n; i++)
        d += all[i];
    cout << d;

    return 0;
}

void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n, k, l, arr[(int)1e5]; unsigned long long all[(int)1e5]; vector<int> ve; double m = 0;

void fast();

int main()
{
    fast();
    memset(arr, 0, sizeof arr);
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
    {
        int a;
        cin >> a;
        ve.push_back(a);
        m += a;
    }
    m /= n;
    sort(ve.begin(), ve.end()); int lo = 0, hi = n*k-1;
    for (int i = 0; i < n; i++)
    {
        int d = k;
        if (d%2 == 0 || d > 1)
        {
            all[i] = ve[lo];
            while (d > 1)
            {
                arr[i] += ve[lo++]+ve[hi--];
                d-=2;
            }
            if (d == 1)
            {
                if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[(hi+lo)/2+1]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+(hi+lo)/2+1);
                hi--;
            }
        }
        else
        {
            all[i] = arr[i] = (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]-m)? ve[(hi+lo)/2] : ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]);
            if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0));
            hi--;
        }
    }
    sort(all, all+n);
    if (all[n-1]-all[0] > l)
    {
        cout << 0;
        return 0;
    }
    m = 0;
    for (int i = 0; i < n; i++)
        m += all[i];
    cout << m;

    return 0;
}

void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n, k, l; unsigned long long all[(int)1e5], arr[(int)1e5]; vector<int> ve; double m = 0;

void fast();

int main()
{
    fast();
    memset(arr, 0, sizeof arr);
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
    {
        int a;
        cin >> a;
        ve.push_back(a);
        m += a;
    }
    m /= n;
    sort(ve.begin(), ve.end()); int lo = 0, hi = n*k-1;
    for (int i = 0; i < n; i++)
    {
        int d = k;
        if (d%2 == 0 || d > 1)
        {
            all[i] = ve[lo];
            while (d > 1)
            {
                arr[i] += ve[lo++]+ve[hi--];
                d-=2;
            }
            if (d == 1)
            {
                if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[(hi+lo)/2+1]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+(hi+lo)/2+1);
                hi--;
            }
        }
        else
        {
            all[i] = arr[i] = (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]-m)? ve[(hi+lo)/2] : ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]);
            if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0));
            hi--;
        }
    }
    sort(all, all+n);
    if (all[n-1]-all[0] > l)
    {
        cout << 0;
        return 0;
    }
    long long d;
    for (int i = 0; i < n; i++)
        d += all[i];
    cout << d;

    return 0;
}

void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k, l, arr[(int)1e5];
    scanf("%d%d%d", &n, &k, &l);
    for (int i = 0; i < n*k; i++)
        scanf("%d", &arr[i]);
    sort(arr, arr+n*k);
    int lo = 0;
    while (lo < n*k-1 && arr[lo+1]-arr[0] <= l)
        lo++;
    if (lo < n-1)
    {
        printf("0");
        return 0;
    }
    long long sum = 0; int r = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += arr[r];
        if (r+k <= lo && lo-(r+k)+1 >= n-i)
            r += k;
        else
            r++;
    }
    printf("%lld", sum);

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n, k, l, arr[(int)1e5]; unsigned long long all[(int)1e5]; vector<int> ve; double m = 0;

void fast();

int main()
{
    fast();
    memset(arr, 0, sizeof arr);
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
    {
        int a;
        cin >> a;
        ve.push_back(a);
        m += a;
    }
    m /= n;
    sort(ve.begin(), ve.end()); int lo = 0, hi = n*k-1;
    for (int i = 0; i < n; i++)
    {
        int d = k;
        if (d%2 == 0 || d > 1)
        {
            all[i] = ve[lo];
            while (d > 1)
            {
                arr[i] += ve[lo++]+ve[hi--];
                d-=2;
            }
            if (d == 1)
            {
                if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[(hi+lo)/2+1]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+(hi+lo)/2+1);
                hi--;
            }
        }
        else
        {
            all[i] = arr[i] = (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]-m)? ve[(hi+lo)/2] : ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]);
            if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0));
            hi--;
        }
    }
    sort(all, all+n);
    if (all[n-1]-all[0] > l)
    {
        cout << 0;
        return 0;
    }
    m = 0;
    for (int i = 0; i < n; i++)
        m += all[i];
    cout << (long long int)m;

    return 0;
}

void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n, k, l, arr[(int)1e5], all[(int)1e5]; vector<int> ve; double m = 0;

void fast();

int main()
{
    fast();
    memset(all, 0, sizeof all);
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
    {
        int a;
        cin >> a;
        ve.push_back(a);
    }
    sort(ve.begin(), ve.end()); int lo = 0, hi = n*k-1;
    for (int i = 0; i < n; i++)
    {
        int d = k;
        if (d%2 == 0 || d > 1)
        {
            arr[i] = all[i] = ve[lo];
            lo += d/2; hi -= d/2;
            if (d % 2 == 1)
                ve.erase(ve.begin()+(hi+lo)/2);
        }
        else
            all[i] = arr[i] = ve[(hi+lo)/2];
    }
    sort(all, all+n);
    if (all[n-1]-all[0] > l)
    {
        cout << 0;
        return 0;
    }
    for (int i = 0; i < n; i++)
        m += arr[i];
    cout << m;

    return 0;
}

void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, k, l, arr[(int)1e5];
    scanf("%d%d%d", &n, &k, &l);
    for (int i = 0; i < n*k; i++)
        scanf("%d", &arr[i]);
    sort(arr, arr+n*k);
    int lo = 0;
    while (lo < n*k-1 && arr[lo+1]-arr[0] <= l)
        lo++;
    if (lo < n-1)
    {
        printf("0");
        return 0;
    }
    int sum = 0, r = 0;
    for (int i = 1; i <= n; i++)
    {
        sum += arr[r];
        if (r+k < lo && lo-(r+k)+1 >= n-i)
            r += k;
        else
            r++;
    }
    printf("%d", sum);

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n, k, l, arr[(int)1e5], all[(int)1e5]; vector<int> ve; double m = 0;

void fast();

int main()
{
    fast();
    memset(arr, 0, sizeof arr);
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
    {
        int a;
        cin >> a;
        ve.push_back(a);
        m += a;
    }
    m /= n;
    sort(ve.begin(), ve.end()); int lo = 0, hi = n*k-1;
    for (int i = 0; i < n; i++)
    {
        int d = k;
        if (d%2 == 0 || d > 1)
        {
            all[i] = ve[lo];
            while (d > 1)
            {
                arr[i] += ve[lo++]+ve[hi--];
                d-=2;
            }
            if (d == 1)
            {
                if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[(hi+lo)/2+1]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+(hi+lo)/2+1);
                hi--;
            }
        }
        else
        {
            all[i] = arr[i] = (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]-m)? ve[(hi+lo)/2] : ve[((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0)]);
            if (abs(arr[i]+ve[(hi+lo)/2]-m) < abs(arr[i]+ve[(hi+lo)/2+1]-m))
                    ve.erase(ve.begin()+(hi+lo)/2);
                else
                    ve.erase(ve.begin()+((hi+lo)/2+1 < ve.size()-1? (hi+lo)/2+1 : 0));
            hi--;
        }
    }
    sort(all, all+n);
    if (all[n-1]-all[0] > l)
    {
        cout << 0;
        return 0;
    }
    m = 0;
    for (int i = 0; i < n; i++)
        m += all[i];
    cout << m;

    return 0;
}

void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n, k, l, arr[(int)1e5], all[(int)1e5]; vector<int> ve; double m = 0;

void fast();

int main()
{
    fast();
    memset(all, 0, sizeof all);
    cin >> n >> k >> l;
    for (int i = 0; i < n*k; i++)
    {
        int a;
        cin >> a;
        ve.push_back(a);
    }
    sort(ve.begin(), ve.end()); int lo = 0, hi = n*k-1;
    for (int i = 0; i < n; i++)
    {
        int d = k;
        if (d%2 == 0 || d > 1)
        {
            arr[i] = all[i] = ve[lo];
            lo += d/2; hi -= d/2;
            d -= (d/2);
            d -= d/2;
            if (d == 1)
                ve.erase(ve.begin()+(hi+lo)/2);
        }
        else
            all[i] = arr[i] = ve[(hi+lo)/2];
    }
    sort(all, all+n);
    for (int i = 0; i < n-1; i++)
    {
        if (all[i+1]-all[i] > l)
        {
            cout << 0;
            return 0;
        }
    }
    for (int i = 0; i < n; i++)
        m += arr[i];
    cout << m;

    return 0;
}

void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}