CodeEff/ECCO huggingface dataset:
# Original solution
N,K = list(map(int,input().split()))
points1 = []
points2 = []
for i in range(N):
	x,y = tuple((list(map(int,input().split()))))
	points1.append((x,y))
	points2.append(y)
points1.sort()
points2.sort()

xDict = {}
index = 0
for x,y in points1:
	if index in xDict:
		if xDict[index] != x:
			index += 1
			xDict[index] = x
	else:
		xDict[index] = x

yDict = {}
index = 0
for y in points2:
	if index in yDict:
		if yDict[index] != y:
			index += 1 
			yDict[index] = y
	else:
		yDict[index] = y

nPoints = [[0 for j in range(len(yDict))] for i in range(len(xDict))]

for kx,vx in list(xDict.items()):
	for ky,vy in list(yDict.items()):
		exists = 1 if (vx,vy) in points1 else 0
		if kx == 0 and ky == 0:
			nPoints[kx][ky] += exists
		elif kx == 0 and ky > 0:
			nPoints[kx][ky] += nPoints[kx][ky-1] + exists
		elif kx > 0 and ky == 0:
			nPoints[kx][ky] += nPoints[kx-1][ky] + exists
		else:
			nPoints[kx][ky] += nPoints[kx-1][ky] + nPoints[kx][ky-1] - nPoints[kx-1][ky-1] + exists

ans = -1
for x1 in range(len(xDict)):
	for x2 in range(x1+1):
		for y1 in range(len(yDict)):
			for y2 in range(y1+1):
				point = nPoints[x1][y1]
				if x2 > 0:
					point -= nPoints[x2-1][y1]
				if y2 > 0:
					point -= nPoints[x1][y2-1]
				if x2 > 0 and y2 > 0:
					point += nPoints[x2-1][y2-1]
				if point >= K:
					area = (xDict[x1]-xDict[x2]) * (yDict[y1]-yDict[y2])
					if ans < 0:
						ans = area
					else:
						ans = min(ans, area)
print(ans)

# Optimized solution
N,K = list(map(int,input().split()))
points1 = []
points2 = []
for i in range(N):
	x,y = tuple((list(map(int,input().split()))))
	points1.append((x,y))
	points2.append(y)
points1.sort()
points2.sort()

xDict = {}
index = 0
for x,y in points1:
	if index in xDict:
		if xDict[index] != x:
			index += 1
			xDict[index] = x
	else:
		xDict[index] = x

yDict = {}
index = 0
for y in points2:
	if index in yDict:
		if yDict[index] != y:
			index += 1 
			yDict[index] = y
	else:
		yDict[index] = y

nPoints = [[0 for j in range(len(yDict))] for i in range(len(xDict))]

for kx,vx in list(xDict.items()):
	for ky,vy in list(yDict.items()):
		exists = 1 if (vx,vy) in points1 else 0
		if kx == 0 and ky == 0:
			nPoints[kx][ky] += exists
		elif kx == 0 and ky > 0:
			nPoints[kx][ky] += nPoints[kx][ky-1] + exists
		elif kx > 0 and ky == 0:
			nPoints[kx][ky] += nPoints[kx-1][ky] + exists
		else:
			nPoints[kx][ky] += nPoints[kx-1][ky] + nPoints[kx][ky-1] - nPoints[kx-1][ky-1] + exists

ans = -1
for x1 in range(len(xDict)):
	for x2 in range(x1+1,-1,-1):
		for y1 in range(len(yDict)):
			for y2 in range(y1+1,-1,-1):
				point = nPoints[x1][y1]
				if x2 > 0:
					point -= nPoints[x2-1][y1]
				if y2 > 0:
					point -= nPoints[x1][y2-1]
				if x2 > 0 and y2 > 0:
					point += nPoints[x2-1][y2-1]
				if point >= K:
					area = (xDict[x1]-xDict[x2]) * (yDict[y1]-yDict[y2])
					if ans < 0:
						ans = area
					else:
						ans = min(ans, area)
					break
