#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int iz=100005;
const long long inf=2e15;
typedef long long ll;
int x,y,s,t,n,m;
int u,v,tot=0;
ll e[1005][1005],w[iz<<1],dis[1005],p;
int Head[1005],Next[iz<<1],to[iz<<1];

inline void add(int q,int r,int k){
	to[++tot]=r; w[tot]=k;
	Next[tot]=Head[q];
	Head[q]=tot;
}
struct Heap{
	long long d;
	int id;
	bool operator < (const Heap &a) const{
		return d>a.d;
	}
}z;
priority_queue<Heap> q;

void Floyd(){
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            if(k!=i){
                int t=(k<i)?e[i][k]:e[k][i];
                if(t==inf) continue;
                for(int j=1;j<=((k<i)?k:i);j++){
                    if(t+e[k][j]<e[i][j])e[i][j]=t+e[k][j];
                }
                for(int j=k+1;j<=i;j++){
                    if(t+e[j][k]<e[i][j])e[i][j]=t+e[j][k];
                }
            }
        }
    }
    return ;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		dis[i]=inf;
		for(int j=1;j<=n;j++)e[i][j]=inf;
	}
	scanf("%d%d",&s,&t);
	for(int i=1;i<=m;i++){
		scanf("%d%d%I64d",&u,&v,&p);
//		printf("%I64d\n",e[u][v]);
		e[u][v]=e[v][u]=min(e[u][v],p);
	}
	for(int i=1;i<=n;i++)e[i][i]=0;
	Floyd();
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x,&y);
		for(int j=1;j<=n;j++){
			if(e[i][j]<=x && i!=j){
				add(i,j,y);
			}
		}
	}
	z.id=s; z.d=0; q.push(z); dis[s]=0;
	while(!q.empty()){
		if(dis[q.top().id]!=q.top().d){q.pop(); continue;}
		z=q.top(); q.pop();
		for(int i=Head[z.id];i;i=Next[i]){
			if(dis[to[i]]>dis[z.id]+w[i]){
				dis[to[i]]=dis[z.id]+w[i];
				q.push((Heap){dis[to[i]],to[i]});
			}
		}
	}
	if(dis[t]==inf)printf("-1");
	else printf("%I64d",dis[t]);
}


#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int iz=200005;
const long long inf=2e15;
const int iz2=1005;
typedef long long ll;
int x,y,s,t,n,m;
int u,v,tot=0;
ll e[1005][1005],w[iz<<1],dis[1005],p;
int Head[1005],Next[iz<<1],to[iz<<1];
int H2[1005],N2[iz2<<1],t2[iz2<<1],w2[iz2<<1];
ll d[1005],vis[1005];

inline void add(int q,int r,int k){
    to[++tot]=r; w[tot]=k;
    Next[tot]=Head[q];
    Head[q]=tot;
}
inline void A2(int q,int r,int k){
    t2[++tot]=r; w2[tot]=k;
    N2[tot]=H2[q];
    H2[q]=tot;
}
struct Heap{
    long long d;
    int id;
    bool operator < (const Heap &a) const{
        return d>a.d;
    }
}z;
priority_queue<Heap> q;

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        dis[i]=inf;
	}
    tot=0;
    scanf("%d%d",&s,&t);
    for(int i=1;i<=m;i++){
        scanf("%d%d%I64d",&u,&v,&p);
        A2(u,v,p); A2(v,u,p);
    }
    tot=0;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x,&y);
        for(int j=1;j<=n;j++)d[j]=inf;
        memset(vis,0,sizeof(vis));
        q.push((Heap){0,i}); d[i]=0;
        while(!q.empty()){
            if(vis[q.top().id]){q.pop(); continue;}
            z=q.top(); q.pop();
            for(int j=H2[z.id];j;j=N2[j]){
                if(!vis[t2[j]] && d[t2[j]]>d[z.id]+w2[j]){
                    d[t2[j]]=d[z.id]+w2[j];
                    q.push((Heap){d[t2[j]],t2[j]});
                }
            }
        }
        for(int j=1;j<=n;j++){
            if(d[j]<=x && i!=j){
                add(i,j,y);
            }
        }
    }
    z.id=s; z.d=0; q.push(z); dis[s]=0;
    memset(vis,0,sizeof(vis));
    while(!q.empty()){
        if(vis[q.top().id]){q.pop(); continue;}
        z=q.top(); q.pop();
        for(int i=Head[z.id];i;i=Next[i]){
            if(!vis[to[i]] && dis[to[i]]>dis[z.id]+w[i]){
                dis[to[i]]=dis[z.id]+w[i];
                q.push((Heap){dis[to[i]],to[i]});
            }
        }
    }
    if(dis[t]==inf)printf("-1");
    else printf("%I64d",dis[t]);
}


import sys
rawdata = sys.stdin.read()
data = int(n) for n in rawdata.split()
print(data)
print(data[0]*3)


temp = input().split()
votes = temp[0]*3
arr = ()
for i in range(len(temp)-1):
    arr[i+1] = int(temp[i+1])
print(arr)


import sys
rawdata = sys.stdin.read()
data = list(int(n) for n in rawdata.split())
submissions = data[0]*3
correct = 0
positive=0
for i in range(1,submissions,3):
    positive = data[i] + data[i+1] + data[i+2]
    if(positive>1):
        correct= correct+1
print(correct)


import sys

rawdata = sys.stdin.readline
def inp():
    return(int(rawdata()))
data = inp()
print(data)
print(data[0]*3)


import sys

testCase = sys.stdin.read()
print(testCase)


problems = int(input())
solutions = input().split()
print(problems)
print(solutions)


import sys
rawdata = sys.stdin.readline()
data = (int(n) for n in rawdata.split(" "))
print(data)


import sys
data = sys.stdin.read()
print(data)
print(data[0]*3)


import sys
data = sys.stdin.int(read())
print(data)


import sys

rawdata = sys.stdin.readline
data = return(int(rawdata()))
print(data)
print(data[0]*3)


problems = int(input())
votes = problems * 3
arr = int(input()).split()
print(arr)


import sys
rawdata = sys.stdin.read()
data = (int(n) for n in rawdata.split())
print(data)
print(data[0]*3)


import sys
import numpy as np
rawdata = raw_input()
data = (int(n) for n in rawdata.strip().split(" "))
print(data)
print(data[0]*3)


import sys
rawdata = sys.stdin.readline()
data = (int(n) for n in rawdata.strip().split(" "))
print(data)#test


temp = input().split()
votes = temp[0]*3
arr = ()
for i in range(len(temp)-1):
    arr[i+1] = int(temp[i+1])#test
print(arr)


import sys
testCase = sys.stdin.read()
dataString = testCase.split()
data = []
for i in range(len(dataString)):
    data[i] = int(dataString[i])
submissions = data[0]*3
passedSol = 0
for i in range(1,submissions):
    if(i%3==0&i<submissions-2):
        sol = data[i]+data[i+1]+data[i+2]
        if(sol>1):
            passedSol++
print(passedSol)


temp = input().split()
votes = temp[0]*3
arr = []
for i in range(len(temp)-1):
    arr[i+1].append(int(temp[i+1]))
print(arr)


import sys
testCase = sys.stdin.read()
data = testCase.split()
print(testCase,data)


import sys
rawdata = sys.stdin.readline()
data = (int(n) for n in rawdata.strip().split(" "))
print(data)


import sys
rawdata = sys.stdin.readline
print(rawdata)


problems = int(input())
votes = problems * 3
temp = input().split()
arr = []
for i in range(len(temp)):
    arr[i] = int(temp[i])
print(arr)


import sys
testCase = sys.stdin.read()
dataString = testCase.split()
data = []
for i in range(len(dataString)):
    data[i] = int(dataString[i])
submissions = data[0]*3
passedSol = 0
for i in range(1,submissions):
    if(i%3==0&i<submissions-2):
        sol = data[i]+data[i+1]+data[i+2]
        if(sol>1):
            passedSol+=1
print(passedSol)


import sys
import numpy as np
rawdata = raw_input()
data = (int(n) for n in rawdata.split())
print(data)


#include <iostream>

using namespace std;

void func(int m)
{
	int submission = 0;
	int n = m * 3;
	int* arr = new int[n];
	//int arr[] = { 1, 0, 0,0, 1, 0,1, 1, 1,0, 0, 1,0, 0 ,0 };

	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		int count = 0;
		if (i % 3 == 0 && i <= n - 3 && n != 3)
		{
			count += arr[i] + arr[i + 1] + arr[i + 2];
		}
		if (count > 1)
		{
			submission++;
		}
	}
	cout << submission;
}

int main()
{
	int m;
	cin >> m;
	//int m = 5;
	func(m);
}


import sys
rawdata = sys.stdin.readline()
print(rawdata)


