Harryxun/stf_run huggingface dataset:
import sys
import math
import collections
import bisect
import itertools
import numba
from numba import njit, b1, i4, i8, f8

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

@njit((i8, i8, i8, i8[:]), cache=True)
def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[0] * 4 for _ in range(c + 1)]

    for i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

    print(max(dp[c - 1]))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[0] * 4 for _ in range(c + 1)]

    for i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

    print(max(dp[c - 1]))


if __name__ == '__main__':
    main()
V, E, root = map(int, input().split())
visited = [False] * V
nodes = [[] for i in range(V)]
cost = [[] for i in range(V)]
for i in range(E):
    s, t, d = map(int, input().split())
    nodes[s].append(t)
    cost[s].append(d)

dist = [float('inf')] * V
dist[root] = 0

negative_cycle = False

for k in range(V):
    for i in range(V):
        for j in range(nodes[i]):
            if dist[nodes[i][j]] > dist[i] + cost[i][j]:
                dist[nodes[i][j]] = dist[i] + cost[i][j]
                if k==n-1:
                    dist[nodes[i][j]] = -float('inf')
                    negative_cycle = True
if negative_cycle:
    print('NEGATIVE CYCLE')
else:
    for i in range(V):
        if dist[i] == float('inf'):
            print('INF')
        else:
            print(dist[i])

### FIXED CODE ###

V, E, root = map(int, input().split())
visited = [False] * V
nodes = [[] for i in range(V)]
cost = [[] for i in range(V)]
for i in range(E):
    s, t, d = map(int, input().split())
    nodes[s].append(t)
    cost[s].append(d)

dist = [float('inf')] * V
dist[root] = 0

negative_cycle = False

for k in range(V):
    for i in range(V):
        for j in range(len(nodes[i])):
            if dist[nodes[i][j]] > dist[i] + cost[i][j]:
                dist[nodes[i][j]] = dist[i] + cost[i][j]
                if k == V - 1:
                    dist[nodes[i][j]] = -float('inf')
                    negative_cycle = True
if negative_cycle:
    print('NEGATIVE CYCLE')
else:
    for i in range(V):
        if dist[i] == float('inf'):
            print('INF')
        else:
            print(dist[i])
# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
rev_index = []
for i in range(N-1):
    if p[i] > p[i+1]:
        if len(rev_index) > 0:
            rev_index.append(i+1)
        else:
            rev_index.append(i)
if len(rev_index) > 0:
    p[rev_index[0]], p[rev_index[1]] = p[rev_index[1]], p[rev_index[0]]
if p == list(range(1,N+1)):
    print("YES")
else:
    print("NO")

### FIXED CODE ###

# stdin
INPUT_SENTENCES = 2
ss = [input() for i in range(INPUT_SENTENCES)]
N = int(ss[0])
p = list(map(lambda x: int(x), ss[1].split()))
rev_index = []
for i in range(N-1):
    if p[i] > p[i+1]:
        if len(rev_index) > 0:
            rev_index.append(i+1)
        else:
            rev_index.append(i)
if len(rev_index) == 2:
    p[rev_index[0]], p[rev_index[1]] = p[rev_index[1]], p[rev_index[0]]
if p == list(range(1,N+1)):
    print("YES")
else:
    print("NO")
contest=input()
if contest == 'ABC':
    print('ARC')