print(ans)
# Original solution
n,k=list(map(int,input().split()))
xy=[list(map(int,input().split())) for _ in range(n)]
x=[t[0] for t in xy]
y=[t[1] for t in xy]

res=[]
for i in range(n):
    for j in range(n):
        for a in range(n):
            for b in range(n):
                l=min(x[i],x[j])
                r=max(x[i],x[j])
                d=min(y[a],y[b])
                u=max(y[a],y[b])
                tk=0
                for t in xy:
                    if l<=t[0]<=r and d<=t[1]<=u:
                        tk+=1
                if tk>=k:
                    res.append((r-l)*(u-d))
print((min(res)))

# Optimized solution
n,k=list(map(int,input().split()))
xy=[list(map(int,input().split())) for _ in range(n)]
x=[t[0] for t in xy]
y=[t[1] for t in xy]

res=[]
for i in range(n-1):
    for j in range(i+1,n):
        for a in range(n-1):
            for b in range(a+1,n):
                l=min(x[i],x[j])
                r=max(x[i],x[j])
                d=min(y[a],y[b])
                u=max(y[a],y[b])
                tk=0
                for t in xy:
                    if l<=t[0]<=r and d<=t[1]<=u:
                        tk+=1
                if tk>=k:
                    res.append((r-l)*(u-d))
print((min(res)))
# Original solution
N,K = list(map(int,input().split()))
XY = [list(map(int,input().split())) for i in range(N)]

ans = float("inf")
import itertools
I = [i for i in range(N)]

for B in itertools.combinations(I,4):
    i,j,k,kk = B
    x1,y1 = XY[i]
    x2,y2 = XY[j]
    x3,y3 = XY[k]
    x4,y4 = XY[kk]
    u = max(y1,y2,y3,y4)
    d = min(y1,y2,y3,y4)
    r = max(x1,x2,x3,x4)
    l = min(x1,x2,x3,x4)
    num = 0
    for m in range(N):
        x,y = XY[m]
        if l<=x<=r and d<=y<=u:
            num += 1
    if num >= K:
        tmp = (u-d)*(r-l)
        if tmp < ans:
            ans = tmp
for B in itertools.combinations(I,3):
    i,j,k = B
    x1,y1 = XY[i]
    x2,y2 = XY[j]
    x3,y3 = XY[k]
    u = max(y1,y2,y3)
    d = min(y1,y2,y3)
    r = max(x1,x2,x3)
    l = min(x1,x2,x3)
    num = 0
    for m in range(N):
        x,y = XY[m]
        if l<=x<=r and d<=y<=u:
            num += 1
    if num >= K:
        tmp = (u-d)*(r-l)
        if tmp < ans:
            ans = tmp
for B in itertools.combinations(I,2):
    i,j = B
    x1,y1 = XY[i]
    x2,y2 = XY[j]
    u = max(y1,y2)
    d = min(y1,y2)
    r = max(x1,x2)
    l = min(x1,x2)
    num = 0
    for m in range(N):
        x,y = XY[m]
        if l<=x<=r and d<=y<=u:
            num += 1
    if num >= K:
        tmp = (u-d)*(r-l)
        if tmp < ans:
            ans = tmp
print(ans)

# Optimized solution
N,K = list(map(int,input().split()))
XY = [list(map(int,input().split())) for i in range(N)]