problems = int(input())
solutions = input().split()
for i in range(problems):
    solutions.append(input().split())
print(problems)
print(solutions)


import sys
rawdata = sys.stdin.read()
data = (int(n) for n in rawdata.split())
print(data)


import sys
rawdata = sys.stdin.read()
data = (int(n) for n in rawdata.split())
print(rawdata)


rawdata = raw_input()
data = (int(n) for n in rawdata.split())
print(data)
print(data[0]*3)


temp = input().split()
votes = temp[0]*3
arr = []
for i in range(len(temp)-1):
    arr[i+1] = int(temp[i+1])
print(arr)


import sys
rawdata = sys.stdin.readline()
print(data)


import sys
data = sys.stdin.read()
print(data)


import sys
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
print(inp())


inputAdeti = int (input(""))

i=1
while i<=inputAdeti:
    inputlar= input("")
    sayaç=0
    for x in inputlar:
        if x == 1:
            sayaç+=1
        print(x)
    i+=1


inputAdeti = int (input(""))

i=1
while i<=inputAdeti:
    inputlar= input("")
    sayac=0
    for x in inputlar:
        if x == 1:
            sayac+=1
        print(x)
    i+=1


inputAdeti = int (input(""))

i=1
while i<=inputAdeti:
    inputlar= input("")
    sayac=0
    for x in inputlar:
        if x == '1':
            sayac+=1
    print(sayac)
    i+=1


inputAdeti = int (input(""))

sonuc=0
i=1
while i<=inputAdeti:
    inputlar= input("")
    sayac=0
    for x in inputlar:
        if x == '1':
            sayac+=1
    if sayac>=2:
        sonuc+=1
    i+=1
print(sonuc)


# -*- coding: utf-8 -*-
"""
Created on Sun Oct 18 14:08:51 2020

@author: pinky
"""

n=int(input())
sol=0
for i in range (n):
    a,b,c=[int(x) for x in range(input().split())]
    if a+b+c>1:
        sol=sol+1

print(sol)


# -*- coding: utf-8 -*-
"""
Created on Sun Oct 18 14:08:51 2020

@author: pinky
"""

n=input(int())
sol=0
for i in range (n):
    a,b,c=[int(x) for x in range(input().split())]
    if a+b+c>1:
        sol=sol+1

        print(sol)


# -*- coding: utf-8 -*-
"""
Created on Sun Oct 18 14:08:51 2020

@author: pinky
"""

n=int(input())
sol=0
for i in range(n):
    a,b,c=[int(x) for x in range(input().split())]
    if a+b+c>1:
        sol=sol+1

print(sol)


# -*- coding: utf-8 -*-
"""
Created on Sun Oct 18 14:08:51 2020

@author: pinky
"""

n=int(input())
sol=0
for i in range (n):
    a,b,c=[int(x) for x in range(input().split())]
    if a+b+c>1:
        sol=sol+1

        print(sol)


# -*- coding: utf-8 -*-
"""
Created on Sun Oct 18 14:08:51 2020

@author: pinky
"""

n=int(input())
sol=0
for i in range (n):
    a,b,c=[int(x) for x in range(input().split())]
    if a+b+c>1:
        sol+=1

print(sol)


# -*- coding: utf-8 -*-
"""
Created on Sun Oct 18 14:08:51 2020

@author: pinky
"""

n=int(input())
sol=0
for i in range(n):
    a,b,c=[int(x) for x in (input().split())]
    if a+b+c>1:
        sol=sol+1

print(sol)


count = 0

"""
for i in range(int(input())):
    if input().split().count('1') >= 2:
        count+=1
print(count)

"""
for i in range(int(input())):
    rep = 0
    for i in input():
        if i == "1":
            rep+=1
    if rep>=2:
        count+=1
print(count)


count = 0

#"""
for i in range(int(input())):
    if input().split().count('1') >= 2:
        count+=1
print(count)

"""
for i in range(int(input())):
    rep = 0
    for i in input():
        if i == "1":
            rep+=1
    if rep>=2:
        count+=1
print(count)

"""


count = 0

for i in range(int(input())):
    if input().split().count('1') >= 2:
        count+=1
print(count)


print(sum(input().count('1')>1 for x in range(int(input()))))


n=int(input())
Number_of_solutions=0
for i in range(n):
    P,V,T=int(input()),int(input()),int(input())
    y=P+V+T
    if y>=2:
       Number_of_solutions+=1
print(Number_of_solutions)


n=int(input())
Number_of_solutions=0
for i in range(1,n+1):
    print(i)
    P, V, T=int(input()), int(input()), int(input())
    y=P+V+T
    if y>=2:
       Number_of_solutions+=1
print(Number_of_solutions)


n=int(input())
Number_of_solutions=0
for i in range(n):
    P,V,T=(int(input()),int(input()),int(input()))
    y=P+V+T
    if y>=2:
       Number_of_solutions+=1
print(Number_of_solutions)


n=int(input())
y,Number_of_solutions=0,0
for i in range(1,n+1):
    P,V,T=input('Petya: '), input('Vasya: '), input('Tonya: ')
    y=int(P)+int(V)+int(T)
    if y>=2:
       Number_of_solutions+=1
print(Number_of_solutions)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
list1 = input().split()
list1 = list(map(int,list1)) #
k = 0
n = list[0]
for m in range(1,3*n,3):
    if list1[m] + list1[m+1] + list1[m+2] >= 2:
        k +=1
print(k)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
list1 = input().split()
list1 = list(map(int,list1))
k = 0
for m in range(0,3*n,3):
    if list1[m] + list1[m+1] + list1[m+2] >= 2:
        k +=1
print(k)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
list1 = input().split()
list1 = list(map(int,list1))
k = 0
n = list[0]
for m in range(1,3*n,3):
    if list1[m] + list1[m+1] + list1[m+2] >= 2:
        k += 1
print(k)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
list1 = input().split()
list1 = list(map(int,list1))
k = 0
n = list1[0]
for m in range(1,3*n,3):
    if list1[m] + list1[m+1] + list1[m+2] >= 2:
        k += 1
print(k)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
list1 = input().split()
list1 = list(map(int,list1)) #
k = 0
for m in range(0,3*n,3):
    if list1[m] + list1[m+1] + list1[m+2] >= 2:
        k +=1
print(k)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
k = 0
for m in range(0,n):
    list1 = input().split()
    list1 = list(map(int, list1))
    if list1[0] + list1[1] + list1[2] >= 2:
        k += 1
print(k)


n = int(input())
counter = 0
for i in range(n):
    x,y,z = map(int, input().split(" "))
    sum = x+y+z
    if sum >= 2:
        counter += 1

print(counter)


n = int(input())
counter = 0
for i in range(0, n):
    x,y,z = map(int, input().split(" "))
    if sum(x, y, z) >= 2:
        counter += 1

print(counter)


n = input()
counter = 0
while n:
    x,y,z = map(int, input().split(' '))
    if x + y + z > 1:
        counter +=1
    n-=1

print(counter)


n = input()
counter = 0
i=0
while i < n:
    x,y,z = map(input.split(' '))
    if x + y + z > 1:
        counter +=1
    i+=1

print(counter)


n = input()
counter = 0
while n:
    x,y,z = map(input.split(' '))
    if x + y + z > 1:
        counter +=1
    n-=1

print(counter)


t=input()
q=0
for i in range(0,t):
	if sum(map(int,input().strip().split(" ")))>=2:
		q+=1
print(q)


def solve(n, problems):
    solved = 0
    for problem in problems:
        if problem.count('1') > 1:
            solved += 1

    return solved

if __name__ == "__main__":
    problems = list()
    n = int(input)
    number = 0
    while number < n:
        problems.append(input())
    number+=1
    print(solve(n, problems))


n = input()
counter = 0
for i in range(t):
    x,y,z = map(int, input().split(" "))
    if sum(x, y, z) >= 2:
        counter += 1

print counter


n = input()
counter = 0
for i in range(t):
    x,y,z = map(int, input().split(" "))
    if sum(x, y, z) >= 2:
        counter += 1

print(counter)


n = input()
counter = 0
while i < n:
    x,y,z = map(input.split(' '))
    if x + y + z > 1:
        counter +=1

print counter


n = input()
counter = 0
while n:
    x,y,z = map(int, input.split(' '))
    if x + y + z > 1:
        counter +=1
    n-=1

