# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
#二部探索

import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
inda = np.argsort(-a)
lena = inda.size
judge = [True for i in range(lena+2)]
take = n//2
ans = 0
ind = 0
count = 0
while True:
    if judge[inda[ind]+2] and judge[inda[ind]]:
        ans += a[inda[ind]]
        count+=1
        judge[inda[ind] + 1] = False
        ind += 1
        if count==take:
            break
    else:
        ind+=1
print(ans)