ans = float("inf")
for i in range(N):
    x1,y1 = XY[i]
    for j in range(i+1,N):
        x2,y2 = XY[j]
        u2 = max(y1,y2)
        d2 = min(y1,y2)
        r2 = max(x1,x2)
        l2 = min(x1,x2)
        for k in range(j+1,N):
            x3,y3 = XY[k]
            u3 = max(u2,y3)
            d3 = min(d2,y3)
            r3 = max(r2,x3)
            l3 = min(l2,x3)
            for kk in range(k+1,N):
                x4,y4 = XY[kk]
                u4 = max(u3,y4)
                d4 = min(d3,y4)
                r4 = max(r3,x4)
                l4 = min(l3,x4)
                num = 0
                for m in range(N):
                    x,y = XY[m]
                    if l4<=x<=r4 and d4<=y<=u4:
                        num += 1
                if num >= K:
                    tmp = (u4-d4)*(r4-l4)
                    if tmp < ans:
                        ans = tmp
            num = 0
            for m in range(N):
                x,y = XY[m]
                if l3<=x<=r3 and d3<=y<=u3:
                    num += 1
            if num >= K:
                tmp = (u3-d3)*(r3-l3)
                if tmp < ans:
                    ans = tmp
        num = 0
        for m in range(N):
            x,y = XY[m]
            if l2<=x<=r2 and d2<=y<=u2:
                num += 1
        if num >= K:
            tmp = (u2-d2)*(r2-l2)
            if tmp < ans:
                ans = tmp
print(ans)
# Original solution
inf = float('inf')

N,K = list(map(int,input().split()))
ans = inf
X = []
Y = []
XY = []
for _ in range(N):
    x,y = list(map(int,input().split()))
    X.append(x)
    Y.append(y)
    XY.append((x,y))

X = sorted(X)
Y = sorted(Y)

for i in range(N):
    for j in range(i+1,N):
        for k in range(N):
            for l in range(k+1,N):
                cnt = 0
                for x, y in XY:
                    if X[i] <= x <= X[j] and Y[k] <= y <= Y[l]:
                        cnt += 1
                if cnt < K: continue
                S = (Y[l]-Y[k])*(X[j]-X[i])
                if S < ans:
                    ans = S

print(ans)

# Optimized solution
inf = float('inf')

N,K = list(map(int,input().split()))
ans = inf
X = []
Y = []
XY = []
for _ in range(N):
    x,y = list(map(int,input().split()))
    X.append(x)
    Y.append(y)
    XY.append((x,y))

X = sorted(X)
Y = sorted(Y)

for i, left in enumerate(X):
    for right in X[i+1:]:
        for j, bottom in enumerate(Y):
            for top in Y[j+1:]:
                cnt = 0
                for x, y in XY:
                    if left <= x <= right and bottom <= y <= top:
                        cnt += 1
                if cnt < K: continue
                S = (right-left)*(top-bottom)
                if S < ans:
                    ans = S

print(ans)
# Original solution
n,k=list(map(int,input().split()))
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort(key=lambda z:z[0])
y.sort(key=lambda z:z[0])
ans=(10**18)*5
ra=list(range(n))
for i1 in ra:
    for l1 in range(n-i1,0,-1):
        for i2 in ra:
            for l2 in range(n-i2,0,-1):
                if l1*l2<k:
                    break
                z=[0]*n
                for i in range(i1,i1+l1):
                    l=x[i][1]
                    z[l]=1
                for i in range(i2,i2+l2):
                    l=y[i][1]
                    z[l]=1
                if sum(z)>=k:
                    x_sub1,y_sub1=10**9+1,10**9+1
                    x_sub2,y_sub2=-10**9-1,-10**9-1
                    for i in range(n):
                        if z[i]==1:
                            x_sub1=min(xy[i][0],x_sub1)
                            x_sub2=max(xy[i][0],x_sub2)
                            y_sub1=min(xy[i][1],y_sub1)
                            y_sub2=max(xy[i][1],y_sub2)
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)


# Optimized solution
n,k=list(map(int,input().split()))
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort()
y.sort()
ans=(10**18)*5
for i1 in range(n):
    for l1 in range(n-i1,1,-1):
        for i2 in range(n):
            for l2 in range(n-i2,1,-1):
                x_sub1=x[i1][0]
                x_sub2=x[i1+l1-1][0]
                y_sub1=y[i2][0]
                y_sub2=y[i2+l2-1][0]
                z=[0]*n
                for i in range(n):
                    if x_sub1<=xy[i][0]<=x_sub2 and y_sub1<=xy[i][1]<=y_sub2:
                        z[i]=1
                if sum(z)>=k:
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
ans = 0

