Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.

In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.

Du will chat in the group for $n$ days. On the $i$-th day:  If Du can speak, he'll make fun of Boboniu with fun factor $a_i$. But after that, he may be muzzled depending on Boboniu's mood.  Otherwise, Du won't do anything. 

Boboniu's mood is a constant $m$. On the $i$-th day:  If Du can speak and $a_i>m$, then Boboniu will be angry and muzzle him for $d$ days, which means that Du won't be able to speak on the $i+1, i+2, \cdots, \min(i+d,n)$-th days.  Otherwise, Boboniu won't do anything. 

The total fun factor is the sum of the fun factors on the days when Du can speak.

Du asked you to find the maximum total fun factor among all possible permutations of $a$.


-----Input-----

The first line contains three integers $n$, $d$ and $m$ ($1\le d\le n\le 10^5,0\le m\le 10^9$).

The next line contains $n$ integers $a_1, a_2, \ldots,a_n$ ($0\le a_i\le 10^9$).


-----Output-----

Print one integer: the maximum total fun factor among all permutations of $a$.


-----Examples-----
Input
5 2 11
8 10 15 23 5

Output
48

Input
20 2 16
20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7

Output
195



-----Note-----

In the first example, you can set $a'=[15, 5, 8, 10, 23]$. Then Du's chatting record will be:  Make fun of Boboniu with fun factor $15$.  Be muzzled.  Be muzzled.  Make fun of Boboniu with fun factor $10$.  Make fun of Boboniu with fun factor $23$. 

Thus the total fun factor is $48$.

Difficulty: MEDIUM_HARD

Solutions:
def mi():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def si():
	return input().split()
(n, d, m) = mi()
a = li()
a_s = []
a_b = []
for i in range(n):
	if a[i] > m:
		a_b.append(a[i])
	else:
		a_s.append(a[i])
a_b.sort(reverse=True)
a_s.sort(reverse=True)
s = 0
db = []
ds = []
for i in a_b:
	db.append(s)
	s += i
db.append(s)
s = 0
for i in a_s:
	ds.append(s)
	s += i
ds.append(s)
ans = ds[-1]
for i in range(1, len(db)):
	tmp = db[i]
	days = (i - 1) * (d + 1) + 1
	rem = n - days
	if rem >= len(ds):
		ans = max(ans, tmp + ds[-1])
	elif rem < 1:
		if days <= n:
			ans = max(ans, tmp)
	else:
		ans = max(ans, tmp + ds[rem])
print(ans)


(n, d, m) = map(int, input().split())
a = [*map(int, input().split())]
(ba, sa) = ([*filter(lambda x: x > m, a)], [*filter(lambda x: x <= m, a)])
ba.sort(reverse=True)
sa.sort()
from itertools import accumulate
aba = [*accumulate(ba)]
asa = [0] + [*accumulate(sa)]
ans = asa[-1]
for i in range(len(aba)):
	j = max(0, i * d - (len(aba) - i - 1))
	if j < len(asa):
		ans = max(ans, aba[i] + (asa[-1] - asa[j]))
print(ans)


from itertools import groupby, accumulate, product, permutations, combinations

def solve():
	(n, d, m) = map(int, input().split())
	A = list(map(int, input().split()))
	over = []
	safe = []
	for i in range(n):
		if A[i] > m:
			over.append(A[i])
		else:
			safe.append(A[i])
	X = len(over)
	Y = len(safe)
	over.sort(reverse=True)
	over = [0] + list(accumulate(over))
	safe.sort(reverse=True)
	safe = [0] + list(accumulate(safe))
	safe = safe + [safe[-1]] * (n - Y)
	if X == 0:
		return sum(A)
	ans = 0
	for x in range(1, X + 1):
		p = (x - 1) * (d + 1) + 1
		if p > n:
			break
		y = n - p
		ans = max(ans, over[x] + safe[y])
	return ans
print(solve())


def main():
	(n, d, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(filter(lambda i: i > m, a))
	c = list(filter(lambda i: i <= m, a))
	del a
	b.sort(reverse=True)
	c.sort(reverse=True)
	for (idx, i) in enumerate(b):
		if idx:
			b[idx] += b[idx - 1]
	for (idx, i) in enumerate(c):
		if idx:
			c[idx] += c[idx - 1]
	mx = 0
	k = (n + d) // (d + 1)
	if len(b) >= k:
		mx = b[k - 1]
	for (idx, i) in enumerate(c):
		bcnt = (n - idx - 1 + d) // (d + 1)
		if len(b) >= bcnt:
			if bcnt:
				mx = max(mx, b[bcnt - 1] + c[idx])
			elif len(c) == n:
				mx = max(mx, c[idx])
	print(mx)
	return
main()


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	(n, d, m) = map(int, input().split())
	(small, big) = ([], [])
	for x in map(int, input().split()):
		if x > m:
			big.append(x)
		else:
			small.append(x)
	small.sort(reverse=True)
	big.sort()
	if not big:
		print(sum(small))
		exit()
	n -= 1
	ans = big.pop()
	small.extend([0] * len(big))
	while len(small) >= d + 1 and big:
		x = sum((small.pop() for i in range(d + 1)))
		ans += max(x, big.pop())
	print(ans + sum(small))
main()


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
(N, D, M) = MAP()
A1 = []
A2 = []
for a in LIST():
	if a <= M:
		A1.append(a)
	else:
		A2.append(a)
A1.sort(reverse=1)
A2.sort(reverse=1)
N1 = len(A1)
N2 = len(A2)
acc1 = [0] + list(accumulate(A1))
acc2 = [0] + list(accumulate(A2))
ans = 0
for i in range(N1 + 1):
	have = N - i
	j = ceil(have, D + 1)
	if j > N2:
		continue
	ans = max(ans, acc1[i] + acc2[j])
print(ans)


import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
(n, d, m) = nm()
a = nl()
num = 0
for i in range(n):
	num += a[i] <= m
a.sort()
a.insert(0, 0)
su = []
su.append(0)
for i in range(1, n + 1):
	su.append(su[i - 1] + a[i])
(div, ans) = (n - num, 0)
d += 1
for i in range(0, div + 1):
	if i * d >= div and (i - 1) * d <= n - 1:
		temp = n - max((i - 1) * d + 1, div)
		ans = max(ans, su[n] - su[n - i] + su[num] - su[num - temp])
print(ans)


def solve(a, n):
	a = [a[0]] + sorted(a[1:], reverse=True)
	for i in range(1, n + 1):
		a[i] += a[i - 1]
	return a

def main():
	(n, d, m) = map(int, input().split())
	cons = list(map(int, input().split()))
	k = 0
	l = 0
	a = [0 for _ in range(n + 1)]
	b = [0 for _ in range(n + 1)]
	for el in cons:
		if el > m:
			k += 1
			a[k] = el
		else:
			l += 1
			b[l] = el
	s = 0
	if k == 0:
		for i in range(n + 1):
			s += b[i]
		print(s)
		return
	a = solve(a, k)
	b = solve(b, l)
	for i in range(l + 1, n + 1):
		b[i] = b[l]
	res = 0
	for i in range((k + d) // (d + 1), k + 1):
		if (i - 1) * (d + 1) + 1 <= n:
			res = max(res, a[i] + b[n - (i - 1) * (d + 1) - 1])
	print(res)
main()


import sys
readline = sys.stdin.buffer.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))

def solve():
	(n, d, m) = nm()
	a = nl()
	f = list()
	g = list()
	for x in a:
		if x > m:
			f.append(x)
		else:
			g.append(x)
	f.sort(reverse=True)
	g.sort(reverse=True)
	ng = len(g)
	a = [0] * (ng + 1)
	for i in range(ng):
		a[i + 1] = a[i] + g[i]
	ans = a[ng]
	cur = 0
	for i in range(len(f)):
		if i + 1 + i * d > n:
			break
		cur += f[i]
		v = n - i * d - i - 1
		if v > ng:
			v = ng
		if v < 0:
			v = 0
		if ans < cur + a[v]:
			ans = cur + a[v]
	print(ans)
	return
solve()