elif contest == 'ARC':
    print('ABC)
    

### FIXED CODE ###

contest=input()
if contest == 'ABC':
    print('ARC')
elif contest == 'ARC':
    print('ABC')
a,b,c=int(input())
if a+b+c<=21:
  print("win")
else:
  print("bust")

### FIXED CODE ###

a,b,c=map(int,input().split())
if a+b+c<=21:
  print("win")
else:
  print("bust")
from collections import deque
import itertools
d,g = list(map(int,input().split()))
pc = [list(map(int,input().split())) for _ in range(d)]
g /= 100

pat = list(itertools.permutations(range(1,d+1)))
ans = sum([[x,y] for x,y in zip(pc[0], pc[1])][0])

def dfs(k, point, cnt, pat):
  global ans
  i = pat[k]
  for j in range(pc[i-1][0]):
    point += i
    cnt += 1
    if j == pc[i-1][0]-1:
      point += pc[i-1][1]/100
    #print(i,j,point,cnt)
    if point >= g:
      ans = min(ans, cnt)
      point = 0
      cnt = 0
      break
  
  if k < d-1:
    dfs(k+1, point, cnt, pat)
    
for p in pat:
  #print(p)
  dfs(0,0,0,list(p))

print(ans)

### FIXED CODE ###

from collections import deque
import itertools, math
d,g = list(map(int,input().split()))
pc = [list(map(int,input().split())) for _ in range(d)]
g /= 100

#ans = sum([pc[x][0] for x in range(d)])
ans = float('inf')
for bit in range(1<<d):
  cnt = 0
  point = 0
  pat = set(range(1,d+1))
  
  for i in range(d):
    if bit & (1<<i):
      point += pc[i][0]*(i+1) + pc[i][1]//100
      cnt += pc[i][0]
      pat.discard(i+1)
  
  if point < g:
      next = max(pat)
      n = min(pc[next-1][0], math.ceil((g - point)/(next)))
      cnt += n
      point += n*(next)
    
  if point >= g:
      #print(ans,cnt)
      ans = min(ans,cnt)


print(ans)
numbers = list(map(int, input().split()))
k = int(input())
sum = 0
for i in range(3):
  if i == numbers.index(max(numbers)):
    sum += max(numbers) * pow(2, k)
  else:
    sum += numbers[i]
print(sum)

### FIXED CODE ###

a, b = map(int,input().split())
if a <= b:
  print(a)
elif a > b:
  print(a-1)
import sys

sys.setrecursionlimit(10**5)


H,W,D=map(int,input().split())

dic={}
A=[]
for h in range(H):
    A.append(list(map(int,input().split())))
    for w in range(W):
        dic[A[h][w]]=[h,w]

Q=int(input())

c=[-1]*(H*W+1)
def rec(n):
    if c[n]!=-1:
        return [c[n]]
    y,x=dic[n]
    ny,nx=dic[n+D]
    ret=abs(y-ny)+abs(x-nx)
    c[n]=ret
    return ret

for i in range(Q):
    L,R=map(int,input().split())
    N=(R-L)//D
    ans=0
    for j in range(N):
        ans+=rec(L+D*j)
    print(ans)

### FIXED CODE ###

H,W,D=map(int,input().split())
A=[]

for h in range(H):
    A.append(list(map(int,input().split())))

pos= {}
for h in range(H):
    for w in range(W):
        pos[A[h][w]]=[h,w]

S=[0]*(H*W)
for d in range(D):
    tmp=0
    now=d+1
    while now+D<=H*W:
        nowh,noww=pos[now]
        newh,neww=pos[now+D]
        tmp+=abs(nowh-newh)+abs(noww-neww)
        S[now+D-1]=tmp
        now+=D

Q=int(input())
for i in range(Q):
    L,R=map(int,input().split())
    ans=S[R-1]-S[L-1]
    print(ans)
s,t = map(inut())
c=0

for i in range(len(s)):
  if s[i]!=t[i]:
    c +=1

print(c)

### FIXED CODE ###

s = input()
t =input()
c=0

for i in range(len(s)):
  if s[i]!=t[i]:
    c +=1

print(c)
n,m = map(int, input().split())
a = []
b = []
for i in range(n):
    ai = input()
    a.append(ai)
for i in range(m):
    bi = input()
    b.append(bi)
flag = True    
for i in range(n-m+1):
    flag = True
    for k in range(n-m+1):
        for j in range(i,i+m+1):
        
            if a[j][k:k+m]!=b[j-i]:
                flag = False
                break
        if flag:
            break
    if flag:
        break
#print(i,k,flag)        
print("Yes" if flag else "No")


### FIXED CODE ###

n,m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

flag = False  
for i in range(n-m+1):
    #flag = True
    for k in range(n-m+1):
        flag=True#ここ
        for j in range(i,i+m):
            #if i==k==3:
            #    print(a[j][k:k+m],b[j-i],a[j][k:k+m]==b[j-i],flag)
            if a[j][k:k+m]!=b[j-i]:
                flag = False
                break
        if flag:
            break
    if flag:
        break
#print(i,k,flag)        
print("Yes" if flag else "No")
s = input()

def kaibun1(w):
  w = str(w)
  t = len(w)
  n = 1
  while n < t//4:
    if w[n-1] == w[(t-1)//2 - (n-1)]:
      n += 1
    else:
      return False
      break

def kaibun2(w):
  w = str(w)
  t = len(w)
  m = 1
  while m < t//4:
    if w[t+3//2-1+(m-1)] == w[t-(m-1)]:
      m += 1
    else:
      return False
      break
if len(s) == 3:
  if s[0] == s[2]:
    print('Yes')
  else:
    print('No')
else:      
  if kaibun1(s)  is False or kaibun2(s) is False:
    print('No')
  else:
    print('Yes') 

### FIXED CODE ###

s = input()
n = len(s)
s1 = s[0:(n-1)//2]
s2 = s1[::-1]
s3 = s[(n+3)//2-1:n]
s4 = s3[::-1]
if s1 == s2 == s3 == s4:
  print('Yes')
else:
  print('No')
nums = input().split()

if nums[0] == "0":
print(1)

elif nums[1] == "0":
print(2)

elif nums[2] == "0":
print(3)

elif nums[3] == "0":
print(4)

elif nums[4] == "0":
print(5)


### FIXED CODE ###

# coding: utf-8
# Your code here!
x=input().split()



if(x[0]=="0"):
    print(1)
elif(x[1]=="0"):
    print(2)
elif(x[2]=="0"):
    print(3)
elif(x[3]=="0"):
    print(4)
elif(x[4]=="0"):
    print(5)
N = int(input())
X = str(input())
X10 = int(X,2)

one_num = X.count("1")
X10_pl = X10%(one_num+1)
X10_mi = X10%(one_num-1)

for i in range(N):
    target = int(X[i])
    
    if target == 0:
        ones = one_num + 1
        plus = pow(2,N-i-1,ones)
        Xnow = (X10_pl + plus)%ones
        
    else:
        if one_num == 1:
            print(0)
            continue
        ones = one_num-1
        plus = -pow(2,N-i-1,ones)
        Xnow = (X10_mi + plus)%ones

    count=1
    
    while Xnow > 0:
        Xnow2 = bin(Xnow)
        ones = Xnow2.count("1")
        Xnow = Xnow%ones
        count+=1
        
    print(count)



### FIXED CODE ###

N = int(input())
x2 = input()
x10 = int(x2, 2)
popc =  x2.count("1")
#print("x10", x10)
#print("popc", popc)
#popc: Nを2進数で表したときの1の個数

#以下で1つフリップさせた時の入力に対する余りを事前に計算
if popc <= 1:
    xp = x10%(popc+1)
    xm = 0
else:
    xp = x10%(popc+1)
    xm = x10%(popc-1)
#print("xp", xp)
#print("xm", xm)

#以下でフリップさせた場所のみを計算
for i in range(N):
    if x2[i] == "1":
        if popc == 1:
            print(0)
            continue
        tmp = (xm - pow(2, N-i-1, popc-1))%(popc-1)
    else:
        tmp = (xp + pow(2, N-i-1, popc+1))%(popc+1)
        
    #print("tmp", tmp)
    ans = 1
    while tmp > 0:
        tmp %= bin(tmp).count("1")
        ans += 1
    print(ans)
k,s=map(int,input(),split())

ans=0
for x in range(k+1):
    for y in range(k+1):
        z=S-x-y
        if 0<=s and z<=k:
            ans+=1
            
print(ans)
            
        




### FIXED CODE ###

k,s=map(int,input().split())
#k=2
#s=2
result=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
            result+=1
            
print(result)
N, K = map(int,input().split())
H = list(map(int,input().split()))
if K >= N:
  print(0)
else:
  H.sort
  print(sum(H[0:N-K])

### FIXED CODE ###

N, K = map(int,input().split())
H = list(map(int,input().split()))
if K >= N:
  print(0)
else:
  H.sort()
  print(sum(H[0:N-K]))
import itertools
N = int(input())
S = input()
C = np.array(list(itertools.combinations_with_replacement(range(1, N + 1), 3)))
count = 0
for i, j, k in C:
    if (i != 2 * j - k) and (S[i - 1] != S[j - 1] and S[i - 1] != S[k - 1] and S[j - 1] != S[k - 1]):
        count += 1
print(count)


### FIXED CODE ###

N = int(input())
S = input()
count = S.count("R") * S.count("G") * S.count("B")


for j in range(N):
    for i in range(j):
        k = 2 * j - i
        if k >= N:
            continue
        if (S[i] != S[j]) and (S[i] != S[k]) and (S[j] != S[k]):
            count -= 1
print(count)
N, X, Y = map(int, input().split(' '))

dct = {X : Y}
short = Y - X - 1

dist_list = [0] * N

for i in range(1,N):
    for j in range(i+1,N+1):
        d1 = abs(X - i) + 1 + abs(Y - j)
        d2 = j - i
        dist = min(d1,d2)
        dist_list[dist] += 1

for k in range(1,N):
    print(dist[k])

### FIXED CODE ###

S = list(input())

if S[2] == S[3] and S[4]==S[5]:
    print('Yes')
else:
    print('No')
AC = 0
WA = 0
TLE = 0
RE = 0
from collections import defaultdict
d = defaultdict(0)
print(d[1])
N = int(input())
for i in range(N):
  s = input()

### FIXED CODE ###

li = ["AC", "WA", "TLE", "RE"]
from collections import defaultdict
d = defaultdict(int)
N = int(input())
for i in range(N):
  s = input()
  d[s] += 1
for an in li:
  print(f"{an} x {d[an]}")
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def main():
    n, k = map(int, input().split())
    ans = 0
    for i in range(k, n + 2):
        ans += i * (n - i + 1) + 1
    print(ans%MOD)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
MOD = 10**9 + 7

def main():
    n, k = map(int, input().split())
    ans = 0
    for i in range(k, n + 2):
        ans += i * (n - i + 1) + 1
    print(ans%MOD)


if __name__ == '__main__':
    main()
2
10000000 10000000

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
print('YES' if len(list(set(a)))==n else 'NO')
N,ma,mb = map(int,raw_input().split())

a=[]
b=[]
c=[]
for i in range(N):
	at,bt,ct=map(int,raw_input().split())

	a.append(at)
	b.append(bt)
	c.append(ct)
	

dp = [[[10**10 for i in range(400+1)] for j in range(400+1)] for k in range(N+1)]
dp[0][0][0]=0
for i in range(N):
	for j in range(401):
		for k in range(401):
			if(dp[i][j][k]<10**10):
				dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i])

int ans=10**10

for i in range(1,401):
	for j in range(1,401):
		if i*mb==j*ma:
			ans=min(ans,dp[N][i][j])

if ans>=10**10:
	print -1
else:
	print ans

### FIXED CODE ###

N,ma,mb = map(int,raw_input().split())

a=[]
b=[]
c=[]
for i in range(N):
	at,bt,ct=map(int,raw_input().split())

	a.append(at)
	b.append(bt)
	c.append(ct)
	

dp = [[[10**10 for i in range(400+1)] for j in range(400+1)] for k in range(N+1)]
dp[0][0][0]=0
for i in range(N):
	for j in range(401):
		for k in range(401):
			if(dp[i][j][k]<10**10):
				dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i])

ans=10**10

for i in range(1,401):
	for j in range(1,401):
		if i*mb==j*ma:
			ans=min(ans,dp[N][i][j])

if ans>=10**10:
	print -1
else:
	print ans
n = input()
s = {input() for i in range(3)}

print(len(s))

### FIXED CODE ###

n = int(input())
s = {input() for i in range(n)}
 
print(len(s))
N, A, B = map(int, input().split())
round_count = 0

med = N / 2 + 0.5

for i in range(1e18):
    if abs(A - B) % 2 == 0:
        if A > B:
            A = A - 1
            B = B + 1

            if A < 1:
                A = 1
            elif B > N:
                B = N
        else:
            A = A + 1
            B = B - 1

            if A > N:
                A = N
            elif B < 1:
                B = 1
    else:
        Max = max([A, B])
        Min = min([A, B])
        if (Max + Min) / 2 > med:
            A = A + 1
            B = B + 1

            if A > N:
                A = N
            elif B > N:
                B = N
        else:
            A = A - 1
            B = B - 1

            if A < 1:
                A = 1
            elif B < 1:
                B = 1

    round_count = round_count + 1

    if A == B:
        break

print(round_count)

### FIXED CODE ###

N, A, B = map(int, input().split())

med = N / 2 + 0.5
Sub = B - A

if (Sub) % 2 == 0:
    round_count = Sub // 2
else:
    round_count = min(A - 1, N - B) + 1 + (Sub - 1) // 2
            
print(round_count)
def main():
    import numpy as np
    import sys
    input = sys.stdin.readline

    n,w = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]

    dp = np.zeros(n+1,w+1)
    for i in range(n):
        dp[i+1,l[i][0]:] = np.maximum(dp[i,l[i][0]:],dp[i,-l[i][0]]+l[i][1])
    print(dp[n][w])

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    n,w = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]

    dp = [[0]*(w+1) for i in range(n+1)]
    for i in range(1,n+1):
        for j in range(w+1):
            if j-l[i-1][0] >= 0:
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-l[i-1][0]]+l[i-1][1])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp[n][w])
if __name__ == "__main__":
    main()