for i in range(N):
    ans += a[-2]
    a = a[1:-2]
print(ans)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))

a.sort(reverse=True)
ans = 0
count = 0
for i in range(1, N*3+1, 2):
    if count == N:
        break
    else:
        ans += a[i]
        count += 1

print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int, input().split()))
a.sort(reverse=True)
print((sum(a[1:2*n:2])))

# Optimized solution
n=int(eval(input()))
a=sorted(list(map(int, input().split())), reverse=True)
print((sum(a[1:2*n:2])))
# Original solution
N = int(eval(input()))
a = [int(i) for i in input().split()]

_sum = 0

for i in range(N):
    a.remove(max(a))
    _sum += max(a)
    a.remove(max(a))

print(_sum)


# Optimized solution
N = int(eval(input()))
a = [int(i) for i in input().split()]

a.sort(reverse=True)
print((sum(a[1:2*N][::2])))
# Original solution
# AGC012A - AtCoder Group Contest
def main():
    n = int(eval(input()))
    A = sorted(map(int, input().rstrip().split()))[n:]
    print((sum(A[::2])))


if __name__ == "__main__":
    main()

# Optimized solution
# AGC012A - AtCoder Group Contest
def main():
    n = int(eval(input()))
    A = sorted(map(int, input().rstrip().split()))
    print((sum(A[n::2])))


if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
while len(A) > 0:
  ans += A[1]
  A = A[2:-1]
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
for i in range(1, 2*N, 2):
  ans += A[i]
print(ans)
# Original solution
N=int(eval(input()))
a = sorted(list(map(int,input().split())),reverse=True)
ans=0
for i in range(2*N):
  tmp=a.pop(0)
  if i%2==1:
    ans+=tmp
print(ans)

# Optimized solution
N=int(eval(input()))
a = sorted(list(map(int,input().split())),reverse=True)
ans=0
for i in range(N):
  ans+=a[2*i+1]
print(ans)
# Original solution
N = int(eval(input()))
A = list(sorted(list(map(int, input().split()))))
# N = 2
# A = list(sorted([5,2,8,5,1,5]))
group = []
ret = 0
for n in range(N):
    group.append([A.pop(0), A.pop(), A.pop()])
for g in group:
    ret += list(sorted(g))[1]
print(ret)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
ret = 0
for n in range(N, N*3, 2):
    ret += A[n]
print(ret)
# Original solution
def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    A.sort()
    tot = 0
    while A:
        A.pop()
        tot += A.pop()
        A.pop(0)
    return tot

if __name__ == '__main__':
    print((main()))

# Optimized solution
def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    A.sort()
    tot = 0
    for i in range(N):
        tot += A[3*N-2-2*i]
    return tot
if __name__ == '__main__':
    print((main()))
# Original solution
n = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse = True)

sum = 0
for i in range(n):
    a.pop(0)
    sum += a.pop(0)
print(sum)


# Optimized solution
n = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse = True)
print((sum(a[1::2][:n])))
# Original solution
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest-
#  Atcoder_Grand_Contest-
#  TODO https://atcoder.jp/contests/abc/tasks/abc_
import time
from contextlib import contextmanager
# from time import sleep
@contextmanager
def timer(title):
	t0 = time.time()
	yield
	print(("{} - done in {:.0f}s".format(title,time.time()-t0) ))

def  maxLevel(memberNumber,orgMemberLevelList):
	maxLevelSortedList = sorted(orgMemberLevelList,reverse=True)
	maxLevelScore = 0
	checkMemberCountRange = list(range(0,memberNumber,+1))
	for i in checkMemberCountRange:
		maxLevelScore = maxLevelScore+maxLevelSortedList[2*i+1]
	answer = maxLevelScore
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	levelNoSortList = list(map(int,input().strip().split(' ')))
	solution=maxLevel(N,levelNoSortList)
	print(("{}".format(solution)))