(n, d, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a = list(reversed(sorted(a)))
nl = [x for x in a if x <= m]
ml = [x for x in a if x > m]
aml = [0]
for x in ml:
	aml.append(aml[-1] + x)
anl = [0]
for x in nl:
	anl.append(anl[-1] + x)
if len(ml) == 0:
	print(sum(nl))
	return
result = []
best = 0
for i in range(1, len(ml) + 1):
	if (i - 1) * (d + 1) + 1 > n:
		continue
	if i * d < len(ml) - i:
		continue
	cur = aml[i]
	need_nmes = max(0, (i - 1) * (d + 1) + 1 - len(ml))
	rem_nmes = len(nl) - need_nmes
	assert rem_nmes >= 0
	cur += anl[rem_nmes]
	if cur > best:
		best = cur
print(best)


from itertools import accumulate
(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
(u, v) = ([], [])
for i in a:
	if i > m:
		u.append(i)
	else:
		v.append(i)
u.sort(reverse=True)
v.sort(reverse=True)
u = list(accumulate(u))
v = list(accumulate(v))
ans = 0
for i in range(0, len(u) + 1):
	ms = u[i - 1] if i else 0
	av = n - i - max(0, i - 1) * d
	if av < 0:
		continue
	ns = v[min(av - 1, len(v) - 1)] if v and av else 0
	ans = max(ans, ms + ns)
print(ans)


arr = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
n = arr[0]
d = arr[1]
m = arr[2]
big = []
small = []
for i in a:
	if i > m:
		big.append(i)
	else:
		small.append(i)
big = sorted(big)[::-1]
n1 = len(big)
ans = 0
n2 = len(small)
small = sorted(small)[::-1]
for i in range(1, n1):
	big[i] += big[i - 1]
for i in range(1, n2):
	small[i] += small[i - 1]
if n2 > n:
	ans = small[n - 1]
elif n2 >= 1:
	ans = small[n2 - 1]
for i in range(n1):
	no_of_big_considered = i + 1
	no = (no_of_big_considered - 1) * (d + 1) + 1
	if no > n:
		break
	temp = big[i]
	ele = n - no
	if ele > 0 and n2 >= 1:
		temp += small[min(ele - 1, n2 - 1)]
	else:
		pass
	ans = max(ans, temp)
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import bisect
(n, d, m) = map(int, input().split())
vals = list(map(int, input().split()))
fun = []
left = []
days = 0
for s in range(n):
	if vals[s] <= m:
		fun.append(vals[s])
	else:
		left.append(vals[s])
fun.sort()
left.sort()
store1 = [0]
store2 = []
d1 = []
sum1 = 0
sum2 = 0
if len(fun) > 0:
	for s in range(len(fun)):
		sum1 += fun[-1 - s]
		store1.append(sum1)
dd = 0
if len(left) > 0:
	for s in range(len(left)):
		sum2 += left[-1 - s]
		store2.append(sum2)
		d1.append(dd)
		if dd >= n:
			break
		dd += d + 1
maxsofar = 0
if len(d1) > 0:
	for s in range(len(store1)):
		v1 = store1[s]
		d2 = s
		ind = min(bisect.bisect_left(d1, n - d2), len(d1) - 1)
		if d1[ind] + d2 >= n:
			ind -= 1
		v2 = store2[ind]
		ans = v1 + v2
		if ans > maxsofar:
			maxsofar = ans
else:
	maxsofar = sum(vals)
print(maxsofar)


(n, d, m) = map(int, input().split())
(*arr,) = map(int, input().split())
arr.sort()
big = sum((1 for v in arr if v > m))
n_large_slots = (n + d) // (d + 1)
large = []
small = []
while arr:
	v = arr.pop()
	if v > m:
		large.append(v)
	else:
		small.append(v)
small_sum = sum(small)
nsmall = len(small)
small.sort(reverse=True)
large.sort(reverse=True)
j = 0
if not large:
	print(small_sum)
else:
	s = small_sum
	ans = -1
	for i in range(1, min(n_large_slots, len(large)) + 1):
		s += large[i - 1]
		while len(small) > n - ((i - 1) * (d + 1) + 1):
			s -= small.pop()
		ans = max(ans, s)
	print(ans)


import math
import itertools
(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
a_lower = []
a_upper = []
for i in range(n):
	if a[i] <= m:
		a_lower.append(a[i])
	else:
		a_upper.append(a[i])
a_lower.sort(reverse=True)
a_upper.sort(reverse=True)
a_lower = list(itertools.accumulate(a_lower))
a_upper = list(itertools.accumulate(a_upper))
lower_length = len(a_lower)
upper_length = len(a_upper)
a_lower.insert(0, 0)
a_upper.insert(0, 0)
max_val = 0
for i in range(lower_length + 1):
	if math.ceil((n - i) / (d + 1)) > upper_length:
		continue
	else:
		max_val = max(max_val, a_lower[i] + a_upper[math.ceil((n - i) / (d + 1))])
print(max_val)


import math
(n, d, m) = input().split()
n = int(n)
d = int(d)
m = int(m)
A = list(map(int, input().split()))
rude = []
polite = []
for a in A:
	if a > m:
		rude += [a]
	else:
		polite += [a]
rude = sorted(rude)[::-1]
polite = sorted(polite)[::-1]
rude_prefix = [0]
for r in rude:
	rude_prefix += [rude_prefix[-1] + r]
for _ in range(n):
	rude_prefix += [rude_prefix[-1]]
polite_prefix = [0]
for p in polite:
	polite_prefix += [polite_prefix[-1] + p]
for _ in range(n):
	polite_prefix += [polite_prefix[-1]]
ans = float('-inf')
for np in range(len(polite) + 1):
	polite_score = polite_prefix[np]
	rude_cells = n - np
	num_rude = math.ceil(rude_cells / (d + 1))
	rude_score = rude_prefix[num_rude]
	ans = max(ans, polite_score + rude_score)
print(ans)


l = input().split()
n = int(l[0])
d = int(l[1])
m = int(l[2])
l = input().split()
li = [int(i) for i in l]
great = []
less = []
for i in li:
	if i > m:
		great.append(i)
	else:
		less.append(i)
great.sort()
less.sort()
prefg = [0]
prefl = [0]
gr = len(great)
le = len(less)
for i in great:
	prefg.append(prefg[-1] + i)
for i in less:
	prefl.append(prefl[-1] + i)
maxa = 10 ** 18
z = sum(li)
if gr == 0:
	print(z)
	quit()
for i in range(1, n // d + 2):
	for j in range(d):
		maxas = i
		rest = (i - 1) * d + j
		if maxas + (i - 1) * d + j > n:
			continue
		if gr < maxas:
			continue
		ans = prefg[gr - maxas]
		rest = rest - (gr - maxas)
		if rest > le or rest < 0:
			continue
		ans = ans + prefl[rest]
		maxa = min(maxa, ans)
print(z - maxa)


def solve(n, d, m, a):
	a.sort()
	small = sorted((x for x in a if x <= m))
	scs = [0]
	for x in small:
		scs.append(scs[-1] + x)
	sol = scs[-1]
	bn = n - len(small)
	(take, r, sbig, possible) = (1, n - 1, 0, True)
	while possible:
		skip = d * (take - 1)
		if a[r] > m and skip + take <= n:
			sbig += a[r]
			skip = max(skip - (bn - take), 0)
			ssmall = scs[-1] - scs[skip] if skip < len(scs) else 0
			sol = max(sol, sbig + ssmall)
			r -= 1
			take += 1
		else:
			possible = False
	return sol
(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, d, m, a))


from itertools import accumulate
(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
lo = []
hi = []
for x in a:
	if x <= m:
		lo.append(x)
	else:
		hi.append(x)
lo.sort(reverse=True)
lo_accum = list(accumulate(lo))
hi.sort(reverse=True)
hi_accum = list(accumulate(hi))
best = 0
if not hi:
	print(lo_accum[-1])
	exit()
for hi_chosen in range(1, len(hi) + 1):
	rem_hi = len(hi) - hi_chosen
	can_cover = hi_chosen * d
	if can_cover < rem_hi:
		continue
	must_cover = max((hi_chosen - 1) * d, rem_hi)
	lo_covered = max(0, must_cover - rem_hi)
	if lo_covered > len(lo):
		continue
	cur = 0
	cur += hi_accum[hi_chosen - 1]
	if lo_covered < len(lo):
		cur += lo_accum[len(lo) - lo_covered - 1]
	best = max(best, cur)
print(best)


(n, d, m) = map(int, input().split())
(n1, n2) = ([0 for i in range(d)], [])
for i in map(int, input().split()):
	if i > m:
		n2.append(i)
	else:
		n1.append(i)
out = su = sum(n1)
n1.sort(reverse=True)
n2.sort(reverse=True)
count = 0
for i in range(len(n2)):
	while n1 and count + len(n2) - i - 1 < (i + 1) * d:
		su -= n1.pop()
		count += 1
	su += n2[i]
	if count + len(n2) - i - 1 >= d * (i + 1):
		out = max(out, su)
print(out)


from sys import stdin
import sys
(n, d, m) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
a.sort()
a.reverse()
over = [0]
below = [0]
nuse = 0
for i in range(n):
	if a[i] > m:
		over.append(over[-1] + a[i])
	else:
		below.append(below[-1] + a[i])
ans = 0
if len(over) == 1:
	print(below[-1])
	sys.exit()
for l in range(n + 1):
	r = n - l
	if l > len(below) - 1:
		continue
	if r < len(over) - 1 or (len(over) - 1) * (d + 1) < r:
		continue
	ans = max(ans, below[l] + over[(r + d) // (d + 1)])
print(ans)


(n, d, m) = map(int, input().split())
ln = list(map(int, input().split()))
la = [u for u in ln if u <= m]
lb = [u for u in ln if u > m]
la.sort()
lb.sort()
(na, nb) = (len(la), len(lb))
(sma, smb) = ([0] * (na + 1), [0] * (nb + 1))
for i in range(1, na + 1):
	sma[i] += sma[i - 1] + la[i - 1]
for i in range(1, nb + 1):
	smb[i] += smb[i - 1] + lb[i - 1]
mx = 0
for u in range(nb + 1):
	(mxvc, mnvc) = (u * d, max(0, u - 1) * d)
	if nb - u > mxvc:
		continue
	sm = smb[nb] - smb[nb - u]
	cc = max(0, mnvc - (nb - u))
	if cc > na:
		continue
	sm += sma[na] - sma[cc]
	mx = max(mx, sm)
print(mx)


def solve():
	input_str = input().split()
	(n, d, m) = (int(input_str[0]), int(input_str[1]), int(input_str[2]))
	a = [0] + [int(x) for x in input().split()]
	a[1:] = sorted(a[1:], reverse=True)
	muzzle_days_cnt = 0
	for i in range(1, n + 1):
		if a[i] > m:
			muzzle_days_cnt += 1
		a[i] += a[i - 1]
	ans = 0
	if muzzle_days_cnt == 0:
		print(a[n])
		return 0
	for i in range(1, muzzle_days_cnt + 1):
		days_left = n - ((i - 1) * (d + 1) + 1)
		if days_left >= 0:
			ans = max(ans, a[min(n, muzzle_days_cnt + days_left)] - a[muzzle_days_cnt] + a[i])
	print(ans)
	return 0
solve()


(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
(e, f) = ([i for i in a if i <= m], [i for i in a if i > m])
e.sort(reverse=True)
f.sort(reverse=True)
c = len(e)
if c == n:
	print(sum(a))
	exit()
l = 1
r = min((n - 1) // (d + 1) + 1, len(f))
ans = sum(e)
(nowe, nowf) = (0, 0)
for i in range(l, r + 1):
	if i == l:
		nowe = sum(e[:n - (1 + (l - 1) * (d + 1))])
		nowf = sum(f[:l])
		ans = max(nowe + nowf, ans)
		continue
	nowe -= sum(e[n - (1 + (i - 1) * (d + 1)):n - (1 + (i - 1 - 1) * (d + 1))])
	nowf += f[i - 1]
	ans = max(nowe + nowf, ans)
print(ans)


import sys
input = sys.stdin.buffer.readline
(n, d, m) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
smaller = []
larger = []
for x in arr:
	if x > m:
		larger.append(x)
	else:
		smaller.append(x)
larger.sort(reverse=True)
smaller.sort(reverse=True)
psL = [0]
psS = [0]
for x in larger:
	psL.append(x + psL[-1])
for x in smaller:
	psS.append(x + psS[-1])
maxx = -float('inf')
for xL in range(len(larger) + 1):
	xLT = (xL - 1) * (d + 1) + 1
	xST = n - xLT
	xST = min(xST, len(smaller))
	if xST < 0:
		break
	total = psL[xL] + psS[xST]
	maxx = max(maxx, total)
print(maxx)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def solve(n, d, m, a):
	big = sorted([ai for ai in a if ai > m], reverse=True)
	small = sorted([ai for ai in a if ai <= m], reverse=True)
	bn = len(big)
	sn = len(small)
	ans = 0
	for x in range(bn + 1):
		taken = (x - 1) * (d + 1) + 1
		score = sum(a[:x])
		if taken > n:
			break
		rem = n - taken
		ans = max(ans, sum(big[:x]) + sum(small[:rem]))
	return ans

def main():
	(n, d, m) = ria()
	a = ria()
	wi(solve(n, d, m, a))
main()


(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
not_angry = []
angry = []
for i in range(n):
	if a[i] <= m:
		not_angry.append(a[i])
	else:
		angry.append(a[i])
not_angry.sort(reverse=True)
angry.sort(reverse=True)
not_angry = [0] + not_angry
angry = [0] + angry
for i in range(1, len(not_angry)):
	not_angry[i] += not_angry[i - 1]
for i in range(1, len(angry)):
	angry[i] += angry[i - 1]
ans = 0
for i in range(len(not_angry)):
	tmp = not_angry[i]
	q = min((n - i - 1) // (d + 1) + 1, len(angry) - 1)
	tmp += angry[q]
	ans = max(ans, tmp)
print(ans)


from collections import defaultdict
from queue import deque

def arrinp():
	return [*map(int, input().split(' '))]

def mulinp():
	return map(int, input().split(' '))

def intinp():
	return int(input())

def solution():
	(n, d, m) = mulinp()
	a = arrinp()
	a.sort()
	dp = [0]
	c = 0
	for j in range(n):
		dp.append(dp[-1] + a[j])
		if a[j] > m:
			c = c + 1
	res = dp[n - c]
	if a[-1] > m:
		res = res + a[-1]
	s = res
	for j in range(1, c):
		p = c - 1 - j
		q = dp[n - 1] - dp[n - 1 - j]
		nd = max(0, j * d - p)
		if nd > n - c:
			break
		else:
			s = max(s, res + q - dp[nd])
	print(s)
testcases = 1
for _ in range(testcases):
	solution()


(n, d, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
(sm, bg) = ([], [])
for i in range(n):
	if arr[i] > m:
		bg.append(arr[i])
	else:
		sm.append(arr[i])
bg.sort()
sm.sort()
bg.append(0)
sm.append(0)
bg = bg[-1::-1]
sm = sm[-1::-1]
ans = -10 ** 18
for i in range(1, len(sm)):
	sm[i] += sm[i - 1]
for i in range(1, len(bg)):
	bg[i] += bg[i - 1]
for i in range(len(sm)):
	s = sm[i]
	r = n - i
	c = (r + d) // (d + 1)
	c = min(c, len(bg) - 1)
	s += bg[c]
	ans = max(ans, s)
print(ans)


def main():
	(n, day, mood) = map(int, input().split())
	a = list(map(int, input().split()))
	out = []
	safe = []
	for v in a:
		if v <= mood:
			safe.append(v)
		else:
			out.append(v)
	safe.sort(reverse=True)
	out.sort(reverse=True)
	if not out:
		print(sum(safe))
		return
	safe.insert(0, 0)
	out.insert(0, 0)
	for i in range(1, len(safe)):
		safe[i] += safe[i - 1]
	for i in range(1, len(out)):
		out[i] += out[i - 1]
	ans = 0
	for l in range(len(out)):
		if l == 0:
			ans = max(ans, safe[min(n, len(safe) - 1)])
		else:
			possible = n - 1 - (day + 1) * (l - 1)
			if possible >= 0:
				ans = max(ans, safe[min(possible, len(safe) - 1)] + out[l])
	print(ans)
	return
main()


import sys
input = sys.stdin.readline
(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
up = []
down = []
for i in range(n):
	if a[i] > m:
		up.append(a[i])
	else:
		down.append(a[i])
up = sorted(up)
down = sorted(down)
if not up:
	print(sum(down))
	exit()
ans = 0
ans += up.pop()
(lap, rem) = divmod(n - 1, d + 1)
for i in range(rem):
	if not down:
		break
	else:
		ans += down.pop()
matome = []
while down:
	tmp = 0
	for _ in range(d + 1):
		if down:
			tmp += down.pop()
	matome.append(tmp)
matome = sorted(matome + up, reverse=True)
ans += sum(matome[0:min(lap, len(matome))])
print(ans)


(n, d, m) = map(int, input().split())
a = [*map(int, input().split())]
(s, b) = ([], [])
for i in a:
	if i <= m:
		s.append(i)
	else:
		b.append(i)
ans = 0
s.sort(reverse=True)
b.sort(reverse=True)
for i in range(1, len(s)):
	s[i] += s[i - 1]
for i in range(1, len(b)):
	b[i] += b[i - 1]
if len(b) == 0:
	print(s[-1])
	exit(0)
for i in range(len(b)):
	mx = i * (d + 1) + 1
	if mx > n:
		break
	res = 0
	rest = n - mx
	if rest == 0 or len(s) == 0:
		res += b[i]
		ans = max(ans, res)
		continue
	else:
		res = s[min(len(s) - 1, rest - 1)]
	res += b[i]
	ans = max(ans, res)
print(ans)


(n, d, m) = map(int, input().split())
arr = list(map(int, input().split()))
dp = [0] * (n + 1)
arr.sort()
count = 0
for i in range(n):
	dp[i + 1] = arr[i] + dp[i]
	if arr[i] <= m:
		count += 1
res = dp[count]
for i in range(1, n - count + 1):
	if (i - 1) * d + i > n:
		break
	res = max(res, dp[n] - dp[n - i] + dp[count] - dp[max(0, (i - 1) * d - (n - count - i))])
print(res)


(n, d, m) = map(int, input().split())
l = list(map(int, input().split()))
small = []
big = []
for i in l:
	if i <= m:
		small.append(i)
	else:
		big.append(i)
small.sort(reverse=True)
big.sort(reverse=True)
curr = 0
pre = [0]
for i in range(len(small)):
	pre.append(pre[-1] + small[i])
ans = pre[-1]
for i in range(len(big)):
	if i + 1 + i * d > n:
		break
	curr += big[i]
	ind = n - i * d - i - 1
	if ind > len(small):
		ind = len(small)
	if ind < 0:
		ind = 0
	temp = curr + pre[ind]
	ans = max(ans, temp)
print(ans)


import sys
readline = sys.stdin.readline
(N, D, M) = map(int, readline().split())
A = list(map(int, readline().split()))
Am = [a for a in A if a > M]
Ao = [a for a in A if a <= M]
Am.sort(reverse=True)
Ao.sort(reverse=True)
Cam = Am[:]
Cao = Ao[:]
for i in range(1, len(Cam)):
	Cam[i] += Cam[i - 1]
for i in range(1, len(Cao)):
	Cao[i] += Cao[i - 1]
k = -(-N // (D + 1))
ans = sum(Am[:k])
lcam = len(Cam)
Cam = [0] + Cam
for i in range(len(Cao)):
	k = min(lcam, -(-(N - (i + 1)) // (D + 1)))
	ans = max(ans, Cao[i] + Cam[k])
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def gns():
	return list(map(int, input().split()))
(n, d, m) = gns()
d += 1
ns = gns()
a = [x for x in ns if x <= m]
b = [x for x in ns if x > m]
a.sort(reverse=True)
b.sort(reverse=True)

def sm(x):
	for i in range(1, len(x)):
		x[i] += x[i - 1]
sm(a)
sm(b)
ans = 0
for i in range(len(a) + 1):
	j = n - i
	j = j // d + (j % d != 0)
	if j > len(b):
		continue
	s = (a[i - 1] if i > 0 else 0) + (b[j - 1] if j > 0 else 0)
	ans = max(ans, s)
print(ans)


t = 1
for test in range(t):
	(n, d, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	big = [each for each in arr if each > m]
	small = [each for each in arr if each <= m]
	big = [0] + sorted(big, reverse=True)
	small = [0] + sorted(small, reverse=True)
	for i in range(1, len(big)):
		big[i] += big[i - 1]
	for i in range(1, len(small)):
		small[i] += small[i - 1]
	ans = small[-1]
	for i in range(1, len(big)):
		days = (i - 1) * (d + 1) + 1
		if days <= n:
			ans = max(ans, big[i] + small[min(len(small) - 1, n - days)])
	print(ans)


import bisect
(n, d, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
f = {0: 0}
for i in range(n):
	f[i + 1] = f[i] + arr[i]
k = bisect.bisect_right(arr, m)
ans = 0
for nlo in range(k + 1):
	nhg = (n - nlo + d) // (d + 1)
	if nhg <= n - k:
		ans = max(ans, f[n] - f[n - nhg] + f[k] - f[k - nlo])
print(ans)


(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
(b, c) = ([], [])
for i in range(n):
	if a[i] <= m:
		b.append(a[i])
	else:
		c.append(a[i])
c.sort(reverse=True)
b.sort()
if len(b) == 0:
	j = len(c) - 1
	ans = 0
	for i in range(n):
		if i > j:
			break
		ans += c[i]
		j -= d
	print(ans)
	exit()
pref = [b[0]]
for i in range(1, len(b)):
	pref.append(pref[-1] + b[i])
ans = 0
maxx = sum(b)
for i in range(len(c)):
	ans += c[i]
	skip = i * d
	left = max(0, skip - (len(c) - i - 1))
	if left > len(pref):
		break
	if not left:
		maxx = max(maxx, ans + pref[-1])
	else:
		maxx = max(maxx, ans + pref[-1] - pref[left - 1])
print(maxx)


(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
p = []
q = []
for x in a:
	if x > m:
		p.append(x)
	else:
		q.append(x)
p = [0] + sorted(p, reverse=True)
q = [0] + sorted(q, reverse=True)
for i in range(len(p) - 1):
	p[i + 1] += p[i]
for i in range(len(q) - 1):
	q[i + 1] += q[i]
ans = 0
for t in range(len(p)):
	v = n + d - t * d - t
	if 0 <= v < len(q) + d:
		ans = max(ans, p[t] + q[min(v, len(q) - 1)])
print(ans)


(n, d, m) = map(int, input().split())
s = [int(x) for x in input().split()]
L1 = []
L2 = []
for i in range(0, len(s)):
	if s[i] <= m:
		L2.append(s[i])
	else:
		L1.append(s[i])
L1.sort()
L1 = L1[::-1]
L2.sort()
ans = 0
tt1 = len(L1) // (d + 1)
if len(L1) % (d + 1) != 0:
	tt1 += 1
for i in range(tt1):
	ans += L1[i]
for i in range(0, len(L2)):
	ans += L2[i]
kk = len(L1) % (d + 1)
if kk != 0:
	kk -= 1
else:
	kk = d
ptr = 0
c = 0
for i in range(tt1, len(L1)):
	ok = d
	rem = kk
	if i >= len(L1) - kk:
		ok = d - 1
		rem = kk - 1
	if ptr + ok - rem < len(L2):
		tot = 0
		for j in range(ptr, ptr + ok + 1 - rem):
			tot += L2[j]
		if tot < L1[i]:
			ans += L1[i]
			ans -= tot
			ptr += ok + 1 - rem
			kk = 0
		else:
			break
	else:
		break
print(ans)


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

def neo():
	return map(int, input().split())

def Neo():
	return list(map(int, input().split()))
(n, d, m) = neo()
A = Neo()
(G, L) = ([], [])
for i in A:
	if i > m:
		G.append(i)
	else:
		L.append(i)
G.sort(reverse=True)
L.sort()
Gpf = list(accumulate(G))
Lpf = list(accumulate(L))
Gpf = [0] + Gpf
Lpf = [0] + Lpf
Ans = []
for i in range(len(Gpf)):
	days = (i - 1) * (d + 1) + 1
	if days <= n:
		t = Gpf[i]
		rd = n - days
		t += Lpf[-1] - Lpf[max(0, len(Lpf) - rd - 1)]
		Ans.append(t)
print(max(Ans))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
(n, d, m) = sp()
arr = l()
(a, b) = ([], [])
for i in range(n):
	if arr[i] > m:
		a.append(arr[i])
	else:
		b.append(arr[i])
a.sort(reverse=True)
b.sort(reverse=True)
for i in range(1, len(a)):
	a[i] += a[i - 1]
for i in range(1, len(b)):
	b[i] += b[i - 1]
answer = max(a[0], b[-1]) if a and b else b[-1] if b else a[0]
for i in range(len(a)):
	temp = n - ((d + 1) * i + 1)
	if temp >= 0:
		answer = max(answer, a[i])
	temp -= 1
	if temp >= 0 and b:
		temp = min(temp, len(b) - 1)
		answer = max(answer, a[i] + b[temp])
		continue
out(answer)


from math import ceil
import sys
read = lambda : sys.stdin.readline().rstrip('\r\n')

def maxFun():
	(n, d, m) = map(int, read().split())
	nums = list(map(int, read().split()))
	nums.sort(reverse=True)
	smaller = list()
	larger = list()
	for i in nums:
		if i <= m:
			smaller.append(i)
		else:
			larger.append(i)
	large_len = len(larger)
	smaller = smaller + [0] * (n - len(smaller))
	larger = larger + [0] * (n - len(larger))
	large_suff = [0] * (n + 1)
	small_pre = [0] * (n + 1)
	for i in range(1, n + 1):
		small_pre[i] = small_pre[i - 1] + smaller[i - 1]
		large_suff[i] = large_suff[i - 1] + larger[i - 1]
	ans = small_pre[-1]
	for j in range(1, large_len + 1):
		pos = (j - 1) * (d + 1) + 1
		if pos > n:
			break
		ans = max(ans, large_suff[j] + small_pre[n - pos])
	print(ans)
maxFun()


from collections import deque as dq
from collections import defaultdict as dd
from collections import Counter as ct
from functools import lru_cache as lc
from heapq import heappush as hpush, heappop as hpop, heapify as hfy
from bisect import bisect_left, bisect_right
import itertools as it
import math
import sys
input = sys.stdin.readline

def solve():
	(N, D, M) = map(int, input().split())
	A = sorted(map(int, input().split()))
	if A[-1] <= M:
		print(sum(A))
		return
	PSum = [0]
	for a in A:
		PSum.append(PSum[-1] + a)
	x = bisect_right(A, M)
	ret = 0
	for i in range(N):
		if i and A[i - 1] > M:
			continue
		right_cnt = N - i
		trap_cnt = (right_cnt + D) // (D + 1)
		if A[-trap_cnt] <= M:
			continue
		candi = PSum[x] - PSum[x - i]
		idx = N - trap_cnt
		candi += PSum[N] - PSum[idx]
		ret = max(ret, candi)
	print(ret)
t = 1
for i in range(t):
	solve()


(n, d, m) = map(int, input().split())
arr = list(map(int, input().split()))
a = []
b = []
for i in arr:
	if i > m:
		a.append(i)
	else:
		b.append(i)
a.sort(reverse=True)
b.sort(reverse=True)
pref_a = [0] * (len(a) + 1)
pref_b = [0] * (len(b) + 1)
for i in range(len(a)):
	pref_a[i + 1] = pref_a[i] + a[i]
for i in range(len(b)):
	pref_b[i + 1] = pref_b[i] + b[i]
ans = sum(b)
for i in range(1, len(a) + 1):
	if (d + 1) * (i - 1) + 1 > n:
		break
	temp = pref_a[i]
	kk = n - (d + 1) * (i - 1) - 1
	kk = min(len(b), kk)
	temp += pref_b[kk]
	ans = max(temp, ans)
print(ans)


import sys
input = sys.stdin.readline
for _ in range(1):
	(n, d, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	(a, b) = ([], [])
	for i in arr:
		if i > m:
			a.append(i)
		else:
			b.append(i)
	a.sort(reverse=True)
	b.sort(reverse=True)
	for i in range(1, len(a)):
		a[i] += a[i - 1]
	for i in range(1, len(b)):
		b[i] += b[i - 1]
	if a and b:
		ans = max(a[0], b[-1])
	elif a:
		ans = a[0]
	else:
		ans = b[-1]
	for i in range(len(a)):
		rem = n - ((d + 1) * i + 1)
		if rem >= 0:
			ans = max(ans, a[i])
		rem -= 1
		if rem >= 0 and b:
			rem = min(rem, len(b) - 1)
			ans = max(ans, a[i] + b[rem])
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from math import ceil, floor, sqrt
(n, d, m) = RL()
a = RLL()
big = 0
for i in a:
	if i > m:
		big += 1
small = n - big
(l, h) = (sorted([i for i in a if i <= m], reverse=True), sorted([i for i in a if i > m], reverse=True))
sl = [0]
for i in range(small):
	sl.append(sl[-1] + l[i])
sh = [0]
for i in range(big):
	sh.append(sh[-1] + h[i])
res = 0
for i in range(ceil(big / (d + 1)), min(big, ceil(n / (d + 1))) + 1):
	j = small - max(0, d * (i - 1) - (big - i))
	res = max(res, sh[i] + sl[j])
print(res)


import sys
import math
input = sys.stdin.readline
(n, d, m) = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
small = []
big = []
for a in A:
	if a > m:
		big.append(a)
	else:
		small.append(a)
small.sort(reverse=True)
big.sort(reverse=True)
small_sums = [s for s in small]
big_sums = [b for b in big]
for i in range(1, len(small)):
	small_sums[i] += small_sums[i - 1]
for i in range(1, len(big)):
	big_sums[i] += big_sums[i - 1]
ans = 0
for big_used in range(len(big) + 1):
	used_and_wasted = 1 + (big_used - 1) * (d + 1) if big_used != 0 else 0
	rest = n - used_and_wasted
	if used_and_wasted < 0 or rest < 0:
		continue
	local_ans = 0
	if big_used:
		local_ans += big_sums[big_used - 1]
	if rest > 0 and small:
		local_ans += small_sums[min(rest, len(small)) - 1]
	ans = max(ans, local_ans)
print(ans)


import sys
input = sys.stdin.buffer.readline

def solution():
	(n, d, m) = map(int, input().split())
	a = list(map(int, input().split()))
	g = []
	l = []
	for i in range(n):
		if a[i] > m:
			g.append(a[i])
		else:
			l.append(a[i])
	g.sort(reverse=True)
	l.sort(reverse=True)
	if g == []:
		print(sum(l))
	else:
		for i in range(1, len(l)):
			l[i] += l[i - 1]
		for i in range(1, len(g)):
			g[i] += g[i - 1]
		l = [0] + l
		k = len(g)
		x = l[-1]
		for i in range(k, 10 ** 5 + 6):
			g.append(0)
		for i in range(len(l), 10 ** 5 + 6):
			l.append(x)
		ans = 0
		for i in range((k + d) // (1 + d), k + 1):
			x = (i - 1) * (d + 1) + 1
			if x <= n:
				s = g[i - 1] + l[n - x]
				ans = max(ans, s)
		print(ans)
t = 1
for _ in range(t):
	solution()


(n, d, m) = map(int, input().split())
ar = list(map(int, input().split()))
(n1, n2) = ([0 for i in range(d)], [])
for i in range(n):
	if ar[i] > m:
		n2.append(ar[i])
	else:
		n1.append(ar[i])
n1.sort()
n2.sort()
out = su = sum(n1)
n1.sort()
n2.sort()
j = 0
for i in range(len(n2) - 1, -1, -1):
	while j < len(n1) and i + j < d * (len(n2) - i):
		su -= n1[j]
		j += 1
	su += n2[i]
	if i + j >= d * (len(n2) - i):
		out = max(out, su)
print(out)


(n, d, m) = [int(inp) for inp in input().split()]
aArr = sorted([int(inp) for inp in input().split()], reverse=True)
i = sum([j > m for j in aArr])
aU = aArr[:i]
aL = aArr[i:]
aUS = aU
for i in range(1, len(aU)):
	aUS[i] += aUS[i - 1]
aUS = [0] + aUS
aLS = aL
for i in range(1, len(aL)):
	aLS[i] += aLS[i - 1]
aLS = [0] + aLS
fromU = min(1 + (n - 1) // (d + 1), len(aU))
maxFun = aUS[0] + aLS[-1]
for j in range(1, fromU + 1):
	newFun = aUS[j] + aLS[min(max(0, n - 1 - (j - 1) * (d + 1)), len(aL))]
	if newFun > maxFun:
		maxFun = newFun
print(maxFun)


(n, d, m) = map(int, input().split())
u = list(map(int, input().split()))
a = []
b = []
for i in range(n):
	if u[i] > m:
		a.append(u[i])
	else:
		b.append(u[i])
if len(a) == 0:
	print(sum(b))
	exit()
La = len(a)
Lb = len(b)
a.sort(reverse=1)
b.sort(reverse=1)
a.append(0)
b.append(0)
for i in range(La):
	a[i] += a[i - 1]
for i in range(Lb):
	b[i] += b[i - 1]
cnt = min(La, (n - 1) // (d + 1) + 1)
ans = 0
for i in range(cnt, 0, -1):
	free = n - i - d * (i - 1)
	if free - d > Lb:
		continue
	cur = a[i - 1] + b[min(free, Lb) - 1]
	ans = max(ans, cur)
print(ans)


import sys
import math
input = sys.stdin.readline
(n, d, m) = map(int, input().split())
a = [int(i) for i in input().split() if i != '\n']
a.sort()
lo = -1
for i in range(n):
	if a[i] > m:
		lo = i
		break
pref = [0]
for i in range(n):
	pref.append(pref[-1] + a[i])
if n <= d + 1:
	if lo == -1:
		print(pref[lo])
	else:
		print(pref[lo] + a[-1])
else:
	ans = 0
	if (n - 1) % (d + 1) == 0:
		pq = math.ceil((n - 1) / (d + 1)) + 1
	else:
		pq = math.ceil((n - 1) / (d + 1))
	pos = min(n - lo, pq)
	hi = n - pos
	for i in range(hi, n):
		ans += a[i]
	lo -= 1
	for i in range((pos - 1) * (d + 1), n - 1):
		if lo < 0:
			break
		ans += a[lo]
		lo -= 1
	lo += 1
	while True:
		if lo < 0 or hi >= n:
			break
		if pref[lo] - pref[max(0, lo - d - 1)] > a[hi]:
			ans -= a[hi]
			ans += pref[lo] - pref[max(0, lo - d - 1)]
			lo -= d + 1
			hi += 1
		else:
			break
	print(ans)


import sys
(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
S = sum(a)
a1 = []
a2 = []
for ai in a:
	if ai > m:
		a2.append(ai)
	else:
		a1.append(ai)
a1.sort()
a2.sort()
c1 = [0]
c2 = [0]
for ai in a1:
	c1.append(c1[-1] + ai)
for ai in a2:
	c2.append(c2[-1] + ai)
if len(a2) == 0:
	print(S)
	sys.exit()
ans = 0
for angry_day in range(0, len(a2) + 1):
	nokori = (angry_day - 1) * d - (len(a2) - angry_day)
	if nokori < 0 and nokori > -d:
		nokori = 0
	if nokori >= 0 and nokori <= len(a1):
		ans = max(ans, S - c2[len(a2) - angry_day] - c1[nokori])
print(ans)


import sys, math
input = sys.stdin.readline
(n, d, m) = map(int, input().split())
l = list(map(int, input().split()))
lessThanM = []
greaterThanM = []
for i in l:
	if i > m:
		greaterThanM.append(i)
	else:
		lessThanM.append(i)
lessThanM.sort(reverse=True)
greaterThanM.sort(reverse=True)
lessN = len(lessThanM)
greaterN = len(greaterThanM)
prefix = []
for i in range(lessN):
	if i == 0:
		prefix.append(lessThanM[0])
	else:
		prefix.append(lessThanM[i] + prefix[i - 1])
if greaterN == 0:
	print(prefix[lessN - 1])
else:
	ans = greaterThanM[0]
	if lessN > 0:
		ans += prefix[lessN - 1]
	greaterOne = greaterThanM[0]
	for i in range(1, greaterN):
		greaterOne += greaterThanM[i]
		index = n - (1 + i * (d + 1))
		index = min(index, lessN)
		if index == 0:
			ans = max(ans, greaterOne)
		elif index > 0:
			ans = max(ans, greaterOne + prefix[index - 1])
	print(ans)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, D, M, A):
	D += 1
	notMad = [a for a in A if a <= M]
	mad = [a for a in A if a > M]
	notMad.sort(reverse=True)
	mad.sort(reverse=True)
	pref = [0]
	for x in notMad:
		pref.append(pref[-1] + x)
	pref2 = [0]
	for x in mad:
		pref2.append(pref2[-1] + x)
	best = 0
	for i in range(len(notMad) + 1):
		j = N - i
		takeMad = j // D
		if j % D != 0:
			takeMad += 1
		if takeMad < len(pref2):
			best = max(best, pref[i] + pref2[takeMad])
	return best
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N, D, M) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, D, M, A)
print(ans)


import os, sys
from io import BytesIO, IOBase

def main():
	(n, d, m) = map(int, input().split())
	a = list(map(int, input().split()))
	bi = sorted(filter(lambda x: x > m, a), reverse=1)
	sm = sorted(filter(lambda x: x <= m, a))
	if not len(bi):
		print(sum(sm))
	elif not len(sm):
		print(sum(bi[:len(bi) // (d + 1) + (len(bi) % (d + 1) != 0)]))
	else:
		ans = sum(sm) + bi[0]
		(val, j) = (ans, 0)
		for i in range(1, len(bi)):
			val += bi[i]
			for xx in range(j, min(i * d - len(bi) + i + 1, len(sm))):
				val -= sm[xx]
				j += 1
			if i * d >= len(sm) + len(bi) - i:
				break
			ans = max(ans, val)
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, d, m) = map(int, input().split())
a = [int(v) for v in input().split()]
a.sort()
dp = [0]
c = 0
for j in range(n):
	dp.append(dp[-1] + a[j])
	if a[j] > m:
		c = c + 1
res = dp[n - c]
if a[-1] > m:
	res = res + a[-1]
s = res
q = 0
for j in range(1, c):
	p = c - 1 - j
	q = q + a[-j - 1]
	nd = max(0, j * d - p)
	if nd > n - c:
		break
	else:
		s = max(s, res + q - dp[nd])
print(s)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
(n, d, m) = R()
bg = []
sm = []
for i in R():
	if i > m:
		bg += (i,)
	else:
		sm += (i,)
bg.sort(reverse=True)
sm.sort(reverse=True)
bg = [0] + bg
sm = [0] + sm
x = len(bg)
for i in range(1, x):
	bg[i] += bg[i - 1]
y = len(sm)
for i in range(1, y):
	sm[i] += sm[i - 1]
ans = 0
x -= 1
y -= 1
for i in range(1, x + 1):
	if (i - 1) * (d + 1) + 1 > n:
		break
	ans = max(ans, bg[i] + sm[min(y, n - ((i - 1) * (d + 1) + 1))])
print(ans + (sm[-1] if not x else 0))


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def solve():
	pre = []
	pos = []
	for a in aa:
		if a > m:
			pos.append(a)
		else:
			pre.append(a)
	pos.sort(reverse=True)
	pre.sort(reverse=True)
	cs = [0]
	for a in pre:
		cs.append(cs[-1] + a)
	pre = cs
	cs = [0]
	for a in pos:
		cs.append(cs[-1] + a)
	pos = cs
	ans = 0
	for i in range(len(pre)):
		j = min((n - i - 1) // (d + 1) + 1, len(pos) - 1)
		cur = pre[i] + pos[j]
		ans = max(ans, cur)
	print(ans)
(n, d, m) = MI()
aa = MI()
solve()


(n, d, m) = tuple(map(int, input().split()))
arr = sorted(list(map(int, input().split())), reverse=True)
(good, bad) = ([], [])
for i in arr:
	if i <= m:
		good.append(i)
	else:
		bad.append(i)
good_pref = [0]
for i in range(len(good)):
	good_pref.append(good_pref[i] + good[i])
bad_pref = [0]
for i in range(len(bad)):
	bad_pref.append(bad_pref[i] + bad[i])
min_bad = (len(bad) - 1) // (d + 1) + 1
max_bad = n // (d + 1)
if n % (d + 1) != 0:
	max_bad += 1
max_bad = min(max_bad, len(bad))
ans = 0
for bad_block in range(min_bad, max_bad + 1):
	if bad_block == 0:
		ans = good_pref[-1]
		continue
	worst_good = max(0, (d + 1) * bad_block - d - len(bad))
	now = bad_pref[bad_block] + good_pref[-worst_good - 1]
	ans = max(ans, now)
print(ans)


(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
(small, big) = ([], [])
for i in a:
	if i > m:
		big.append(i)
	else:
		small.append(i)
small.sort(reverse=True)
big.sort(reverse=True)
res = 0
if len(small) == 0:
	cnt = int((n + d) / (d + 1))
	for i in range(cnt):
		res += big[i]
elif len(big) == 0:
	res = 0
	for i in range(n):
		res += small[i]
else:
	sum = [small[0]]
	for i in range(1, len(small)):
		sum.append(sum[i - 1] + small[i])
	tot = 0
	for i in range(len(big)):
		tot += big[i]
		rem = min(n - (i * (d + 1) + 1), len(sum))
		if rem == 0:
			res = max(res, tot)
		elif rem > 0:
			res = max(res, tot + sum[rem - 1])
		else:
			break
print(res)


(N, D, M) = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
L = [a for a in A if a > M]
S = [a for a in A if a <= M]
cum_S = [0]
c = 0
for s in S:
	c += s
	cum_S.append(c)
d = N - 1
ans = max(A)
if len(L) == 0:
	print(sum(S))
	exit()
cum_L = 0
for (n, l) in enumerate(L, 1):
	cum_L += l
	if d < 0:
		break
	need = (n - 1) * D
	if not len(L) - n <= need:
		if len(L) - n <= need + D:
			need = len(L) - n
		else:
			d -= D + 1
			continue
	n_s = need - (len(L) - n)
	an = cum_S[max(0, len(S) - n_s)] + cum_L
	ans = max(ans, an)
	d -= D + 1
print(ans)


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, d, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
s = []
b = []
for i in a:
	if i <= m:
		s.append(i)
	else:
		b.append(i)
s.sort(reverse=1)
b.sort(reverse=1)
b.insert(0, 0)
s.insert(0, 0)
for i in range(1, len(b)):
	b[i] += b[i - 1]
for i in range(1, len(s)):
	s[i] += s[i - 1]
ans = 0
maxi = (n - 1) // (d + 1) + 1
for i in range(len(b)):
	if i > maxi:
		break
	tans = b[i]
	spent = 0
	if i != 0:
		spent = (i - 1) * (d + 1) + 1
	rem = n - spent
	tans += s[min(rem, len(s) - 1)]
	ans = max(ans, tans)
print(ans)


from itertools import accumulate

def main():
	(n, d, m) = map(int, input().split())
	A = list(map(int, input().split()))
	A_low = []
	A_high = []
	for a in A:
		if a <= m:
			A_low.append(a)
		else:
			A_high.append(a)
	Ll = len(A_low)
	Lh = len(A_high)
	A_low.sort(reverse=True)
	A_high.sort(reverse=True)
	accA_high = [0] + list(accumulate(A_high))
	t = (n + d) // (d + 1)
	if t <= Lh:
		ans = accA_high[(n + d) // (d + 1)]
	else:
		ans = accA_high[-1]
	low = 0
	for i in range(Ll):
		low += A_low[i]
		t = (n - i - 1 + d) // (d + 1)
		if t <= Lh:
			high = accA_high[(n - i - 1 + d) // (d + 1)]
		else:
			high = accA_high[-1]
		if low + high > ans:
			ans = low + high
	print(ans)
main()


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
(n, d, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
l = deque(l)
a = []
while l:
	if l[0] <= m:
		a.append(l.popleft())
	else:
		break
if len(l) == 0:
	print(sum(a))
else:
	count = l.pop()
	z = 0
	x = 1
	a.reverse()
	a = deque(a)
	for i in range(min(d + 1, len(a))):
		z += a[i]
	f = d + 1
	while l and x < n:
		if len(a) > 0 and (z >= l[-1] or d + 1 > n - x):
			y = a.popleft()
			count += y
			z -= y
			if f < len(a):
				z += a[f]
			x += 1
		elif d + 1 <= n - x:
			count += l.pop()
			x += d + 1
		else:
			break
	if x < n and len(a) > 0:
		for i in range(x, n):
			if a:
				count += a.popleft()
	print(count)


import sys, collections
(n, d, m) = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
big = []
small = []
for i in arr:
	if i > m:
		big.append(i)
	else:
		small.append(i)
big.sort(reverse=True)
small.sort(reverse=True)
big = [0] + big
small = [0] + small
for i in range(2, len(big)):
	big[i] = big[i] + big[i - 1]
for i in range(2, len(small)):
	small[i] = small[i] + small[i - 1]
ans = 0
for i in range(len(small)):
	left_days = n - i
	if left_days < 0:
		continue
	if left_days % (d + 1) == 0:
		k = left_days // (d + 1)
	else:
		k = left_days // (d + 1) + 1
	if k >= len(big):
		k = len(big) - 1
	if k < 0:
		k = 0
	ans = max(ans, small[i] + big[k])
print(ans)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
sys.setrecursionlimit(300000)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, d, m) = map(int, input().split())
l = list(map(int, input().split()))
small = []
big = []
l.sort()
if l[-1] <= m:
	print(sum(l))
	sys.exit(0)
for i in range(n):
	if l[i] <= m:
		small.append(l[i])
	else:
		big.append(l[i])
small.sort(reverse=True)
big.sort(reverse=True)
s = SegmentTree(small)
s1 = SegmentTree(big)

def check(mid):
	ans = 0
	ans += s1.query(0, mid - 1)
	er = n - (mid - 1) * (d + 1) - 1
	if er < 0:
		return -1
	if er > len(small):
		er = len(small)
	ans += s.query(0, er - 1)
	return ans
ans = 0
for i in range(len(big) + 1):
	ch = check(i)
	if ch == -1:
		continue
	else:
		ans = max(ans, ch)
print(ans)


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1
while t > 0:
	t -= 1
	(n, d, m) = mi()
	a = li()
	a.sort()
	pre = [a[0]]
	maxi = 0
	z = -1
	if a[0] <= m:
		maxi += a[0]
	else:
		z = 0
	for i in range(1, n):
		pre.append(pre[-1] + a[i])
		if a[i] <= m:
			maxi += a[i]
		elif z == -1:
			z = i
	suf = [a[n - 1]]
	for i in range(n - 2, -1, -1):
		suf.append(suf[-1] + a[i])
	pre.append(0)
	for i in range(n - 1, -1, -1):
		c = 0
		if a[i] > m:
			if i == n - 1:
				c = suf[n - i - 1] + pre[z - 1] + a[i - 1] if z + d < n - 1 else suf[n - i - 1] + pre[z - 1]
				maxi = max(maxi, c)
				continue
			if (n - i - 1) * d >= i + 1:
				continue
			p = i - z
			q = (n - i - 1) * d - p
			if q > 0:
				c = suf[n - i - 1] + pre[z - 1] - pre[q - 1]
			else:
				c = pre[z - 1] + suf[n - i - 1]
		else:
			break
		maxi = max(maxi, c)
	print(maxi)


(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
less = []
more = []
for i in a:
	if i > m:
		more.append(i)
	else:
		less.append(i)
less.sort(reverse=True)
more.sort(reverse=True)
lessp = []
if len(less) > 0:
	lessp = [less[0]]
	for i in less[1:]:
		lessp.append(lessp[-1] + i)
morep = []
if len(more) > 0:
	morep = [more[0]]
	for i in more[1:]:
		morep.append(morep[-1] + i)
ans = 0
for i in range(-1, len(more)):
	high = 0
	if len(morep) > 0 and i >= 0:
		high = morep[i]
	if i * (d + 1) + 1 > n:
		break
	sec = n - i * (d + 1) - 1
	if i + 1 == 0:
		sec = n
		high = 0
	if sec > len(lessp):
		sec = len(lessp)
	low = 0
	if len(lessp) > 0 and sec > 0:
		low = lessp[sec - 1]
	ans = max(ans, high + low)
print(ans)


def solve():
	(n, d, m) = map(int, input().split())
	a = list(map(int, input().split()))
	f = list()
	g = list()
	for x in a:
		if x > m:
			f.append(x)
		else:
			g.append(x)
	f.sort(reverse=True)
	g.sort(reverse=True)
	ng = len(g)
	a = [0] * (ng + 1)
	for i in range(ng):
		a[i + 1] = a[i] + g[i]
	ans = a[ng]
	cur = 0
	for i in range(len(f)):
		if i + 1 + i * d > n:
			break
		cur += f[i]
		v = n - i * d - i - 1
		if v > ng:
			v = ng
		if v < 0:
			v = 0
		if ans < cur + a[v]:
			ans = cur + a[v]
	print(ans)
	return
solve()


import os
from io import BytesIO, IOBase
import sys

def main():
	(n, d, m) = map(int, input().split())
	a = sorted(map(int, input().split()), reverse=True)
	(b, c) = ([], [])
	for i in range(n):
		if a[i] > m:
			b.append(a[i])
		else:
			c.append(a[i])
	if b == []:
		print(sum(c))
	else:
		(nb, nc, e, ma, su) = (len(b), len(c), [0], 0, 0)
		for i in c:
			e.append(e[-1] + i)
		for i in range(1, nb + 1):
			z = n - (i - 1) * (d + 1) - 1
			su += b[i - 1]
			if z >= nc:
				ma = max(ma, su + e[-1])
			elif z >= 0:
				ma = max(ma, su + e[z])
			else:
				break
		print(ma)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
(N, D, M) = map(int, input().split())
X = list(map(int, input().split()))
(Y, Z) = ([], [])
for i in range(N):
	if X[i] > M:
		Y.append(X[i])
	else:
		Z.append(X[i])
X.sort()
Y.sort()
Z.sort()
X = X[::-1]
Y = Y[::-1]
Z = Z[::-1]
zs = 0
yk = -(-N // (D + 1))
ys = sum(Y[:min(yk, len(Y))])
R = 0
for zn in range(len(Z) + 1):
	if zn > 0:
		zs += Z[zn - 1]
	yn = N - zn
	R = max(R, zs + ys)
	if yn % (D + 1) == 1 and yk > 0:
		yk -= 1
		if yk < len(Y):
			ys -= Y[yk]
print(R)


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import defaultdict
import heapq
from math import ceil, floor

def main():
	(n, d, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	a = [i for i in arr if i <= m]
	b = [i for i in arr if i > m]
	a.sort(reverse=True)
	b.sort()
	ans = 0
	pref = [0]
	for i in a:
		pref.append(pref[-1] + i)
	suf = [0]
	for i in b[::-1]:
		suf.append(suf[-1] + i)
	k = n // (d + 1) + (1 if n % (d + 1) else 0)
	k = min(k, len(b))
	ans = pref[-1]
	while k:
		inb = (k - 1) * d
		ans = max(ans, suf[k] + pref[len(a) - max(0, inb - (len(b) - k))])
		k -= 1
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(1):
	main()


from itertools import accumulate

def chat(n, d, m, arr):
	lem = []
	gtm = []
	for x in arr:
		if x <= m:
			lem.append(x)
		else:
			gtm.append(x)
	lem.sort(reverse=True)
	gtm.sort(reverse=True)
	prel = [0] + list(accumulate(lem))
	preg = [0] + list(accumulate(gtm))
	ans = prel[-1]
	for k in range(1, min(len(gtm), (n - 1) // (d + 1) + 1) + 1):
		ans = max(ans, preg[k] + prel[min(n - (k - 1) * d - k, len(lem))])
	return ans
(n, d, m) = map(int, input().split())
arr = list(map(int, input().split()))
print(chat(n, d, m, arr))


(n, d, m) = map(int, input().split())
a = [int(o) for o in input().split()]
bada = []
chota = []
for i in a:
	if i > m:
		bada.append(i)
	else:
		chota.append(i)
bada.sort()
chota.sort()
bada = bada[::-1]
lb = len(bada)
lc = len(chota)
pb = [0] * (lb + 1)
pc = [0] * (lc + 1)
for i in range(lb):
	pb[i + 1] = pb[i] + bada[i]
for i in range(lc):
	pc[i + 1] = pc[i] + chota[i]
aa = []
lcp = len(pc)
for i in range(len(pb)):
	days = (i - 1) * (d + 1) + 1
	if days <= n:
		ans = pb[i]
		rd = n - days
		ans += pc[-1] - pc[max(lcp - rd - 1, 0)]
		aa.append(ans)
print(max(aa))


(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
bigJoke = []
smallJoke = []
for elem in a:
	if elem > m:
		bigJoke.append(elem)
	else:
		smallJoke.append(elem)
bigJoke.sort(reverse=True)
smallJoke.sort(reverse=True)
bigJokePartialSum = [0]
smallJokePartialSum = [0]
for elem in bigJoke:
	bigJokePartialSum.append(bigJokePartialSum[-1] + elem)
for elem in smallJoke:
	smallJokePartialSum.append(smallJokePartialSum[-1] + elem)
maxSum = 0
for i in range(len(bigJokePartialSum)):
	if n - (d + 1) * (i - 1) - 1 < 0:
		break
	if i == 0:
		currentSum = smallJokePartialSum[-1]
	else:
		currentSum = bigJokePartialSum[i]
		currentSum += smallJokePartialSum[min(len(smallJokePartialSum) - 1, n - (d + 1) * (i - 1) - 1)]
	if currentSum > maxSum:
		maxSum = currentSum
print(maxSum)


from math import ceil
[n, d, m] = list(map(int, input().split()))
fun_fact = list(map(int, input().split()))
fun_fact.sort()
if n == 1 or fun_fact[-1] <= m:
	print(sum(fun_fact))
else:
	idx = 0
	(sm_big, sm_small) = ([0], [0])
	while idx < n and fun_fact[idx] <= m:
		sm_small.append(sm_small[-1] + fun_fact[idx])
		idx += 1
	till = idx
	idx = n - 1
	while idx >= till:
		sm_big.append(sm_big[-1] + fun_fact[idx])
		idx -= 1
	(total_big, mx) = (n - till, 0)
	chosen = 0
	while (chosen - 1) * d + chosen <= n and chosen <= total_big:
		waste = max(0, (chosen - 1) * d + chosen - total_big)
		mx = max(mx, sm_big[chosen] + sm_small[till] - sm_small[min(waste, till)])
		chosen += 1
	print(mx)


def solve(n, m, d, nums):
	if not nums:
		return 0
	nums.sort(key=lambda x: x * -1)
	smalls = [0]
	bigs = [0]
	for num in nums:
		if num <= m:
			smalls.append(smalls[-1] + num)
		else:
			bigs.append(bigs[-1] + num)
	ans = 0
	for (x, big) in enumerate(bigs):
		y = n if not x else n - (x - 1) * (d + 1) - 1
		y = min(y, len(smalls) - 1)
		if y < 0:
			break
		ans = max(ans, smalls[y] + big)
	return ans
(n, d, m) = list(map(int, input().split(' ')))
nums = list(map(int, input().split(' ')))
print(solve(n, m, d, nums))


data = [*open(0)]
di = lambda x: map(int, data[x].split())
(n, d, m) = (*di(0),)
a = (*di(1),)
l1 = []
l2 = []
for ai in a:
	if ai > m:
		l1.append(-ai)
	else:
		l2.append(-ai)
l1.sort()
l2.sort()
ans = 0
l1.insert(0, 0)
l2.insert(0, 0)
m1 = len(l1)
m2 = len(l2)
for i in range(1, m1):
	l1[i] = l1[i] + l1[i - 1]
for i in range(1, m2):
	l2[i] = l2[i] + l2[i - 1]
for i in range(m2):
	k = (m2 + m1 - i + d - 2) // (d + 1)
	if k < m1:
		ans = max(ans, -l1[k] - l2[i])
print(ans)


import sys
input = sys.stdin.readline
(n, d, m) = map(int, input().split())
a = [int(item) for item in input().split()]
muzzle = []
no_muzzle = []
for item in a:
	if item <= m:
		no_muzzle.append(item)
	else:
		muzzle.append(item)
no_muzzle.sort(reverse=True)
muzzle.sort(reverse=True)
max_mnum = (n + d) // (d + 1)
ans = 0
for cnt in range(min(len(muzzle), max_mnum) + 1):
	max_nom = n - (cnt + (cnt - 1) * d)
	min_nom = max(0, n - (d + 1) * cnt)
	if len(no_muzzle) < min_nom:
		continue
	nom_num = min(max_nom, len(no_muzzle))
	ret = sum(muzzle[:cnt]) + sum(no_muzzle[:nom_num])
	ans = max(ans, ret)
print(ans)


import sys
input = sys.stdin.readline
from collections import *
(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
(h, l) = ([], [])
for ai in a:
	if ai > m:
		h.append(ai)
	else:
		l.append(ai)
h.sort(reverse=True)
l.sort(reverse=True)
acch = [0]
for hi in h:
	acch.append(acch[-1] + hi)
accl = [0]
for li in l:
	accl.append(accl[-1] + li)
ans = 0
for i in range(len(h) + 1):
	if len(h) - i > d * i:
		continue
	vain = max(d * (i - 1), len(h) - i) - (len(h) - i)
	if vain > len(l):
		continue
	ans = max(ans, acch[i] + accl[len(l) - vain])
print(ans)


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(N, D, M, A):
	l = []
	s = []
	for a in A:
		if a > M:
			l.append(a)
		else:
			s.append(a)
	l.sort()
	s.sort()
	ss = []
	D += 1
	n = N - 1
	r = n % D
	ans = 0
	for _ in range(r):
		if s:
			ans += s.pop()
	while len(s) >= D:
		t = 0
		tt = []
		for _ in range(D):
			a = s.pop()
			t += a
			tt.append(a)
		ss.append((t, D, tt))
	if s:
		ss.append((sum(s), len(s), s))
	ss.reverse()
	if l:
		ans += l.pop()
	else:
		ans += ss.pop()[0]
	for i in range(n // D):
		if l and ss:
			if l[-1] >= ss[-1][0]:
				ans += l.pop()
			else:
				(a, b, c) = ss.pop()
				ans += a
		elif l:
			ans += l.pop()
		else:
			(a, b, c) = ss.pop()
			ans += a
	return ans

def main():
	(N, D, M) = read_int_n()
	A = read_int_n()
	print(slv(N, D, M, A))
main()


def gt():
	return list(map(int, input().split()))

def gtsum(x):
	ret = x.copy()
	for i in range(1, len(x)):
		ret[i] += ret[i - 1]
	return ret
ans = 0
(n, d, m) = gt()
a = gt()
a.sort()
low = []
high = []
for val in a:
	if val <= m:
		low.append(val)
	else:
		high.append(val)
sum_low = [0] + gtsum(low)
sum_high = [0] + gtsum(high)
for i in range(len(low) + 1):
	allow = (n - i + d) // (d + 1)
	if allow <= len(high):
		ans = max(ans, sum_high[-1] - sum_high[-1 - allow] + sum_low[-1] - sum_low[-1 - i])
print(ans)


def gns():
	return list(map(int, input().split()))
(n, d, m) = gns()
d += 1
ns = gns()
a = [x for x in ns if x <= m]
b = [x for x in ns if x > m]
a.sort(reverse=True)
b.sort(reverse=True)

def sm(x):
	for i in range(1, len(x)):
		x[i] += x[i - 1]
sm(a)
sm(b)
ans = 0
for i in range(len(a) + 1):
	j = n - i
	j = j // d + (j % d != 0)
	if j > len(b):
		continue
	s = (a[i - 1] if i > 0 else 0) + (b[j - 1] if j > 0 else 0)
	ans = max(ans, s)
print(ans)


from sys import stdin, stdout

def Boboniu_Chats_with_Du(n, d, m, a_a):
	b_a = []
	c_a = []
	res = 0
	for a in a_a:
		if a > m:
			b_a.append(a)
		else:
			c_a.append(a)
			res += a
	if not b_a:
		return res
	b_a.sort(reverse=True)
	c_a.sort()
	d += 1
	blen = len(b_a)
	bidx = blen // d + (1 if blen % d > 0 else 0)
	cidx = 0
	for i in range(bidx):
		res += b_a[i]
	while bidx < len(b_a):
		if blen % d == 0:
			blen2 = blen + 1
		else:
			blen2 = (blen // d + 1) * d + 1
		if cidx + blen2 - blen > len(c_a):
			break
		csum = 0
		for i in range(cidx, cidx + blen2 - blen):
			csum += c_a[i]
			cidx += 1
		if csum >= b_a[bidx]:
			break
		res += b_a[bidx] - csum
		bidx += 1
		blen = blen2
	return res
(n, d, m) = map(int, stdin.readline().split())
a_a = list(map(int, stdin.readline().split()))
stdout.write(str(Boboniu_Chats_with_Du(n, d, m, a_a)) + '\n')


from math import inf, log2

class SegmentTree:

	def __init__(self, array, func=max):
		self.n = len(array)
		self.size = 2 ** (int(log2(self.n - 1)) + 1) if self.n != 1 else 1
		self.func = func
		self.default = 0 if self.func != min else inf
		self.data = [self.default] * (2 * self.size)
		self.process(array)

	def process(self, array):
		self.data[self.size:self.size + self.n] = array
		for i in range(self.size - 1, -1, -1):
			self.data[i] = self.func(self.data[2 * i], self.data[2 * i + 1])

	def query(self, alpha, omega):
		if alpha == omega:
			return self.data[alpha + self.size]
		res = self.default
		alpha += self.size
		omega += self.size + 1
		while alpha < omega:
			if alpha & 1:
				res = self.func(res, self.data[alpha])
				alpha += 1
			if omega & 1:
				omega -= 1
				res = self.func(res, self.data[omega])
			alpha >>= 1
			omega >>= 1
		return res

	def update(self, index, value):
		index += self.size
		self.data[index] = value
		index >>= 1
		while index:
			self.data[index] = self.func(self.data[2 * index], self.data[2 * index + 1])
			index >>= 1
from bisect import bisect_left, bisect_right

class Result:

	def __init__(self, index, value):
		self.index = index
		self.value = value

class BinarySearch:

	def __init__(self):
		pass

	@staticmethod
	def greater_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_right(func, num)
			if index == len(func):
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(omega) <= num:
				return Result(None, None)
			while alpha < omega:
				if func(alpha) > num:
					return Result(alpha, func(alpha))
				if omega == alpha + 1:
					return Result(omega, func(omega))
				mid = (alpha + omega) // 2
				if func(mid) > num:
					omega = mid
				else:
					alpha = mid

	@staticmethod
	def less_than(num: int, func, size: int=1):
		if isinstance(func, list):
			index = bisect_left(func, num) - 1
			if index == -1:
				return Result(None, None)
			else:
				return Result(index, func[index])
		else:
			(alpha, omega) = (0, size - 1)
			if func(alpha) >= num:
				return Result(None, None)
			while alpha < omega:
				if func(omega) < num:
					return Result(omega, func(omega))
				if omega == alpha + 1:
					return Result(alpha, func(alpha))
				mid = (alpha + omega) // 2
				if func(mid) < num:
					alpha = mid
				else:
					omega = mid
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
bs = BinarySearch()
for _ in range(int(input()) if not True else 1):
	(n, d, m) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	ind = bs.greater_than(m, a).index
	if ind is None:
		print(sum(a))
		continue
	vals = n - ind
	ans = 0
	st = SegmentTree(a, func=lambda a, b: a + b)
	xi = None
	for i in range(1, vals + 1):
		anss = a[-1]
		left = n - 1 - (d + 1) * (i - 1)
		if left < 0:
			if d >= n and i > 1:
				ans = max(ans, anss)
				break
			xi = i
			break
		anss += st.query(n - 2 - i + 2, n - 2)
		anss += st.query(max(0, ind - left), ind - 1)
		ans = max(ans, anss)
	if 1:
		cur = -1
		used = 0
		anss = 0
		while used < n:
			anss += a[cur]
			cur -= 1
			used += d + 1
		cur = ind - 1
		while used < n:
			anss += a[cur]
			cur -= 1
			used += 1
		ans = max(ans, anss)
	anss = 0
	cn = 0
	for i in range(ind - 1, -1, -1):
		if cn == n - 1:
			break
		anss += a[i]
		cn += 1
	anss += a[-1]
	print(max(ans, anss))


import sys
input = sys.stdin.readline
(n, d, m) = map(int, input().split())
A = list(map(int, input().split()))
P = []
M = []
for a in A:
	if a > m:
		P.append(a)
	else:
		M.append(a)
P.sort(reverse=True)
M.sort(reverse=True)
if P == []:
	print(sum(M))
	sys.exit()
ANS = sum(M) + P[0]
useP = 1
useM = len(M)
SUM = ANS
while 0 <= useP <= len(P) and 0 <= useM <= len(M):
	if n - (useP + useM + 1) >= useP * d:
		useP += 1
		if useP > len(P):
			break
		SUM += P[useP - 1]
	else:
		if useM == 0:
			break
		SUM -= M[useM - 1]
		useM -= 1
	ANS = max(ANS, SUM)
print(ANS)


(n, d, m) = [int(i) for i in input().split()]
days = [int(i) for i in input().split()]
days.sort(reverse=True)
smaller = [i for i in days if i <= m]
larger = [i for i in days if i > m]
highest = 0
current = 0
prefix_sums = [0] * (1 + len(larger))
for i in range(0, len(larger)):
	prefix_sums[i + 1] = prefix_sums[i] + larger[i]
prefix_sums2 = [0] * (1 + len(smaller))
for i in range(0, len(smaller)):
	prefix_sums2[i + 1] = prefix_sums2[i] + smaller[i]
if n == len(smaller):
	print(sum(smaller))
else:
	for x in range(1, len(prefix_sums)):
		small_remaining = n - (x - 1) * (d + 1) - 1
		if small_remaining < 0:
			break
		if small_remaining >= len(prefix_sums2):
			if small_remaining - len(prefix_sums2) > d:
				continue
			else:
				highest = max(highest, prefix_sums[x] + prefix_sums2[-1])
				continue
		current = prefix_sums[x] + prefix_sums2[small_remaining]
		highest = max(current, highest)
	print(highest)


import sys
input = sys.stdin.readline
(n, d, m) = map(int, input().split())
A = list(map(int, input().split()))
from random import randint
B = []
C = []
for i in range(n):
	if A[i] > m:
		B.append(A[i])
	else:
		C.append(A[i])
B.sort(reverse=True)
C.sort(reverse=True)
ans = 0
if len(B) == 0:
	ans = sum(A)
else:
	bmin = (n - len(C) - 1) // (d + 1) + 1
	bmax = min(len(B), (n - 1) // (d + 1) + 1)
	bind = bmin
	cind = n - ((bmin - 1) * (d + 1) + 1) - 1
	ans0 = sum(B[:bmin])
	ans0 += sum(C[:cind + 1])
	ans = ans0
	for i in range(cind - len(C) + 1):
		C.append(0)
	while bind < bmax:
		ans0 += B[bind]
		bind += 1
		for i in range(d + 1):
			if len(C) > 0 and cind >= 0:
				ans0 -= C[cind]
				cind -= 1
		ans = max(ans0, ans)
print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(n, d, m) = sep()
	less = []
	greater = []
	a = lis()
	for i in range(n):
		if a[i] > m:
			greater.append(a[i])
		else:
			less.append(a[i])
	greater = sorted(greater)[::-1]
	less = sorted(less)
	if len(greater) == 0:
		print(sum(less))
		return
	if len(less) == 0:
		print(sum(greater[:ceil(len(greater) / (d + 1))]))
		return
	ans = sum(less)
	add = greater[0]
	greater = greater[1:]
	preg = [0] * (len(greater) + 1)
	prel = [0] * (len(less) + 1)
	for i in range(len(greater)):
		preg[i] = preg[i - 1] + greater[i]
	for i in range(len(less)):
		prel[i] = prel[i - 1] + less[i]
	for i in range(1, len(greater) + 1):
		left = len(greater) - i
		req = i * d
		if left >= req:
			ans = max(ans, prel[-2] + preg[i - 1])
		else:
			aur = req - left
			if aur <= len(less):
				ans = max(ans, preg[i - 1] + prel[-2] - prel[aur - 1])
			else:
				break
	print(ans + add)
testcase(1)


def to_int(s):
	return int(s)
ndm = list(map(to_int, input().split(' ')))
n = ndm[0]
d = ndm[1]
m = ndm[2]
values = list(map(to_int, input().split(' ')))
good = []
bad = []
for v in values:
	if v <= m:
		good.append(v)
	else:
		bad.append(v)
good.sort(reverse=True)
bad.sort(reverse=True)
goodSums = [0]
for i in good:
	goodSums.append(goodSums[-1] + i)
if len(bad) == 0:
	print(goodSums[-1])
	exit()
badSums = [0]
for i in bad:
	badSums.append(badSums[-1] + i)
sum = 0
minGood = n - ((len(bad) - 1) * (d + 1) + 1)
if minGood < 0:
	minGood = 0
for i in range(minGood, len(goodSums)):
	nLeft = n - i
	exceed = nLeft // (d + 1)
	if not nLeft % (d + 1) == 0:
		exceed += 1
	sum = max(sum, goodSums[i] + badSums[exceed])
print(sum)


import sys
import math as mt
input = sys.stdin.buffer.readline
I = lambda : list(map(int, input().split()))
for tc in range(1):
	(n, d, m) = I()
	l = I()
	left = [i for i in l if i <= m]
	right = [i for i in l if i > m]
	left.sort(reverse=True)
	right.sort(reverse=True)
	if not right:
		print(sum(left))
		continue
	ans = sum(left) + right[0]
	rr = 1
	ll = len(left)
	temp = ans
	while ll >= 0 and ll <= len(left) and (rr >= 0) and (rr <= len(right)):
		if n - (ll + rr + 1) >= rr * d:
			rr += 1
			if rr > len(right):
				break
			temp += right[rr - 1]
		else:
			if ll == 0:
				break
			temp -= left[ll - 1]
			ll -= 1
		ans = max(ans, temp)
	print(ans)


from collections import defaultdict as dd
import math
import sys
import heapq
import copy
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))

def solve():
	(n, d, m) = mi()
	a_s = lm()
	bigs = []
	smalls = []
	for a in a_s:
		if a > m:
			bigs.append(a)
		else:
			smalls.append(a)
	bigs.sort(reverse=True)
	smalls.sort(reverse=True)
	if len(bigs) == 0:
		print(sum(smalls))
		return
	total = bigs[0]
	small_start = 0
	for j in range((n - 1) % (d + 1)):
		if j < len(smalls):
			total += smalls[j]
			small_start += 1
	big_start = 1
	i = 0
	while i + d + 1 <= n - 1:
		if big_start >= len(bigs):
			total += sum(smalls[small_start:min(n, small_start + d + 1)])
			small_start += d + 1
		elif sum(smalls[small_start:min(n, small_start + d + 1)]) > bigs[big_start]:
			total += sum(smalls[small_start:min(n, small_start + d + 1)])
			small_start += d + 1
		else:
			total += bigs[big_start]
			big_start += 1
		i += d + 1
	print(total)
solve()


(n, d, m) = map(int, input().split())
an = list(map(int, input().split()))
safe = []
muzz = []
for i in an:
	if i <= m:
		safe.append(i)
	else:
		muzz.append(i)
muzz = list(sorted(muzz))[::-1]
safe = list(sorted(safe))
spots = len(muzz) - 1
if len(muzz) > 0:
	ans = sum(safe) + muzz[0]
	muzz.pop(0)
else:
	ans = sum(safe)
for i in muzz:
	if spots >= d + 1:
		ans += i
		spots -= d + 1
	else:
		takeaway = d + 1 - spots
		spots = 0
		if takeaway > len(safe):
			break
		else:
			pot = safe[:takeaway]
			rem = safe[takeaway:]
			if i > sum(pot):
				safe = rem
				ans += i - sum(pot)
			else:
				break
print(ans)


import sys
import bisect
t = 1
for _ in range(t):
	(n, d, m) = map(int, input().split())
	l = list(map(int, input().split()))
	g1 = []
	g2 = []
	for i in l:
		if i > m:
			g1.append(i)
		else:
			g2.append(i)
	g1.sort(reverse=True)
	g2.sort(reverse=True)
	ans = 0
	preg1 = [0] * (len(g1) + 2)
	preg2 = [0] * (n + 2)
	for i in range(len(g1)):
		preg1[i + 1] += preg1[i] + g1[i]
	for i in range(n):
		if i < len(g2):
			preg2[i + 1] += preg2[i] + g2[i]
		else:
			preg2[i + 1] = preg2[i]
	for k in range(1, len(g1) + 1):
		used = (k - 1) * d + k
		if used <= n:
			ans = max(ans, preg1[k] + preg2[n - used])
	print(max(ans, preg2[len(g2)]))


def main():
	(n, d, m) = map(int, input().split())
	a = list(map(int, input().split()))
	l1 = []
	l2 = []
	for i in a:
		if i > m:
			l1.append(i)
		else:
			l2.append(i)
	if len(l1) < 2:
		print(sum(a))
		return
	l1.sort(reverse=True)
	l2.sort(reverse=True)
	l1.append(-1)
	total = l1.pop(0)
	n -= 1
	(q, r) = (n // (d + 1), n % (d + 1))
	z1 = 0
	z2 = r
	for i in range(min(r, len(l2))):
		total += l2[i]
	for i in range(q):
		nice = sum(l2[z2:z2 + d + 1])
		if l1[z1] >= nice:
			total += l1[z1]
			z1 += 1
		else:
			z2 += d + 1
			total += nice
	print(total)
main()


(n, d, m) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
cnt = 0
lt = [x for x in arr if x <= m][::-1]
gt = [x for x in arr if x > m][::-1]
if not gt:
	print(sum(arr))
	exit(0)
for i in range(1, len(gt)):
	gt[i] += gt[i - 1]
for i in range(1, len(lt)):
	lt[i] += lt[i - 1]
k = (n + d) // (d + 1)
ans = sum(arr[-k:])
for i in range(len(lt)):
	k = (n + d - i - 1) // (d + 1)
	if k <= len(gt):
		ans = max(ans, gt[k - 1] + lt[i])
	else:
		ans = max(ans, gt[-1] + lt[k - len(gt) + i])
print(ans)


from itertools import accumulate
(n, d, m) = map(int, input().split())
(*a,) = map(int, input().split())
(l, r) = ([], [])
a.sort()
a.reverse()
for i in range(n):
	if a[i] <= m:
		l.append(a[i])
	else:
		r.append(a[i])
rs = [0] + list(accumulate(r))
ls = [0] + list(accumulate(l))
ans = 0
for i in range(len(ls)):
	j = (n - i + d) // (d + 1)
	if j > len(r):
		continue
	ans = max(ans, ls[i] + rs[j])
print(ans)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
ans = 0

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def LI():
	return [int(i) for i in input().split()]
(n, d, m) = LI()
a = LI()

def solve(n, d, m, a):
	a.sort()
	s = [i for i in a if i <= m]
	l = [i for i in a if i > m]
	S = sum(s)
	L = sum(l)
	A = sum(a)
	aa = accum(a)
	al = accum(l)
	ass = accum(s)
	nl = len(l)
	ns = len(s)
	ans = S
	ans = max(sum(a) - sum(a[:d * (len(l) - 1)]), ans)
	ans = max(sum(a) - sum(l[:nl - 1]), ans)
	for x in range(1, len(l) + 1):
		if x * d >= nl - x and ns + nl - x >= (x - 1) * d:
			t = max((x - 1) * d - (nl - x), 0)
			nouse = al[nl - x] + ass[t]
			tmp = A - nouse
			if ans < tmp:
				ans = tmp
	return ans

def naive(n, d, m, a):
	rt = -1
	ls = []
	for p in permutations(a):
		tmp = 0
		i = 0
		while i < n:
			tmp += p[i]
			if p[i] > m:
				i += d + 1
			else:
				i += 1
		if rt < tmp:
			rt = tmp
			ls = p[:]
	return (rt, ls)
print(solve(n, d, m, a))


import sys
input = sys.stdin.readline
(n, d, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
small = []
big = []
for num in a:
	if num > m:
		big.append(num)
	else:
		small.append(num)
big.sort()
big.reverse()
small.sort()
small.reverse()
ans = 0
small = [0] + small
big = [0] + big
for i in range(1, len(small)):
	small[i] = small[i - 1] + small[i]
for i in range(1, len(big)):
	big[i] = big[i - 1] + big[i]
for i in range(len(small)):
	tmp = small[i]
	ind = (n - i - 1) // (d + 1) + 1
	ind = min(ind, len(big) - 1)
	tmp += big[ind]
	ans = max(ans, tmp)
print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass

def pmat(A):
	for ele in A:
		print(ele, end='\n')
(n, d, m) = map(int, input().split())
arr = list(map(int, input().split()))
dp = [0] * (n + 1)
arr.sort()
count = 0
for i in range(n):
	dp[i + 1] = arr[i] + dp[i]
	if arr[i] <= m:
		count += 1
res = dp[count]
for i in range(1, n - count + 1):
	if (i - 1) * d + i > n:
		break
	res = max(res, dp[n] - dp[n - i] + dp[count] - dp[max(0, (i - 1) * d - (n - count - i))])
print(res)
endtime = time.time()


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0
(n, d, m) = mp()
a = lmp()
ml = []
md = []
for i in a:
	if i > m:
		ml.append(i)
	else:
		md.append(i)
md.sort(reverse=True)
ml.sort(reverse=True)
ml = [0] + ml
md = [0] + md
for i in range(1, len(ml)):
	ml[i] += ml[i - 1]
for i in range(1, len(md)):
	md[i] += md[i - 1]
xx = len(ml)
if xx > 1:
	mx = -1
	for i in range(len(md)):
		x = min((n - i - 1) // (d + 1) + 1, xx - 1)
		ans = ml[x]
		ans += md[i]
		mx = max(mx, ans)
	print(mx)
else:
	print(sum(a))


from bisect import *
import sys
(a, b, c) = map(int, input().split())
d = list(map(int, input().split()))
a -= 1
ans = -1
d.sort()
w = a // (b + 1)
yy = a % (b + 1)
t = a % 2
rr = bisect_right(d, c)
if rr == a + 1:
	print(sum(d))
	sys.exit()
p = [0] * (a + 1)
for i in range(1, a + 1):
	p[i] = p[i - 1] + d[i - 1]
if a - rr < w:
	w = a - rr
	yy = a - (b + 1) * w
while w >= 0:
	ans = max(ans, p[a] - p[a - w] + p[rr] - p[max(0, rr - yy)] + d[-1])
	w -= 1
	yy += b + 1
print(ans)


def sol(num_days, pause, m, jokes):
	nbjokes = []
	bjokes = []
	for joke in jokes:
		if joke > m:
			bjokes.append(joke)
		else:
			nbjokes.append(joke)
	bjokes.sort(reverse=True)
	nbjokes.sort(reverse=True)
	nb_prefix = [0]
	for nb in nbjokes:
		nb_prefix.append(nb_prefix[-1] + nb)
	b_prefix = [0]
	for b in bjokes:
		b_prefix.append(b_prefix[-1] + b)
	best = 0
	if len(bjokes) == 0:
		if nb_prefix:
			print(nb_prefix[min(len(nb_prefix) - 1, num_days)])
		return
	for x in range(1, len(bjokes) + 1):
		ban_val = b_prefix[x]
		no_ban_days = num_days - ((x - 1) * (pause + 1) + 1)
		if no_ban_days < 0:
			break
		no_ban_val = nb_prefix[min(no_ban_days, len(nb_prefix) - 1)]
		best = max(best, ban_val + no_ban_val)
	print(best)

def main():
	(num_days, pause, m) = map(int, input().split())
	jokes = list(map(int, input().split()))
	sol(num_days, pause, m, jokes)
main()


(n, d, m) = [int(c) for c in input().split()]
arr = [int(c) for c in input().split()]
a = [i for i in arr if i > m]
b = [i for i in arr if i <= m]
k = len(a)
l = len(b)
a.sort(reverse=True)
b.sort(reverse=True)
a.insert(0, 0)
b.insert(0, 0)
for i in range(1, len(a)):
	a[i] += a[i - 1]
for i in range(1, len(b)):
	b[i] += b[i - 1]
b = b + [b[-1]] * n
minmuz = (k + d) // (d + 1)
maxmuz = k
fans = float('-inf')
for i in range(minmuz, maxmuz + 1):
	l = (d + 1) * (i - 1) + 1
	if l > n:
		continue
	left = n - l
	ans = a[i]
	ans += b[left]
	fans = max(fans, ans)
print(fans)


import sys
input = sys.stdin.readline
(n, d, m) = map(int, input().split())
a = list(map(int, input().split()))
b = []
c = []
for e in a:
	if e > m:
		b.append(e)
	else:
		c.append(e)
b.sort(reverse=True)
c.sort(reverse=True)
bb = []
cc = []
tmp = 0
for e in b:
	tmp += e
	bb.append(tmp)
tmp = 0
for e in c:
	tmp += e
	cc.append(tmp)
big = len(b)
if len(b) == 0:
	print(sum(a))
elif len(c) == 0:
	q = 0
	while n > 0:
		q += 1
		n -= d + 1
	print(bb[q - 1])
else:
	res = 0
	for i in range(big):
		if big - i - 1 <= i * d <= n - i - 1:
			de = i * d
		elif i * d <= big - i - 1 <= (i + 1) * d:
			de = big - i - 1
		else:
			continue
		plus = de + i + 1 - big
		if 0 <= n - big - 1 - plus < len(cc):
			tmp = bb[i] + cc[n - big - 1 - plus]
		else:
			tmp = bb[i]
		res = max(res, tmp)
	print(res)


import sys
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math

def solve():
	(N, D, M) = getInts()
	A = getInts()
	A.sort(reverse=True)
	if N == 1 or A[0] <= M:
		return sum(A)
	(safe, dangerous) = ([], [])
	for a in A:
		if a <= M:
			safe.append(a)
		else:
			dangerous.append(a)
	safe_pref = [0]
	for s in safe:
		safe_pref.append(safe_pref[-1] + s)
	dang_pref = [0]
	for d in dangerous:
		dang_pref.append(dang_pref[-1] + d)
	best = 0
	for x in range(1, min((N - 1) // (D + 1) + 2, len(dang_pref))):
		safe_num = min(N - x - (x - 1) * D, len(safe_pref) - 1)
		best = max(best, dang_pref[x] + safe_pref[safe_num])
	return best
print(solve())


from sys import stdin
input = stdin.buffer.readline
(n, d, m) = map(int, input().split())
(*a,) = map(int, input().split())
a.sort()
c = sum((i <= m for i in a))
pref = [a[c - 1]]
ans = 0
tmp = 0
for i in range(c - 2, -1, -1):
	pref.append(pref[-1] + a[i])
for k in range(1, n + 1):
	tmp += a[n - k]
	b = (k - 1) * d
	if n - k - b < 0 or n - k < c:
		break
	s = tmp
	if c and n - k - b:
		s += pref[min(c - 1, n - k - b - 1)]
	ans = max(ans, s)
print(max(ans, pref[-1]))


import sys
(n, d, m) = list(map(int, sys.stdin.readline().strip().split()))
a = list(map(int, sys.stdin.readline().strip().split()))
a.sort()
s1 = 0
s2 = 0
j = 0
i = 0
while a[i] <= m:
	s1 = s1 + a[i]
	i = i + 1
	if i == n:
		break
b = a[0:i]
b.reverse()
a = b + a[i:]
while j * (d + 1) + i < n:
	s2 = s2 + a[n - 1 - j]
	j = j + 1
ans = s1 + s2
while j < n / (d + 1):
	s2 = s2 + a[n - 1 - j]
	j = j + 1
	while j * (d + 1) + i >= n + d + 1:
		s1 = s1 - a[i - 1]
		i = i - 1
	ans = max(ans, s1 + s2)
print(ans)


import sys
input = sys.stdin.readline

def main():
	(n, d, m) = map(int, input().split())
	a = list(map(int, input().split()))
	(small, large) = ([x for x in a if x <= m], [x for x in a if x > m])
	small.sort(reverse=True)
	large.sort(reverse=True)
	c = len(small)
	if c == n:
		print(sum(a))
		exit()
	l = 1
	r = min((n - 1) // (d + 1) + 1, len(large))
	ans = sum(small)
	(now_small, now_large) = (0, 0)
	for i in range(l, r + 1):
		if i == l:
			now_small = sum(small[:n - (1 + (l - 1) * (d + 1))])
			now_large = sum(large[:l])
			ans = max(now_large + now_small, ans)
			continue
		now_small -= sum(small[n - (1 + (i - 1) * (d + 1)):n - (1 + (i - 1 - 1) * (d + 1))])
		now_large += large[i - 1]
		ans = max(now_small + now_large, ans)
	print(ans)
main()


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
from fractions import Fraction
INF = float('inf')
mod = int(1000000000.0) + 7
(n, d, m) = mdata()
a = mdata()
(l1, l2, ans) = ([], [], 0)
for i in a:
	if i > m:
		l2.append(i)
	else:
		l1.append(i)
l2.sort()
l1.sort()
if l2:
	ans += l2.pop()
(cnt, k) = (1, 0)
while l2:
	if cnt * d - len(l2) + 1 <= 0:
		ans += l2.pop()
	elif l2[-1] > sum(l1[k:cnt * d - len(l2) + 1]) and len(l1) >= cnt * d - len(l2) + 1:
		k = cnt * d - len(l2) + 1
		ans += l2.pop()
	else:
		break
	cnt += 1
if l1:
	ans += sum(l1[k:])
out(ans)


(n, d, m) = map(int, input().split())
A = list(map(int, input().split()))
L = []
U = []
for a in A:
	if a <= m:
		L.append(a)
	else:
		U.append(a)
L.sort(reverse=True)
U.sort(reverse=True)
if len(U) <= 1:
	print(sum(A))
	exit()
from itertools import accumulate
CL = [0] + L
CL = list(accumulate(CL))
CU = [0] + U
CU = list(accumulate(CU))
ans = 0
for x in range(1, len(U) + 1):
	m = (x - 1) * (d + 1) + 1
	if m > n:
		break
	l = n - m
	temp = CU[x] + CL[min(l, len(CL) - 1)]
	ans = max(temp, ans)
print(ans)