n = int(input())
i = 0

x = map(int, input().split())

mx = max(x)
mn = min(x)
sum = 0

while i < n:
    sum = sum + x[i]
    i += 1
    
print(mn, mx, sum)

### FIXED CODE ###

n = int(input())
i = 0

x = list(map(int, input().split()))

mx = max(x)
mn = min(x)
sum = 0

while i < n:
    sum = sum + x[i]
    i += 1
    
print(mn, mx, sum)
l = list(map(int,input().split()))

if l[1] < l[2]:
    print(0)
elif l[0] > l[4]:
    print(0)
else:
    print(l[2]-l[1])

### FIXED CODE ###

l = list(map(int,input().split()))

if l[1] < l[2]:
    print(0)
elif l[0] > l[3]:
    print(0)
else:
    l.sort()
    print(l[2]-l[1])
import math
A, B = map(int, input().split())

if B> A:
	print(math.ceil((B-1)//(A-1))
  
else:
	print(1)

### FIXED CODE ###

import math
A, B = map(int, input().split())

print(math.ceil((B-1)/(A-1)))
N,K = map(int, input().split())
A =[0]
B=list(map(int, input().split()))
for m in range(N):
    A.append(B[m])
place=set([])
p=[]
i=1
count=0
while i not in place:
    place.add(i)
    p.append(i)
    i=A[i]
    count+=1
if count>=K:
    print(p[K])
else:
    loop=[i]
    start=i
    j=A[i]
    count+=1
    while j!=start:
        loop.append(j)
        j=A[j]
        count+=1
    if count>=K:
        print(loop[K-len(p)])
    else:
        num=(K-count)%len(loop)
        print(loop[0])

### FIXED CODE ###

N,K = map(int, input().split())
A =[0]
B=list(map(int, input().split()))
for m in range(N):
    A.append(B[m])
place=set([])
p=[]
i=1
count=0
while i not in place:
    place.add(i)
    p.append(i)
    i=A[i]
    count+=1
if count>K:
    print(p[K])
else:
    loop=[i]
    start=i
    j=A[i]
    count+=1
    while j!=start:
        loop.append(j)
        j=A[j]
        count+=1
    if count>K:
        print(loop[K-len(p)])
    else:
        num=(K-count)%len(loop)
        print(loop[num])
s = input()


def reverse(text):
    return text == ''.join(list(reversed(text)))


N = len(s)

if reverse(s) and reverse(s[:(N-1)/2]) and reverse(s[(N+3)/2 - 1:]):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

s = input()


def reverse(text):
    return text == ''.join(list(reversed(text)))


N = len(s)

if reverse(s) and reverse(s[:int((N-1)/2)]) and reverse(s[int((N+3)/2) - 1:]):
    print('Yes')
else:
    print('No')
import numpy as np

H, W, M = map(long, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = np.zeros((H, W))
ans = 3
'''
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if m[i[0]][j[0]] == 1.:
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp
'''
print(int(ans))


### FIXED CODE ###

import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = {}
flag = 0

for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[(tmp_h-1, tmp_w-1)] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if (i[0], j[0]) not in m.keys():
            flag = 1
            break

if flag == 1:
    print(int(h_max + w_max))
else:
    print(int(h_max + w_max - 1))
N, Q = map(int,input().split())
graph = {i:[] for i in range(N)}
G = {i:[] for i in range(N)}
ans = [0 for i in range(N)]
c = [0 for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  graph[a-1] += [b-1]
  graph[b-1] += [a-1]
stuck = [0]
log = [0 for i in range(N)]
log[0]=1
ls = [0]
while stuck:
  x = stuck.pop()
  A = graph[x]
  flag = True
  ki = []
  for a in A:
    if log[a]==0:
      stuck+=[a]
      ki+=[a]
      log[a]=1
      flag = False
  for l in ls:
    G[l] += ki
  ls += ki
  if flag:
    ls.remove(x)
for i in range(Q):
  p, x = map(int,input().split())
  p = p-1
  c[p]+=x

for k in G.keys():
  for x in G[k]:
    ans[x]+=c[k]
  ans[k]+=c[k]
A = map(str,ans)
print(' '.join(ans))

### FIXED CODE ###

from collections import deque
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
count = [0]*N
for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for i in range(Q):
    p, x = map(int, input().split())
    count[p-1]+=x
q = deque([0])
flag = [False]*N
while q:
    v = q.pop()
    flag[v] = True
    for e in G[v]:
        if flag[e]:
            continue
        count[e]+=count[v]
        q.append(e)
print(*count)
S = input()
T = input()

U = T + S
print(U)

### FIXED CODE ###

S, T = (str(i) for i in input().split())

U = T + S
print(U)
S = input()
print('Heisei' if S[5, 7] < '04' or (S[6] == 4 and S[8,] < '31') else 'TBD')

### FIXED CODE ###

S = input()
print('Heisei' if S[5:7] < '04' or (S[6] == '4' and S[8:] < '31') else 'TBD')
k,s = map(int,input().split())

c = 0

if s == 3*k:
  c = 1
elif s >= 2*k:
  c = (5 - s % k) * 3
elif s >= k:
  c = pass
else:
  c = 3 * k
  
print(c)

### FIXED CODE ###

k,s = map(int,input().split())

c = 0

for x in range(k+1):
  for y in range(k+1):
    if 0 <= (s - x - y) <= k:
      c += 1
print(c)
while 1:
  a,op,b = map(str,raw_input().split())
  if op == "+":
    print "%d" %(a + b)
  elif op == "-":
    print "%d" %(a - b)
  elif op == "*":
    print "%d" %(a * b)
  elif op == "/":
    print "%d" %(a / b)
  else:
    break
  

### FIXED CODE ###

while 1:
  s = raw_input().split()
  a, b =int(s[0]), int(s[2])
  op = s[1] 

  if op == "+":
    print "%d" %(a + b)
  elif op == "-":
    print "%d" %(a - b)
  elif op == "*":
    print "%d" %(a * b)
  elif op == "/":
    print "%d" %(a / b)
  else:
    break
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
x = len(a) // n
l = []
for i in range(n):
    for j in range(x):
        ll.append(a[i+j::x-1])
      
ans = 0
for i in range(n):
    ans += l[i][1]
print(ans)

### FIXED CODE ###

n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0

for i in range(n):
    ans += a[i * 2 + 1]

print(ans)