# Optimized solution
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest-
#  Atcoder_Grand_Contest012-A
#  https://atcoder.jp/contests/agc012/tasks/agc012_a

def  maxLevel(memberNumber,orgMemberLevelList):
	maxLevelSortedList = sorted(orgMemberLevelList,reverse=True)
	maxLevelScore = 0
	checkMemberCountRange = list(range(0,memberNumber,+1))
	for i in checkMemberCountRange:
		maxLevelScore = maxLevelScore+maxLevelSortedList[2*i+1]
	answer = maxLevelScore
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	levelNoSortList = list(map(int,input().strip().split(' ')))
	solution=maxLevel(N,levelNoSortList)
	print(("{}".format(solution)))
# Original solution
N = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse=True)
ans = 0
for a in A[1:2*N:2]:
    ans += a
print(ans)


# Optimized solution
import sys
input = sys.stdin.readline

def main():
    N = int(eval(input()))
    A = sorted(list(map(int, input().split())), reverse=True)
    print((sum(A[1:2*N:2])))


if __name__ == '__main__':
    main()
# Original solution
n,a=int(eval(input())),sorted(list(map(int,input().split())))[::-1];print((sum([a[i]*(i%2==1)for i in range(2*n)])))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort(reverse=1)
ans=0
for i in range(1,2*n+1,2):ans+=a[i]
print(ans)
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
A = a[1:len(a):2]
ans = 0
for i in range(N):
    ans += A[i]
print(ans)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
print((sum(a[1:2*N:2])))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort()

ans = 0
for i in range(N, 3 * N, 2):
    ans += a[i]

print (ans)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort()

# ans = 0
# for i in range(N, 3 * N, 2):
#     ans += a[i]

# print (ans)

print((sum(a[N::2])))
# Original solution
n = int(eval(input()))
a = [int(x) for x in input().split()]
a.sort()
ans = sum(a[n::2])
print(ans)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
#print(a)
# @0~N-1, !N,N+1,!N+2,N+3,!N+4, ... ,!N+N=2N
a = a[N::2]
print((sum(a)))
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
a = sorted(a,reverse=True)
ans = 0
for i in range(0,2*n):
    if i%2==1:
        ans += a[i]
print(ans)

# Optimized solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
a = sorted(a)[::-1]
ans = 0
for i in range(2*n):
    if (i+1)%2==0:
        ans += a[i]
print(ans)
# Original solution
N = int(eval(input()))
a = [int(x) for x in input().split()]

a.sort()
a.reverse()

A = a[1:2*N:2]
B = a[N:2*N]

print((max(sum(A),sum(B))))

# Optimized solution
N = int(eval(input()))
a = [int(x) for x in input().split()]

a.sort()
a.reverse()

print((sum(a[1:2*N:2])))
# Original solution
N = int(eval(input()))
member = sorted(map(int, input().split()))
ans = 0
while member:
    member.pop()
    ans += member.pop()
    member.pop(0)
print(ans)


# Optimized solution
N = int(eval(input()))
member = sorted(map(int, input().split()))
ans = sum(member[N::2])
print(ans)
# Original solution
n=int(eval(input()))

a_list=[int(i) for i in input().split()]
a_list.sort(reverse=True)
#print(a_list)
b_list=a_list[1:2*n:2]
#print(b_list)
print((sum(b_list)))

# Optimized solution
n=int(eval(input()))
a_list=[int(i) for i in input().split()]
a_list.sort(reverse=True)
second_list=a_list[1:2*n:2]
print((sum(second_list)))
# Original solution
n = int(eval(input()))
a = sorted(map(int, input().split()))
ans = 0
l = 0
r = 3*n-1
while l < r:
    ans += a[r-1]
    l += 1
    r -= 2
    # print(l, r)