print(counter)


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

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=3e5+10;
int n, m,d ;
int a[N] ;
ll pre[N], Ans ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m ;

    for (int i = 1 ; i<= n; i++)
        cin >>a[i];

    sort(a+1, a+1+n) ;
    reverse(a+1, a+1+n) ;
    int I = n+1 ;

    for (int i = 1 ; i<= n; i++)
        pre[i] = a[i] + pre[i-1] ;

    for (int i = 1 ; i<=n ; i++)
        if (a[i] <= m)
        {
            I = i ;
            break;
        }

    if (I == 1)
        return cout<<pre[n],0;
    for (int i = 1 ; i<= n ; i++)
    {
        int x = n - (i-1)*(d+1)-1 ;
        if (x<0 || a[i] <= m)
            break;
        if (x + i > n)
            continue ;
        ll r = pre[i] + pre[min(n, I+x-1 )] - pre[I-1];
        Ans = max(Ans, r) ;
           //cout<<i<<" "<<x<<" "<<r<<" "<<Ans<<"\n";
    }
    cout<<Ans;
}


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

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=3e5+10;
int n, m,d ;
int a[N] ;
ll pre[N], Ans ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m ;

    for (int i = 1 ; i<= n; i++)
        cin >>a[i];

    sort(a+1, a+1+n) ;
    reverse(a+1, a+1+n) ;
    int I = 0 ;

    for (int i = 1 ; i<= n; i++)
        pre[i] = a[i] + pre[i-1] ;

    for (int i = 1 ; i<=n ; i++)
        if (a[i] <= m)
        {
            I = i ;
            break;
        }

    if (I == 1)
        return cout<<pre[n],0;
    for (int i = 1 ; i<= n ; i++)
    {
        int x = n - (i-1)*(d+1)-1 ;
        if (x<0 || a[i] <= m)
            break;
        if (x + i > n)
            continue ;
        ll r = pre[i] + pre[min(n, I+x-1 )] - pre[I-1];
        Ans = max(Ans, r) ;
        //   cout<<i<<" "<<x<<" "<<r<<" "<<Ans<<"\n";
    }
    cout<<Ans;
}


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

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=3e5+10;
int n, m,d ;
int a[N] ;
ll pre[N], Ans ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m ;

    for (int i = 1 ; i<= n; i++)
        cin >>a[i];

    sort(a+1, a+1+n) ;
    reverse(a+1, a+1+n) ;
    int I = 0 ;

    for (int i = 1 ; i<= n; i++)
        pre[i] = a[i] + pre[i-1] ;

    for (int i = 1 ; i<=n ; i++)
        if (a[i] <= m)
        {
            I = i ;
            break;
        }
    if (!I)
        return cout<<pre[n],0;
    for (int i = 1 ; i<= n ; i++)
    {
        int x = n - (i-1)*(d+1)-1 ;
        if (x<0 || a[i] <= m)
            break;
        if (x + i > n)
            continue ;
        ll r = pre[i] + pre[min(n, I+x-1 )] - pre[I-1];
        Ans = max(Ans, r) ;
        //   cout<<i<<" "<<x<<" "<<r<<" "<<Ans<<"\n";
    }
    cout<<Ans ;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    if(l==n)
    {
        cout<<v1[l-1]<<endl;
        return 0;
    }
    d++;
    ll ans=v1[l-1];
    int pos=0;
    int pp=n-2;
    while(pos<v2.size() && pp>=0)
    {
        int x=min(l-1,pp);
        ans=max(ans,v1[x]+v2[pos]);
        pp-=d;
        pos++;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    ll ans=v1[l-1];
    x=(n-1)/(d+1);
    if(x<v2.size());
        ans=max(ans,v2[x]);
    int pos=n-2; int pp=0; d++;
    while(pos>=0 && pp<v2.size())
    {
        x=min(pos,l-1);
        ans=max(ans,v1[x]+v2[pp]);
        pp++;
        pos-=d;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    if(l==n)
    {
        cout<<v1[l-1]<<endl;
        return 0;
    }
    d++;
    ll ans=v1[l-1];
    int pos=0;
    int pp=n-2;
    while(pos<v2.size())
    {
        int x=min(l-1,pp);
        ans=max(ans,v1[x]+v2[pos]);
        pp-=d;
        pos++;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    ll ans=v1[l-1];
    /*x=(n-1)/(d+1);
    if(x<v2.size());
        ans=max(ans,v2[x]);
    cout<<ans<<" "<<x<<endl;*/
    int pos=n-2; int pp=0; d++;
    while(pos>=0 && pp<v2.size())
    {
        x=min(pos,l-1);
        ans=max(ans,v1[x]+v2[pp]);
        pp++;
        pos-=d;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    ll ans=v1[l-1];
    x=(n-1)/(d+1);
    if(x<v2.size());
        ans=max(ans,v2[x]);
    //cout<<ans<<" "<<x<<endl;*/
    int pos=n-2; int pp=0; d++;
    while(pos>=0 && pp<v2.size())
    {
        x=min(pos,l-1);
        ans=max(ans,v1[x]+v2[pp]);
        pp++;
        pos-=d;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    if(l==n)
    {
        cout<<v1[l-1]<<endl;
        return 0;
    }
    d++;
    if(l==0)
    {
        x=(n-1)/d;
        cout<<v2[x]<<endl;
        return 0;
    }
    ll ans=v2[0];
    int pos=0;
    int pp=n-2;
    while(pos<v2.size() && pp>=0)
    {
        x=min(l-1,pp);
        ans=max(ans,v1[x]+v2[pos]);
        pp-=d;
        pos++;
    }
    if(pp==-1)
        ans=max(ans,v2[pos]);
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    ll ans=v1[l-1];
    x=(n-1)/(d+1);
    ans=max(ans,v2[x]);
    int pos=n-2; int pp=0; d++;
    while(pos>=0 && pp<v2.size())
    {
        x=min(pos,l-1);
        ans=max(ans,v1[x]+v2[pp]);
        pp++;
        pos-=d;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    ll ans=v1[l-1];
    int pos=n-2; int pp=0; d++;
    while(pos>=0 && pp<v2.size())
    {
        int x=min(pos,l-1);
        ans=max(ans,v1[x]+v2[pp]);
        pp++;
        pos-=d;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    ll ans=v1[l-1];
    int pos=n-2; int pp=0; d++;
    while(pos>=0 && pp<v2.size())
    {
        int x=min(pos,l-1);
        ans=max(ans,v1[x]+v2[pp]);
        pp++;
        pos-=d;
    }
    if(pp<v2.size())
        ans=max(ans,v2[pp]);
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1350851717672992089
#define ll long long int
#define ld long double
#define pi pair<ll, ll>
#define vi vector<ll>
#define vp vector<pair<ll, ll>>
#define mp make_pair
#define M 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
    int n,d,m,x;
    cin>>n>>d>>m;
    vi v1, v2;
    for (int i=0; i<n; i++)
    {
        cin>>x;
        if(x>m)
            v2.pb(x);
        else
            v1.pb(x);
    }
    sort(v1.begin(), v1.end(), greater<ll>());
    sort(v2.begin(), v2.end(), greater<ll>());
    for (int i=1; i<v1.size(); i++)
        v1[i]+=v1[i-1];
    for (int i=1; i<v2.size(); i++)
        v2[i]+=v2[i-1];
    int l=v1.size();
    if(l==n)
    {
        cout<<v1[l-1]<<endl;
        return 0;
    }
    d++;
    ll ans=v1[l-1];
    int pos=0;
    int pp=n-2;
    while(pos<v2.size() && pp>=0)
    {
        int x=min(l-1,pp);
        ans=max(ans,v1[x]+v2[pos]);
        pp-=d;
        pos++;
    }
    if(pp==-1)
        ans=max(ans,v2[pos]);
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define NULL 0
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define d0(x) cout<<x<<" ";
#define d1(x) cout<<x<<"\n";
#define d2(x,y) cout<<x<<" "<<y<<"\n";
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n";

//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;}
template<typename T, typename U> static inline void amax(T &x, U y){if (y > x)x = y;}

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const  ll mod= 1000000007  ;
const long long inf = (ll)1e18+17;
const int iinf = 1500000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve(){
    ll n,d,m;cin>>n>>d>>m;
    ll a[n+10],sum=0;
    for(int i=0;i<n;i++)cin>>a[i],sum+=a[i];
    sort(a,a+n);
    vector<ll>b,c;
    for(int i=n-1;i>=0;i--){
        if(a[i]>m)c.pb(a[i]);
        else b.pb(a[i]);
    }
    for(int i=1;i<b.size();i++)b[i]+=b[i-1];
    for(int i=1;i<c.size();i++)c[i]+=c[i-1];
    if(c.size()==0){cout<<sum<<endl;return;}
    ll ans=0;
    for(int i=0;i<c.size();i++){
        int rem= n- (i*d+i+1);
        amin(rem,b.size());
        if(rem>b.size() || rem<0)continue;
        if(rem==0){amax(ans,c[i]);continue;}
        amax(ans,c[i]+b[rem-1]);
    }
    cout<<ans<<endl;
}

int main()
{
    clock_t tt;tt = clock();
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    //pre();
    for(int i=1;i<=t;i++){
       //cout<<"Case #"<<i<<": ";
       solve();
    }
    tt = clock() - tt; double time_taken = ((double)tt)/CLOCKS_PER_SEC;
    //printf("code took %f seconds to execute \n", time_taken);
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove ios_base for interactive problems
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define NULL 0
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define d0(x) cout<<x<<" ";
#define d1(x) cout<<x<<"\n";
#define d2(x,y) cout<<x<<" "<<y<<"\n";
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n";

//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;}
template<typename T, typename U> static inline void amax(T &x, U y){if (y > x)x = y;}

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const  ll mod= 1000000007  ;
const long long inf = (ll)1e18+17;
const int iinf = 1500000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve(){
    ll n,d,m;cin>>n>>d>>m;
    ll a[n+10],sum=0;
    for(int i=0;i<n;i++)cin>>a[i],sum+=a[i];
    sort(a,a+n);
    vector<ll>b,c;
    for(int i=n-1;i>=0;i--){
        if(a[i]>m)c.pb(a[i]);
        else b.pb(a[i]);
    }
    for(int i=1;i<b.size();i++)b[i]+=b[i-1];
    for(int i=1;i<c.size();i++)c[i]+=c[i-1];
    if(c.size()==0){cout<<sum<<endl;return;}
    ll ans=0;
    for(int i=0;i<c.size();i++){
        int rem= n- (i*d+i+1);
        if(n<1ll*d*i+i+1)break;
        amin(rem,b.size());
        if(rem>b.size() || rem<0)continue;
        if(rem==0){amax(ans,c[i]);continue;}
        amax(ans,c[i]+b[rem-1]);
    }
    cout<<ans<<endl;
}

int main()
{
    clock_t tt;tt = clock();
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    //pre();
    for(int i=1;i<=t;i++){
       //cout<<"Case #"<<i<<": ";
       solve();
    }
    tt = clock() - tt; double time_taken = ((double)tt)/CLOCKS_PER_SEC;
    //printf("code took %f seconds to execute \n", time_taken);
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove ios_base for interactive problems
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define NULL 0
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define d0(x) cout<<x<<" ";
#define d1(x) cout<<x<<"\n";
#define d2(x,y) cout<<x<<" "<<y<<"\n";
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n";

//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;}
template<typename T, typename U> static inline void amax(T &x, U y){if (y > x)x = y;}

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const  ll mod= 1000000007  ;
const long long inf = (ll)1e18+17;
const int iinf = 1500000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve(){
    ll n,d,m;cin>>n>>d>>m;
    ll a[n+10],sum=0;
    for(int i=0;i<n;i++)cin>>a[i],sum+=a[i];
    sort(a,a+n);
    vector<ll>b,c;
    for(int i=n-1;i>=0;i--){
        if(a[i]>m)c.pb(a[i]);
        else b.pb(a[i]);
    }
    for(int i=1;i<b.size();i++)b[i]+=b[i-1];
    for(int i=1;i<c.size();i++)c[i]+=c[i-1];
    if(c.size()==0){cout<<sum<<endl;return;}
    ll ans=0;
    for(int i=0;i<c.size();i++){
        int rem= n- (i*d+i+1);
        if(rem>b.size())continue;
        amax(ans,c[i]+b[rem-1]);
    }
    cout<<ans<<endl;
}

int main()
{
    clock_t tt;tt = clock();
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    //pre();
    for(int i=1;i<=t;i++){
       //cout<<"Case #"<<i<<": ";
       solve();
    }
    tt = clock() - tt; double time_taken = ((double)tt)/CLOCKS_PER_SEC;
    //printf("code took %f seconds to execute \n", time_taken);
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove ios_base for interactive problems
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define NULL 0
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define d0(x) cout<<x<<" ";
#define d1(x) cout<<x<<"\n";
#define d2(x,y) cout<<x<<" "<<y<<"\n";
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n";

//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;}
template<typename T, typename U> static inline void amax(T &x, U y){if (y > x)x = y;}

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const  ll mod= 1000000007  ;
const long long inf = (ll)1e18+17;
const int iinf = 1500000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve(){
    ll n,d,m;cin>>n>>d>>m;
    ll a[n+10],sum=0;
    for(int i=0;i<n;i++)cin>>a[i],sum+=a[i];
    sort(a,a+n);
    vector<ll>b,c;
    for(int i=n-1;i>=0;i--){
        if(a[i]>m)c.pb(a[i]);
        else b.pb(a[i]);
    }
    for(int i=1;i<b.size();i++)b[i]+=b[i-1];
    for(int i=1;i<c.size();i++)c[i]+=c[i-1];
    if(c.size()==0){cout<<sum<<endl;return;}
    ll ans=0;
    for(int i=0;i<c.size();i++){
        int rem= n- (i*d+i+1);
        amin(rem,b.size());
        if(rem>b.size() )continue;
        if(rem==0){amax(ans,c[i]);continue;}
        amax(ans,c[i]+b[rem-1]);
    }
    cout<<ans<<endl;
}

int main()
{
    clock_t tt;tt = clock();
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    //pre();
    for(int i=1;i<=t;i++){
       //cout<<"Case #"<<i<<": ";
       solve();
    }
    tt = clock() - tt; double time_taken = ((double)tt)/CLOCKS_PER_SEC;
    //printf("code took %f seconds to execute \n", time_taken);
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove ios_base for interactive problems
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define NULL 0
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define d0(x) cout<<x<<" ";
#define d1(x) cout<<x<<"\n";
#define d2(x,y) cout<<x<<" "<<y<<"\n";
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n";

//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;}
template<typename T, typename U> static inline void amax(T &x, U y){if (y > x)x = y;}

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const  ll mod= 1000000007  ;
const long long inf = (ll)1e18+17;
const int iinf = 1500000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve(){
    ll n,d,m;cin>>n>>d>>m;
    ll a[n+10],sum=0;
    for(int i=0;i<n;i++)cin>>a[i],sum+=a[i];
    sort(a,a+n);
    vector<ll>b,c;
    for(int i=n-1;i>=0;i--){
        if(a[i]>m)c.pb(a[i]);
        else b.pb(a[i]);
    }
    for(int i=1;i<b.size();i++)b[i]+=b[i-1];
    for(int i=1;i<c.size();i++)c[i]+=c[i-1];
    if(c.size()==0){cout<<sum<<endl;return;}
    ll ans=0;
    for(int i=0;i<c.size();i++){
        int rem= n- (i*d+i+1);
        if(rem>b.size() || rem<=0)continue;
        amax(ans,c[i]+b[rem-1]);
    }
    cout<<ans<<endl;
}

int main()
{
    clock_t tt;tt = clock();
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    //pre();
    for(int i=1;i<=t;i++){
       //cout<<"Case #"<<i<<": ";
       solve();
    }
    tt = clock() - tt; double time_taken = ((double)tt)/CLOCKS_PER_SEC;
    //printf("code took %f seconds to execute \n", time_taken);
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove ios_base for interactive problems
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define NULL 0
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define d0(x) cout<<x<<" ";
#define d1(x) cout<<x<<"\n";
#define d2(x,y) cout<<x<<" "<<y<<"\n";
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n";

//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;}
template<typename T, typename U> static inline void amax(T &x, U y){if (y > x)x = y;}

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const  ll mod= 1000000007  ;
const long long inf = (ll)1e18+17;
const int iinf = 1500000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve(){
    ll n,d,m;cin>>n>>d>>m;
    ll a[n+10];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    vector<ll>b,c;
    for(int i=n-1;i>=0;i--){
        if(a[i]>m)c.pb(a[i]);
        else b.pb(a[i]);
    }
    for(int i=1;i<b.size();i++)b[i]+=b[i-1];
    for(int i=1;i<c.size();i++)c[i]+=c[i-1];
    ll ans=0;
    for(int i=0;i<c.size();i++){
        int rem= n- (i*d+i+1);
        if(rem>b.size())continue;
        amax(ans,c[i]+b[rem-1]);
    }
    cout<<ans<<endl;
}

int main()
{
    clock_t tt;tt = clock();
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    //pre();
    for(int i=1;i<=t;i++){
       //cout<<"Case #"<<i<<": ";
       solve();
    }
    tt = clock() - tt; double time_taken = ((double)tt)/CLOCKS_PER_SEC;
    //printf("code took %f seconds to execute \n", time_taken);
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove ios_base for interactive problems
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
const long double PI = acos(-1);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a, b) cout<<a<<" "<<b<<"\n"
#define o3(a, b, c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
#define i1(a) cin>>a
#define i2(a, b) cin>>a>>b
#define i3(a, b, c) cin>>a>>b>>c
#define i4(a, b, c, d) cin>>a>>b>>c>>d
#define fi first
#define se second

ll power(ll a, ll b, ll z = MOD)
{
	ll res = 1;
	a = (a%z);
	while(b)
	{
		if(b&1)
			res = (res*a)%z;
		a = (a*a)%z;
		b = b>>1;
	}
	return res;
}

ll inverse(ll a, ll z = MOD)
{
	return power(a, z-2, z);
}

ll extend(ll a, ll b, ll &x, ll &y)
{
	if(b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll g = extend(b, a%b, x1, y1);
	x = y1;
	y = x1- (a/b)*y1;
	return g;
}

ll mat_power(ll a, ll b, ll c, ll d, ll n, ll z = MOD)
{
	ll a0 = 1, b0 = 0, c0 = 0, d0 = 1;
	while(n)
	{
		if(n&1)
		{
			ll a1 = a0, b1 = b0, c1 = c0, d1 = d0;
			a0 = (a1*a + b1*c)%z;
			b0 = (a1*b + b1*d)%z;
			c0 = (c1*a + d1*c)%z;
			d0 = (c1*b + d1*d)%z;
		}
		ll a1 = a, b1 = b, c1 = c, d1 = d;
		a = (a1*a1 + b1*c1)%z;
		b = (a1*b1 + b1*d1)%z;
		c = (c1*a1 + d1*c1)%z;
		d = (c1*b1 + d1*d1)%z;
		n = n>>1;
	}
	return c0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, d, m;
	i3(n, d, m);
	ll aray[n+1], psum[n+1] = {0}, ssum[n+2] = {0};
	for(int i=1;i<=n;i++)
		i1(aray[i]);
	sort(aray+1, aray+n+1);
	for(int i=1;i<=n;i++)
		psum[i] = psum[i-1] + aray[i];
	for(int i=n;i>=1;i--)
		ssum[i] = ssum[i+1] + aray[i];
	ll loc = 1;
	for(int i=1;i<=n;i++)
	{
		if(aray[i] <= m)
			loc++;
	}
	if(loc == n+1)
	{
		o1(psum[n]);
		return 0;
	}
	int left = 0, right = n-loc+1, mid;
	ll ans = 0;
	while(left <= right)
	{
		mid = (left+right)>>1;
		if(mid*(d+1)-d > n)
		{
			right = mid-1;
			continue;
		}
		ll final = ssum[n-mid+1];
		ll days = mid*(d+1)-d;
		ll rem = n-days;
		if(rem >= loc-1)
			final += psum[loc-1];
		else
			final += psum[loc-1]-psum[loc-rem-1];
		ans = max(ans, final);
		left = mid+1;
	}
	o1(ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
const long double PI = acos(-1);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a, b) cout<<a<<" "<<b<<"\n"
#define o3(a, b, c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
#define i1(a) cin>>a
#define i2(a, b) cin>>a>>b
#define i3(a, b, c) cin>>a>>b>>c
#define i4(a, b, c, d) cin>>a>>b>>c>>d
#define fi first
#define se second

ll power(ll a, ll b, ll z = MOD)
{
	ll res = 1;
	a = (a%z);
	while(b)
	{
		if(b&1)
			res = (res*a)%z;
		a = (a*a)%z;
		b = b>>1;
	}
	return res;
}

ll inverse(ll a, ll z = MOD)
{
	return power(a, z-2, z);
}

ll extend(ll a, ll b, ll &x, ll &y)
{
	if(b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll g = extend(b, a%b, x1, y1);
	x = y1;
	y = x1- (a/b)*y1;
	return g;
}

ll mat_power(ll a, ll b, ll c, ll d, ll n, ll z = MOD)
{
	ll a0 = 1, b0 = 0, c0 = 0, d0 = 1;
	while(n)
	{
		if(n&1)
		{
			ll a1 = a0, b1 = b0, c1 = c0, d1 = d0;
			a0 = (a1*a + b1*c)%z;
			b0 = (a1*b + b1*d)%z;
			c0 = (c1*a + d1*c)%z;
			d0 = (c1*b + d1*d)%z;
		}
		ll a1 = a, b1 = b, c1 = c, d1 = d;
		a = (a1*a1 + b1*c1)%z;
		b = (a1*b1 + b1*d1)%z;
		c = (c1*a1 + d1*c1)%z;
		d = (c1*b1 + d1*d1)%z;
		n = n>>1;
	}
	return c0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, d, m;
	i3(n, d, m);
	ll aray[n+1], psum[n+1] = {0}, ssum[n+2] = {0};
	for(int i=1;i<=n;i++)
		i1(aray[i]);
	sort(aray+1, aray+n+1);
	for(int i=1;i<=n;i++)
		psum[i] = psum[i-1] + aray[i];
	for(int i=n;i>=1;i--)
		ssum[i] = ssum[i+1] + aray[i];
	ll loc = 1;
	for(int i=1;i<=n;i++)
	{
		if(aray[i] <= m)
			loc++;
	}
	if(loc == n+1)
	{
		o1(psum[n]);
		return 0;
	}
	ll ans = psum[loc-1];
	for(ll i=1;i<loc;i++)
	{
		ll days = i*(d+1)-d;
		if(days > n)
			continue;
		ll rem = n-days;
		ll final = ssum[n-i+1];
		if(rem >= loc-1)
			final += psum[loc-1];
		else
			final += psum[loc-1]-psum[loc-rem-1];
		ans = max(ans, final);
	}
	o1(ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
const long double PI = acos(-1);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a, b) cout<<a<<" "<<b<<"\n"
#define o3(a, b, c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
#define i1(a) cin>>a
#define i2(a, b) cin>>a>>b
#define i3(a, b, c) cin>>a>>b>>c
#define i4(a, b, c, d) cin>>a>>b>>c>>d
#define fi first
#define se second

ll power(ll a, ll b, ll z = MOD)
{
	ll res = 1;
	a = (a%z);
	while(b)
	{
		if(b&1)
			res = (res*a)%z;
		a = (a*a)%z;
		b = b>>1;
	}
	return res;
}

ll inverse(ll a, ll z = MOD)
{
	return power(a, z-2, z);
}

ll extend(ll a, ll b, ll &x, ll &y)
{
	if(b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll g = extend(b, a%b, x1, y1);
	x = y1;
	y = x1- (a/b)*y1;
	return g;
}

ll mat_power(ll a, ll b, ll c, ll d, ll n, ll z = MOD)
{
	ll a0 = 1, b0 = 0, c0 = 0, d0 = 1;
	while(n)
	{
		if(n&1)
		{
			ll a1 = a0, b1 = b0, c1 = c0, d1 = d0;
			a0 = (a1*a + b1*c)%z;
			b0 = (a1*b + b1*d)%z;
			c0 = (c1*a + d1*c)%z;
			d0 = (c1*b + d1*d)%z;
		}
		ll a1 = a, b1 = b, c1 = c, d1 = d;
		a = (a1*a1 + b1*c1)%z;
		b = (a1*b1 + b1*d1)%z;
		c = (c1*a1 + d1*c1)%z;
		d = (c1*b1 + d1*d1)%z;
		n = n>>1;
	}
	return c0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, d, m;
	i3(n, d, m);
	ll aray[n+1], psum[n+1] = {0}, ssum[n+2] = {0};
	for(int i=1;i<=n;i++)
		i1(aray[i]);
	sort(aray+1, aray+n+1);
	for(int i=1;i<=n;i++)
		psum[i] = psum[i-1] + aray[i];
	for(int i=n;i>=1;i--)
		ssum[i] = ssum[i+1] + aray[i];
	ll loc = 1;
	for(int i=1;i<=n;i++)
	{
		if(aray[i] <= m)
			loc++;
	}
	if(loc == n+1)
	{
		o1(psum[n]);
		return 0;
	}
	ll ans = psum[loc-1];
	for(int i=1;i<loc;i++)
	{
		ll days = i*(d+1)-d;
		if(days > n)
			continue;
		ll rem = n-days;
		ll final = ssum[n-i+1];
		if(rem >= loc-1)
			final += psum[loc-1];
		else
			final += psum[loc-1]-psum[loc-rem-1];
		ans = max(ans, final);
	}
	o1(ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
const long double PI = acos(-1);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a, b) cout<<a<<" "<<b<<"\n"
#define o3(a, b, c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
#define i1(a) cin>>a
#define i2(a, b) cin>>a>>b
#define i3(a, b, c) cin>>a>>b>>c
#define i4(a, b, c, d) cin>>a>>b>>c>>d
#define fi first
#define se second

ll power(ll a, ll b, ll z = MOD)
{
	ll res = 1;
	a = (a%z);
	while(b)
	{
		if(b&1)
			res = (res*a)%z;
		a = (a*a)%z;
		b = b>>1;
	}
	return res;
}

ll inverse(ll a, ll z = MOD)
{
	return power(a, z-2, z);
}

ll extend(ll a, ll b, ll &x, ll &y)
{
	if(b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll g = extend(b, a%b, x1, y1);
	x = y1;
	y = x1- (a/b)*y1;
	return g;
}

ll mat_power(ll a, ll b, ll c, ll d, ll n, ll z = MOD)
{
	ll a0 = 1, b0 = 0, c0 = 0, d0 = 1;
	while(n)
	{
		if(n&1)
		{
			ll a1 = a0, b1 = b0, c1 = c0, d1 = d0;
			a0 = (a1*a + b1*c)%z;
			b0 = (a1*b + b1*d)%z;
			c0 = (c1*a + d1*c)%z;
			d0 = (c1*b + d1*d)%z;
		}
		ll a1 = a, b1 = b, c1 = c, d1 = d;
		a = (a1*a1 + b1*c1)%z;
		b = (a1*b1 + b1*d1)%z;
		c = (c1*a1 + d1*c1)%z;
		d = (c1*b1 + d1*d1)%z;
		n = n>>1;
	}
	return c0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, d, m;
	i3(n, d, m);
	ll aray[n+1], psum[n+1] = {0}, ssum[n+2] = {0};
	for(int i=1;i<=n;i++)
		i1(aray[i]);
	sort(aray+1, aray+n+1);
	for(int i=1;i<=n;i++)
		psum[i] = psum[i-1] + aray[i];
	for(int i=n;i>=1;i--)
		ssum[i] = ssum[i+1] + aray[i];
	ll loc = 1;
	for(int i=1;i<=n;i++)
	{
		if(aray[i] <= m)
			loc++;
	}
	if(loc == n+1)
	{
		o1(psum[n]);
		return 0;
	}
	ll left = 0, right = n-loc+1, mid;
	ll ans = 0;
	while(left <= right)
	{
		mid = (left+right)>>1;
		if(mid*(d+1)-d > n)
		{
			right = mid-1;
			continue;
		}
		ll final = ssum[n-mid+1];
		ll days = mid*(d+1)-d;
		ll rem = n-days;
		if(rem >= loc-1)
			final += psum[loc-1];
		else
			final += psum[loc-1]-psum[loc-rem-1];
		ans = max(ans, final);
		left = mid+1;
	}
	o1(ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
const long double PI = acos(-1);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a, b) cout<<a<<" "<<b<<"\n"
#define o3(a, b, c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
#define i1(a) cin>>a
#define i2(a, b) cin>>a>>b
#define i3(a, b, c) cin>>a>>b>>c
#define i4(a, b, c, d) cin>>a>>b>>c>>d
#define fi first
#define se second

ll power(ll a, ll b, ll z = MOD)
{
	ll res = 1;
	a = (a%z);
	while(b)
	{
		if(b&1)
			res = (res*a)%z;
		a = (a*a)%z;
		b = b>>1;
	}
	return res;
}

ll inverse(ll a, ll z = MOD)
{
	return power(a, z-2, z);
}

ll extend(ll a, ll b, ll &x, ll &y)
{
	if(b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll g = extend(b, a%b, x1, y1);
	x = y1;
	y = x1- (a/b)*y1;
	return g;
}

ll mat_power(ll a, ll b, ll c, ll d, ll n, ll z = MOD)
{
	ll a0 = 1, b0 = 0, c0 = 0, d0 = 1;
	while(n)
	{
		if(n&1)
		{
			ll a1 = a0, b1 = b0, c1 = c0, d1 = d0;
			a0 = (a1*a + b1*c)%z;
			b0 = (a1*b + b1*d)%z;
			c0 = (c1*a + d1*c)%z;
			d0 = (c1*b + d1*d)%z;
		}
		ll a1 = a, b1 = b, c1 = c, d1 = d;
		a = (a1*a1 + b1*c1)%z;
		b = (a1*b1 + b1*d1)%z;
		c = (c1*a1 + d1*c1)%z;
		d = (c1*b1 + d1*d1)%z;
		n = n>>1;
	}
	return c0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, d, m;
	i3(n, d, m);
	ll aray[n+1], psum[n+1] = {0}, ssum[n+2] = {0};
	for(int i=1;i<=n;i++)
		i1(aray[i]);
	sort(aray+1, aray+n+1);
	for(int i=1;i<=n;i++)
		psum[i] = psum[i-1] + aray[i];
	for(int i=n;i>=1;i--)
		ssum[i] = ssum[i+1] + aray[i];
	ll loc = 1;
	for(int i=1;i<=n;i++)
	{
		if(aray[i] <= m)
			loc++;
	}
	if(loc == n+1)
	{
		o1(psum[n]);
		return 0;
	}
	ll ans = psum[loc-1];
	for(ll i=1;i<=n-loc+1;i++)
	{
		ll days = i*(d+1)-d;
		if(days > n)
			continue;
		ll rem = n-days;
		ll final = ssum[n-i+1];
		if(rem >= loc-1)
			final += psum[loc-1];
		else
			final += psum[loc-1]-psum[loc-rem-1];
		ans = max(ans, final);
	}
	o1(ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
const long double PI = acos(-1);
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a, b) cout<<a<<" "<<b<<"\n"
#define o3(a, b, c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
#define i1(a) cin>>a
#define i2(a, b) cin>>a>>b
#define i3(a, b, c) cin>>a>>b>>c
#define i4(a, b, c, d) cin>>a>>b>>c>>d
#define fi first
#define se second

ll power(ll a, ll b, ll z = MOD)
{
	ll res = 1;
	a = (a%z);
	while(b)
	{
		if(b&1)
			res = (res*a)%z;
		a = (a*a)%z;
		b = b>>1;
	}
	return res;
}

ll inverse(ll a, ll z = MOD)
{
	return power(a, z-2, z);
}

ll extend(ll a, ll b, ll &x, ll &y)
{
	if(b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll g = extend(b, a%b, x1, y1);
	x = y1;
	y = x1- (a/b)*y1;
	return g;
}

ll mat_power(ll a, ll b, ll c, ll d, ll n, ll z = MOD)
{
	ll a0 = 1, b0 = 0, c0 = 0, d0 = 1;
	while(n)
	{
		if(n&1)
		{
			ll a1 = a0, b1 = b0, c1 = c0, d1 = d0;
			a0 = (a1*a + b1*c)%z;
			b0 = (a1*b + b1*d)%z;
			c0 = (c1*a + d1*c)%z;
			d0 = (c1*b + d1*d)%z;
		}
		ll a1 = a, b1 = b, c1 = c, d1 = d;
		a = (a1*a1 + b1*c1)%z;
		b = (a1*b1 + b1*d1)%z;
		c = (c1*a1 + d1*c1)%z;
		d = (c1*b1 + d1*d1)%z;
		n = n>>1;
	}
	return c0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, d, m;
	i3(n, d, m);
	ll aray[n+1], psum[n+1] = {0}, ssum[n+2] = {0};
	for(int i=1;i<=n;i++)
		i1(aray[i]);
	sort(aray+1, aray+n+1);
	for(int i=1;i<=n;i++)
		psum[i] = psum[i-1] + aray[i];
	for(int i=n;i>=1;i--)
		ssum[i] = ssum[i+1] + aray[i];
	ll loc = 1;
	for(int i=1;i<=n;i++)
	{
		if(aray[i] <= m)
			loc++;
	}
	if(loc == n+1)
	{
		o1(psum[n]);
		return 0;
	}
	int left = 0, right = n-loc+1, mid;
	ll ans = 0;
	while(left <= right)
	{
		mid = (left+right)>>1;
		if(mid*(d+1)-d > n)
		{
			right = mid-1;
			continue;
		}
		ll final = ssum[n-mid+1];
		ll days = mid*(d+1)-d;
		ll rem = n-days;
		int l = min(rem, loc-1);
		final += psum[loc-1]-psum[loc-l-1];
		ans = max(ans, final);
		left = mid+1;
	}
	o1(ans);
	return 0;
}


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

// 23 15 10 8 3

int main(){

	long long n, d, m;
	cin >> n >> d >> m;

	vector <long long> arr(n+1);

	for (long long i=1; i<=n; i++){
		cin >> arr[i];
	}

	sort(arr.begin()+1, arr.end(), greater<long long>());

	long long f = -1;
	vector <long long> prefix(n+1);
	prefix[0] = 0;

	for (long long i=1; i<=n; i++){
		prefix[i] = prefix[i-1] + arr[i];

		if (arr[i] <= m and f==-1)
			f = i;
	}
	f--;
// 	cout << f << endl;
	if (f == -1){
		cout << prefix[n];
		return 0;
	}
	long long ans = 0;
	for (long long i=1; i<=f; i++){
		long long gap = (i-1)*d;
		if (n-gap >= f)
			ans = max (ans, prefix[i] + prefix[n-gap] - prefix[f]);
	}

	cout << ans;

}


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

// 23 15 10 8 3

int main(){

	long long n, d, m;
	cin >> n >> d >> m;

	vector <long long> arr(n+1);

	for (long long i=1; i<=n; i++){
		cin >> arr[i];
	}

	sort(arr.begin()+1, arr.end(), greater<long long>());

	long long f = -1;
	vector <long long> prefix(n+1);
	prefix[0] = 0;

	for (long long i=1; i<=n; i++){
		prefix[i] = prefix[i-1] + arr[i];

		if (arr[i] <= m and f==-1)
			f = i;
	}
	f--;
// 	cout << f << endl;
	if (f == -1){
		cout << prefix[n];
		return 0;
	}
	long long ans = 0;
	for (long long i=1; i<=f; i++){
		long long gap = (i-1)*d;
		if (n-gap >= f+1)
			ans = max (ans, prefix[i] + prefix[n-gap] - prefix[f]);
	}

	cout << ans;

}


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

// 23 15 10 8 3

int main(){

	long long n, d, m;
	cin >> n >> d >> m;

	vector <long long> arr(n+1);

	for (long long i=1; i<=n; i++){
		cin >> arr[i];
	}

	sort(arr.begin()+1, arr.end(), greater<long long>());

	long long f = -1;
	vector <long long> prefix(n+1);
	prefix[0] = 0;

	for (long long i=1; i<=n; i++){
		prefix[i] = prefix[i-1] + arr[i];

		if (arr[i] <= m and f==-1)
			f = i;
	}
	f--;
 //	cout << f << endl;
	if (f == 0){
		cout << prefix[n];
		return 0;
	}
	long long ans = 0;
	for (long long i=1; i<=f; i++){
		long long gap = (i-1)*d;
		if (n-gap >= f)
			ans = max (ans, prefix[i] + prefix[n-gap] - prefix[f]);
	}

	cout << ans;

}


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

// 23 15 10 8 3

int main(){

	long long n, d, m;
	cin >> n >> d >> m;

	vector <long long> arr(n+1);

	for (long long i=1; i<=n; i++){
		cin >> arr[i];
	}

	sort(arr.begin()+1, arr.end(), greater<long long>());

	long long f = -1;
	vector <long long> prefix(n+1);
	prefix[0] = 0;

	for (long long i=1; i<=n; i++){
		prefix[i] = prefix[i-1] + arr[i];

		if (arr[i] <= m and f==-1)
			f = i;
	}
	f--;
 //	cout << f << endl;
	if (f == 0){
		cout << prefix[n];
		return 0;
	}
	long long ans = 0;
	for (long long i=1; i<=f; i++){
		long long gap = (i-1)*d;
		if (n-gap > f)
			ans = max (ans, prefix[i] + prefix[n-gap] - prefix[f]);
	}

	cout << ans;

}


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

// 23 15 10 8 3

int main(){

	long long n, d, m;
	cin >> n >> d >> m;

	vector <long long> arr(n+1);

	for (long long i=1; i<=n; i++){
		cin >> arr[i];
	}

	sort(arr.begin()+1, arr.end(), greater<long long>());

	long long f = n+1;
	vector <long long> prefix(n+1);
	prefix[0] = 0;

	for (long long i=1; i<=n; i++){
		prefix[i] = prefix[i-1] + arr[i];

		if (arr[i] <= m and f==n+1)
			f = i;
	}
	f--;
 //	cout << f << endl;
	if (f == 0){
		cout << prefix[n];
		return 0;
	}
	long long ans = 0;
	for (long long i=1; i<=f; i++){
		long long gap = n - (i-1) * (d+1) -1;
		if (gap >= 0)
			ans = max (ans, prefix[i] + prefix[min (n,f + gap)] - prefix[f]);
	}

	cout << ans;

}


/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is good and equally fun like any other game.
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int n,m,d;
  cin>>n>>d>>m;
  vi a(n);
  vll b,s;
  rep(i,n)
  {
    cin>>a[i];
    if(a[i]>m)
      b.pb(a[i]);
    else
      s.pb(a[i]);
  }

  sort(all(b),greater<ll>());
  sort(all(s),greater<ll>());
  vll pref(sz(s)+1,0);
  int mx=pref.size()-1;
  rep(i,mx)
  {
    pref[i+1]+=pref[i]+s[i];
  }

  ll ans=pref[min(n,mx)];
  ll curr=0;
  for(int i=1;i<=sz(b);i++)
  {
    curr+=b[i-1];
    ll big=1ll*(i-1)*(d+1)+1;
    ll small=min(1ll*mx,max(0ll,n-big));
    ll res=pref[small]+curr;
    ans=max(ans,res);

  }

  cout<<ans<<endl;

}

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  ios::sync_with_stdio(false);
  cin.tie(0);

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is good and equally fun like any other game.
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int n,m,d;
  cin>>n>>d>>m;
  vll a,b;

  rep(i,n)
  {
    int x;
    cin>>x;

    if(x>m)
      a.pb(x);
    else
      b.pb(x);
  }

  sort(all(a),greater<ll>());
  sort(all(b),greater<ll>());
  int s1=a.size()-1,s2=b.size()-1;

  rep(i,s1)
  {
    a[i+1]+=a[i];
  }
  rep(i,s2)
  {
    b[i+1]+=b[i];
  }

  ll ans=b[min(n,int(b.size()))-1];

  for(int i=1;i<=a.size();i++)
  {
    ll big=1ll*(i-1)*(d+1)+1;
    ll small=max(0ll,n-big)-1;
    ll curr=a[i-1];
    if(small>=0)
      curr+=b[small];
    ans=max(ans,curr);
  }

  cout<<ans<<endl;

}

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  ios::sync_with_stdio(false);
  cin.tie(0);

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is good and equally fun like any other game.
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int n,m,d;
  cin>>n>>d>>m;
  vi a(n);
  vll b,s;
  rep(i,n)
  {
    cin>>a[i];
    if(a[i]>m)
      b.pb(a[i]);
    else
      s.pb(a[i]);
  }

  sort(all(b),greater<ll>());
  sort(all(s),greater<ll>());
  vll pref(sz(s)+1,0);
  rep(i,sz(pref)-1)
  {
    pref[i+1]+=pref[i]+s[i];
  }

  ll ans=pref[min(n,(int)pref.size()-1)];
  ll curr=0;
  for(int i=1;i<=sz(b);i++)
  {
    curr+=b[i-1];
    ll big=1ll*(i-1)*(d+1)+1;
    ll small=max(0ll,n-big);
    ll res=pref[small]+curr;
    ans=max(ans,res);

  }

  cout<<ans<<endl;

}

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  ios::sync_with_stdio(false);
  cin.tie(0);

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is good and equally fun like any other game.
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int n,m,d;
  cin>>n>>d>>m;
  vll a,b;

  rep(i,n)
  {
    int x;
    cin>>x;

    if(x>m)
      a.pb(x);
    else
      b.pb(x);
  }

  sort(all(a),greater<ll>());
  sort(all(b),greater<ll>());
  int s1=a.size()-1,s2=b.size()-1;

  rep(i,s1)
  {
    a[i+1]+=a[i];
  }
  rep(i,s2)
  {
    b[i+1]+=b[i];
  }

  ll ans=0;
  int x=min(n,int(b.size()))-1;
  if(x>=0)
    ans+=b[x];

  for(int i=1;i<=a.size();i++)
  {
    ll big=1ll*(i-1)*(d+1)+1;
    if(big>1ll*n)
      break;
    ll small=max(0ll,min(n-big,(ll)b.size()))-1;
    ll curr=a[i-1];
    if(small>=0)
      curr+=b[small];
    ans=max(ans,curr);
  }

  cout<<ans<<endl;

}

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  ios::sync_with_stdio(false);
  cin.tie(0);

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is good and equally fun like any other game.
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int n,m,d;
  cin>>n>>d>>m;
  vll a,b;

  rep(i,n)
  {
    int x;
    cin>>x;

    if(x>m)
      a.pb(x);
    else
      b.pb(x);
  }

  sort(all(a),greater<ll>());
  sort(all(b),greater<ll>());
  int s1=a.size()-1,s2=b.size()-1;

  rep(i,s1)
  {
    a[i+1]+=a[i];
  }
  rep(i,s2)
  {
    b[i+1]+=b[i];
  }

  ll ans=b[min(n,int(b.size()))-1];

  for(int i=1;i<=a.size();i++)
  {
    ll big=1ll*(i-1)*(d+1)+1;
    ll small=max(0ll,min(n-big,(ll)b.size()))-1;
    ll curr=a[i-1];
    if(small>=0)
      curr+=b[small];
    ans=max(ans,curr);
  }

  cout<<ans<<endl;

}

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  ios::sync_with_stdio(false);
  cin.tie(0);

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is good and equally fun like any other game.
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int n,m,d;
  cin>>n>>d>>m;
  vll a,b;

  rep(i,n)
  {
    int x;
    cin>>x;

    if(x>m)
      a.pb(x);
    else
      b.pb(x);
  }

  sort(all(a),greater<ll>());
  sort(all(b),greater<ll>());
  int s1=a.size()-1,s2=b.size()-1;

  rep(i,s1)
  {
    a[i+1]+=a[i];
  }
  rep(i,s2)
  {
    b[i+1]+=b[i];
  }

  ll ans=b[min(n,int(b.size()))-1];

  for(int i=1;i<=a.size();i++)
  {
    ll big=1ll*(i-1)*(d+1)+1;
    if(big>1ll*n)
      break;
    ll small=max(0ll,min(n-big,(ll)b.size()))-1;
    ll curr=a[i-1];
    if(small>=0)
      curr+=b[small];
    ans=max(ans,curr);
  }

  cout<<ans<<endl;

}

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  ios::sync_with_stdio(false);
  cin.tie(0);

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll aa,ll bb){
    return aa>bb;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small.back()<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(n-t-1<small.size()&&n-t-1>=0)
            ans=max(ans,big[x-1]+small[n-t-1]);
        else if(!small.empty())ans=max(ans,big[x-1]+small.back());
        else ans=max(ans,big[x-1]);
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll aa,ll bb){
    return aa>bb;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small.back()<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(t>n)break;
        if(n-t-1>=0){
            if(n-t-1<small.size())ans=max(ans,big[x-1]+small[n-t-1]);
            else if(!small.empty())ans=max(ans,big[x-1]+small.back());
            else ans=max(ans,big[x-1]);
        }
        else ans=max(ans,big[x-1]);
        // if(n-t-1<small.size()&&n-t-1>=0)
            // ans=max(ans,big[x-1]+small[n-t-1]);
        // else if(!small.empty())ans=max(ans,big[x-1]+small.back());
        // else ans=max(ans,big[x-1]);
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll aa,ll bb){
    return aa>bb;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small[n-1]<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(t+1<=n&&n-t-1<small.size()){
            assert(x<=big.size());
            assert(n-t-1<small.size());
            ans=max(ans,big[x-1]+small[n-t-1]);
        }
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll aa,ll bb){
    return aa>bb;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small.back()<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(n-t-1<small.size())
            ans=max(ans,big[x-1]+small[n-t-1]);
        else if(!small.empty())ans=max(ans,big[x-1]+small.back());
        else ans=max(ans,big[x-1]);
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll aa,ll bb){
    return aa>bb;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small.back()<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(t>n)break;
        if(n-t-1>=0){
            if(n-t-1<small.size())ans=max(ans,big[x-1]+small[n-t-1]);
            else ans=max(ans,big[x-1]+small.back());
        }
        else ans=max(ans,big[x-1]);
        // if(n-t-1<small.size()&&n-t-1>=0)
            // ans=max(ans,big[x-1]+small[n-t-1]);
        // else if(!small.empty())ans=max(ans,big[x-1]+small.back());
        // else ans=max(ans,big[x-1]);
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll aa,ll bb){
    return aa>bb;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small.back()<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(n-t-1<small.size())
            ans=max(ans,big[x-1]+small[n-t-1]);
        else ans=max(ans,big[x-1]+small.back());
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll aa,ll bb){
    return aa>bb;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small.back()<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(t+1<=n){
            if(n-t-1<small.size())
                ans=max(ans,big[x-1]+small[n-t-1]);
            else ans=max(ans,big[x-1]+small.back());
        }
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll a,ll b){
    return a>b;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small[n-1]<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(t+1<=n){
            ans=max(ans,big[x-1]+small[n-t-1]);
        }
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll aa,ll bb){
    return aa>bb;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small[n-1]<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    assert(ans==0);
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(t+1<=n){
            assert(big[x-1]+small[n-t-1]!=2341676402945760431);
            ans=max(ans,big[x-1]+small[n-t-1]);
        }
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool cmp(ll aa,ll bb){
    return aa>bb;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,d,m;
    cin>>n>>d>>m;
    vector<ll>big,small;
    for(ll u=0;u<n;u++){
        ll a;
        cin>>a;
        if(a>m)big.push_back(a);
        else small.push_back(a);
    }
    sort(small.begin(),small.end(),cmp);
    sort(big.begin(),big.end(),cmp);
    for(int k=1;k<small.size();k++){
        small[k]+=small[k-1];
    }
    for(int k=1;k<big.size();k++){
        big[k]+=big[k-1];
    }
    if(big.empty()){
        cout<<small[n-1]<<"\n";
        return;
    }
    ll bsz=big.size();
    ll ans=0;
    for(ll x=1;x<=bsz;x++){
        ll t=x+d*(x-1);
        if(t+1<=n){
            ans=max(ans,big[x-1]+small[n-t-1]);
        }
    }
    cout<<ans<<"\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}


// created by mtnshh

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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)

#define err() cout<<"--------------------------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265

const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, d, m;
    cin >> n >> d >> m;
    ll A[n];
    ll p = 0;
    rep(i,0,n){
    	cin >> A[i];
    	if(A[i] > m)	p++;
    }
    sort(A,A+n);
    reverse(A,A+n);
    if((d+1) * (p - 1) + 1 <= n){
    	ll q = n - ((d+1)*(p-1)+1);
    	ll ans = 0;
    	rep(i,0,q+p)	ans += A[i];
    	cout << ans << endl;
    }
    else{
    	ll q = (n + d) / (d + 1);
    	ll ans = 0;
    	rep(i,0,q)	ans += A[i];
    	cout << ans << endl;
    }
    return 0;
}


// created by mtnshh

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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)

#define err() cout<<"--------------------------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265

const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, d, m;
    cin >> n >> d >> m;
    ll A[n];
    ll p = 0;
    V v1;
    V v2;
    rep(i,0,n){
    	cin >> A[i];
    	if(A[i] <= m){
            v1.pb(A[i]);
            p += A[i];
        }
        else{
            v2.pb(A[i]);
        }
    }
    sort(all(v1));sort(all(v2));
    reverse(all(v1));
    for(auto i:v2){
        v1.pb(i);
    }
    ll ans = 0;
    ll q = 0;
    if(v2.empty()){
        ans = p;
        cout << ans << endl;
        return 0;
    }
    q += v2.back();
    v2.pop_back();
    v1.pop_back();
    ans = max(ans, p+q);
    while(v2.size()){
        q += v2.back();
        v2.pop_back();
        ll cnt = 0;
        while(v1.size() and cnt <= d){
            if(v1.back() <= m)  p -= v1.back();
            v1.pop_back();
            cnt++;
        }
        if(cnt == d+1){
            ans = max(ans, p+q);
        }
        else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


// created by mtnshh

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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)

#define err() cout<<"--------------------------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265

const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, d, m;
    cin >> n >> d >> m;
    ll A[n];
    ll p = 0;
    V v1;
    V v2;
    rep(i,0,n){
    	cin >> A[i];
    	if(A[i] <= m){
            v1.pb(A[i]);
            p += A[i];
        }
        else{
            v2.pb(A[i]);
        }
    }
    sort(all(v1));sort(all(v2));
    reverse(all(v1));
    for(auto i:v2){
        v1.pb(i);
    }
    ll ans = 0;
    ll q = 0;
    if(v2.empty()){
        ans = p;
        cout << ans << endl;
        return 0;
    }
    q += v2.back();
    v2.pop_back();
    v1.pop_back();
    // errA(v1);
    // errA(v2);
    // err2(p, q);
    if(v1.back() <= m){
        ans = max(ans, p+q);
    }
    else{
        ans = max(ans, q);
    }
    while(v2.size()){
        q += v2.back();
        v2.pop_back();
        ll cnt = 0;
        while(v1.size() and cnt <= d){
            if(v1.back() <= m)  p -= v1.back();
            v1.pop_back();
            cnt++;
        }
        // errA(v1);
        // errA(v2);
        // err2(p, q);
        if(cnt == d+1){
            if(v1.back() <= m){
                ans = max(ans, p+q);
            }
            else{
                ans = max(ans, q);
            }
        }
        else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


// created by mtnshh

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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)

#define err() cout<<"--------------------------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265

const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, d, m;
    cin >> n >> d >> m;
    ll A[n];
    ll p = 0;
    rep(i,0,n){
    	cin >> A[i];
    	if(A[i] > m)	p++;
    }
    sort(A,A+n);
    reverse(A,A+n);
    if((d+1) * (p - 1) + 1 <= n){
    	ll q = n - ((d+1)*(p-1)+1);
    	ll ans = 0;
    	rep(i,0,min(q+p,n))	ans += A[i];
    	cout << ans << endl;
    }
    else{
    	ll q = (n + d) / (d + 1);
    	ll ans = 0;
    	rep(i,0,q)	ans += A[i];
    	cout << ans << endl;
    }
    return 0;
}