print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
a.sort(reverse=True)
for i in range(n):
    ans += a[2*i+1]

print(ans)
# Original solution
def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    A.sort()
    print((sum(A[3*N-2:N-1:-2])))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    A.sort()
    print((sum(A[-2:-2*N-1:-2])))


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
a = sorted(list(map(int, input().split())))

s = 0
while a:
    x = [a[0]] + a[-2:]
    s += x[1]
    a = a[1:-2]
print(s)

# Optimized solution
N = int(eval(input()))
a = sorted(list(map(int, input().split())))

print((sum(a[-2 * (i+1)] for i in range(N))))
# Original solution
N = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse=True)
idx = 0
for i in range(N - 1):
    a.insert(2+idx, a.pop())
    idx += 3
print((sum(a[1::3])))

# Optimized solution
N = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse=True)
print((sum(a[1:len(a)-N:2])))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(N, len(a), 2):
    ans += a[i]
print(ans)

# Optimized solution
N = int(eval(input()))
print((sum(sorted(map(int, input().split()))[N:3*N:2])))
# Original solution
N=int(eval(input()))
t = list(map(int,input().split()))

newLi = sorted(t, reverse=True)
li = []
ans = 0

for i in range(N):
  k = [newLi.pop(0), newLi.pop(0), newLi.pop(-1)]
  ans += k[1]

print(ans)

# Optimized solution
N=int(eval(input()))
t = list(map(int,input().split()))

newLi = sorted(t, reverse=True)
ans = 0

for i in range(N):
  ans += newLi[i * 2 + 1]

print(ans)
# Original solution
import sys

n = int(sys.stdin.readline().rstrip())
a = list(map(int, sys.stdin.readline().rstrip().split()))
a.sort()
# print(a)
ans = 0
for i in range(n):
    a = a[1:]
    a = a[:-1]
    ans += a[-1]
    a = a[:-1]
print(ans)

# Optimized solution
import sys

n = int(sys.stdin.readline().rstrip())
a = list(map(int, sys.stdin.readline().rstrip().split()))
a.sort()

# print(a)
ans = 0
a = a[n:]
a.reverse()
print((sum(a[1::2])))
# Original solution
#
# agc012 a
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
5 2 8 5 1 5"""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000"""
        output = """10000000000"""
        self.assertIO(input, output)


def resolve():
    N = int(eval(input()))
    a = list(map(int, input().split()))
    a.sort()
    ans = 0
    for i in range(N):
        a.pop()
        a.pop(0)
        ans += a.pop()
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


# Optimized solution
#
# agc012 a
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
5 2 8 5 1 5"""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000"""
        output = """10000000000"""
        self.assertIO(input, output)


def resolve():
    N = int(eval(input()))
    a = list(map(int, input().split()))
    a.sort()
    ans = 0
    for i in range(N):
        a.pop()
        ans += a.pop()
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()
# Original solution
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(eval(input()))
    A = sorted(list(map(int, input().split())))

    res = 0
    for i in range(n):
        A.pop(0)
        A.pop(-1)
        res += A[-1]
        A.pop(-1)

    print(res)


if __name__ == '__main__':
    resolve()


# Optimized solution
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(eval(input()))
    A = sorted(list(map(int, input().split())))
    res = 0
    for i in range(n):
        res += A[-(i + 1) * 2]

    print(res)


if __name__ == '__main__':
    resolve()
# Original solution
n = int(eval(input()))
data = list(map(int,input().split()))
data = sorted(data, reverse=True)
sum = 0
while data != []:
    del data[0]
    del data[-1]
    sum += data[0]
    del data[0]
print(sum)

# Optimized solution
n = int(eval(input()))
data = list(map(int,input().split()))
data = sorted(data, reverse=True)
sum = 0
for i in range(n):
    sum += data[1+2*i]
print(sum)