Harryxun/stf_run huggingface dataset:
ts = []
ts_mod = []
for i in range(5):
    ts.append(int(input()))
    ts_mod.append(ts[i] % 10)


def find_index(ts, ts_mod):
    result = 10
    for i in range(len(ts_mod)):
        if ts_mod[i] == 0:
            pass
        else:
            if result > ts_mod[i]:
                result = ts_mod[i]
    return ts_mod.index(result)

min_ind = find_index(ts, ts_mod)

last_ts = ts[min_ind]

del ts_mod[min_ind]
del ts[min_ind]


result = 0
for i in range(len(ts_mod)):
    if ts[i] % 10 == 0:
        result += ts[i]
    else:
        result += ts[i] + ( 10 - ts[i] % 10 )
        
result += last_ts
print(result)

### FIXED CODE ###

ts = []
ts_mod = []
for i in range(5):
    ts.append(int(input()))
    ts_mod.append(ts[i] % 10)


def find_index(ts, ts_mod):
    if all([x == 0 for x in ts_mod]):
        return 0
    else:
        result = 10
        for i in range(len(ts_mod)):
            if ts_mod[i] == 0:
                pass
            else:
                if result > ts_mod[i]:
                    result = ts_mod[i]
        return ts_mod.index(result)

min_ind = find_index(ts, ts_mod)

last_ts = ts[min_ind]

del ts_mod[min_ind]
del ts[min_ind]


result = 0
for i in range(len(ts_mod)):
    if ts[i] % 10 == 0:
        result += ts[i]
    else:
        result += ts[i] + ( 10 - ts[i] % 10 )
        
result += last_ts
print(result)
a = int(input())
b = int(input())
c = int(input())
print((a+b)*h//2)

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
print((a+b)*c//2)
n=int(input())
h=[int(i) for i in input().split()]
r=0
k=0
for i in range(n):
  if h(i+1)>=h(i):
    k+=1
  else:
    r=max(k,r)
    k=0
print(r)

### FIXED CODE ###

n=int(input())
h=[int(i) for i in input().split()]
r=0
k=0
for i in range(n-1):
  if h[i+1]<=h[i]:
    k+=1
  else:
    r=max(k,r)
    k=0
r=max(k,r)
print(r)
import numpy as np
H,W = map(int,input().split())
S=np.array([list(input().rstrip("\n")) for _ in range(H)]) == '.'
D = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)
for i in range(H):# 上下
  U[i] = (U[i-1] + 1) * S[i]
  D[-i-1] = (D[-i] + 1) * S[-i-1]
for i in range(W):# 左右
  L[:,i] = (L[:,i-1] + 1) * S[:,i]
  R[:,-i-1] = (R[:,-i] + 1) * S[:,-i-1]
print(np.max(U+D+L+R)-3)

### FIXED CODE ###

import numpy as np
H,W = map(int,input().split())
S=np.array([list(input().rstrip("\n")) for _ in range(H)]) == '.'
D = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)
for i in range(H):# 上下
  U[i] = (U[i-1] + 1) * S[i]
  D[-i-1] = (D[-i] + 1) * S[-i-1]
for i in range(W):# 左右
  L[:,i] = (L[:,i-1] + 1) * S[:,i]
  R[:,-i-1] = (R[:,-i] + 1) * S[:,-i-1]
print(np.max(U+D+L+R)-3)
def main():
    N,M=map(int,input().split())
    a=1
    b=N-1
    for i in range(1,M+1):
        print(a,b)
        a+=1
        b-=1
if __name__=='__main__':
    main()


### FIXED CODE ###

def makeSeqList(N,M,curList,res):
    if len(curList)==N:
        res.append(curList.copy())
        return

    for i in range(1,M+1):
        if len(curList)!=0 and i<curList[-1]:
            continue
        curList.append(i)
        makeSeqList(N,M,curList,res)
        del curList[-1]

def main():
    N,M,Q=map(int,input().split())
    quadList=[]
    for _ in range(Q):
        quadList.append(list(map(int,input().split())))
    res=[]
    makeSeqList(N,M,[],res)
    ans=-1
    for sequence in res:
        summ=0
        for q in quadList:
            if (sequence[q[1]-1]-sequence[q[0]-1])==q[2]:
                summ+=q[3]
        ans=max(ans,summ)
    print(ans)

if __name__=='__main__':
    main()
S = input()
if S = ABC:
	retrun ARC
else:
	retrun ABC

### FIXED CODE ###

S = input()
if S == 'ABC':
	print('ARC')
else:
	print('ABC')
import sys
import math

x_list = []

for line in sys.stdin.readlines():
  x_list.append(int(line.strip()))

count = 0

num_list.remove(x_list[0])

for i in x_list:
  flag = 0
  for j in range(2, math.sqrt(i)+1):
    if i % j == 0:
      flag = 1
      break
    if flag == 0:
      count ++

print count
    

### FIXED CODE ###

import sys
import math

x_list = []

for line in sys.stdin.readlines():
  x_list.append(int(line.strip()))

count = 0

x_list.remove(x_list[0])

for i in x_list:
  flag = 0
  for j in range(2, int(math.sqrt(i))+1):
    if i % j == 0:
      flag = 1
      break
  if flag == 0:
    count += 1

print count
m = map(int,input().split())
print m[0]*m[1],2*(m[0]+m[1])

### FIXED CODE ###

m = map(int,raw_input().split())
print m[0]*m[1],2*(m[0]+m[1])
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if a[-1] < k:
    print("IMPOSSIBLE")
    exit()
if n > 1:
    m = 10**9
    for i in range(n-1):
        m = min(m, abs(a[i+1]-a[i]))
    for i in range(n):
        if abs(a[i]-k) % m == 0:
            print("POSSIBLE")
            exit()
else:
    if a[0] == k:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

a = sorted(list(set(a)))

if a[-1] < k:
    print("IMPOSSIBLE")
    exit()

n = len(a)

if n > 1:
    m = 10**9
    for i in range(n-1):
        if a[i] != a[i+1]:
            m = min(m, abs(a[i+1]-a[i]))
    for i in range(n):
        if abs(a[i]-k) % m == 0:
            print("POSSIBLE")
            exit()
else:
    if a[0] == k:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")
N = input()
N = list(map(int,[i for i in N]))
lst = base_convert(N,10,26)
lst_converted = convertList(lst)
print(''.join([dict1[i] for i in lst_converted]))

### FIXED CODE ###

def base_convert(nl, ibase, obase):
    o = []
    while any(nl):
        c = 0
        for i in range(len(nl)):
            c = c * ibase + nl[i]
            nl[i],c = divmod(c,obase)
        o.append(c)
    o.reverse()
    return o

def convertList(lst):
    rev_lst = list(reversed(lst))
    for i,num in enumerate(rev_lst):
        if i < len(rev_lst)-1:
            if num <= 0:
                rev_lst[i+1] = rev_lst[i+1]-1
                rev_lst[i] = rev_lst[i] + 26
    return list(reversed(rev_lst))

dict1 = {
    0: '',
    1: 'a',
    2: 'b',
    3: 'c',
    4: 'd',
    5: 'e',
    6: 'f',
    7: 'g',
    8: 'h',
    9: 'i',
    10: 'j',
    11: 'k',
    12: 'l',
    13: 'm',
    14: 'n',
    15: 'o',
    16: 'p',
    17: 'q',
    18: 'r',
    19: 's',
    20: 't',
    21: 'u',
    22: 'v',
    23: 'w',
    24: 'x',
    25: 'y',
    26: 'z'
}

N = input()
N = list(map(int,[i for i in N]))
lst = base_convert(N,10,26)
lst_converted = convertList(lst)
ans = ''.join([dict1[i] for i in lst_converted])
print(ans)
a,b=map(int,input().split())
ans=a*b
p=math.log10(ans)
if p>=18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

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

flg=True
if 0 in list:
  print(0)
  flg=False
else:
  prod=1
  for a in list:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      flg=False
      break
if flg:
  print(prod)
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
p = list(map(int, input().split()))
l = []
for i in range(1,101):
  l.append(i)
L = []
for i in l:
  if i not in p:
    L.append(i)
l = []
for i in L:
  l.append([i, abs(x-i)])
a = min(l, key = lambda t: t[1])
print(list(a)[0])

### FIXED CODE ###

x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()

p = list(map(int, input().split()))
l = []
for i in range(-100,102):
  l.append(i)

L = []
for i in l:
  if i not in p:
    L.append(i)

l = []
for i in L:
  l.append([i, abs(x-i)])
a = min(l, key = lambda t: t[1])
print(list(a)[0])
s=int(input())
l=[]
while(s not in 1):
  l.append(s)
  if s%2==0:s//=2
  else:s=s*3+1
print(len(l)+1)

### FIXED CODE ###

s=int(input())
l=[]
while(s not in l):
  l.append(s)
  if s%2==0:s//=2
  else:s=s*3+1
print(len(l)+1)
s = input()
m = []

for c in s:
  if c == 'B':
    if s:
      m.pop()
  else:
    m.append(c)

print(''.join(m))

### FIXED CODE ###

s = input()
m = []

for c in s:
  if c == 'B':
    if m:
      m.pop()
  else:
    m.append(c)

print(''.join(m))
import numpy as np

num=np.array(list(map(int,input().split())))

history = []
count = 0

for i in range(0,num[0]):
    history.append(num[i+1])
    num_min = np.min(history)
    if(num[i+1] <= num_min):
        count = count + 1

print(count)

### FIXED CODE ###

num = [input() for i in range(2)]
num_0 = int(num[0])
num_1 = list(map(int, num[1].split()))

num_min = num_1[0]
count = 0

for i in range(0,num_0):
  if(num_min >= num_1[i]):
    count = count+1
    num_min = num_1[i]
    
print(count)
#coding: UTF-8

for i in range(1,10):
    for j in range(1,10):
        print(i + "*" + j + "=" + i*j)

### FIXED CODE ###

#coding: UTF-8

for i in range(1,10):
    for j in range(1,10):
        print str(i) + 'x' + str(j) + '=' + str(i*j)
n = list(input())
a, b = map(int, input())

count = 0
for j in range(n):
    l = [n[i] for i in range(len(j))]
    sum = sum(l)
    if a <= sum and sum <= b:
        count += 1
print(count)


### FIXED CODE ###

m, a, b = map(int, input().split())

x = []
for j in range(1, m + 1):
    n = list(str(j))
    l = [int(n[i]) for i in range(len(n))]
    if len(l) == 1:
        l.append(0)
    s = sum(l)
    if a <= s and s <= b:
        x.append(j)
print(sum(x))
N,K=map(int,input().split())
td=[[int(a) for a in input().split()]for i in range(N)]

td=sorted(td,key=lambda x:-x[1])

ans=0
eat=[]
noteat=[]
for t,d in td[:K]:
  ans+=d
  if t not in eat:
    eat.append(t)
  else:
    noteat.append(d)
temp_result=ans+len(eat)**2
max_result=temp_result

for t,d in td[K:]:
  if not noteat:
    break
  if t not in eat:
    temp_result+=2*len(eat)+1
    temp_result+=d-noteat.pop()
    eat.add(t)
    max_result=max(max_result,temp_result)
print(max_result)
 



### FIXED CODE ###

a,b,c=map(int,input().split())
arr=sorted([a,b,c])
print(int(arr[0]*arr[1]/2))
a,b,c = map(int,input().split())

print(a - b - (c *((a-b) // c)))

### FIXED CODE ###

X,A,B = (int(input()) for i in range(3))

print((X-A) % B)
n = int(input())
k = int(input())
summ = 0
for _ in range(n):
  x = int(input())
  summ += min(2*x, 2*(k-x))
 print(summ)

### FIXED CODE ###

n = int(input())
k = int(input())
summ = 0
x = list(map(int, input().split()))
for i in x:
	summ += min(2*i, 2*(k-i))
print(summ)
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
a.insert(0,10000)
a.append(0)
l=[0]*(n+2)
for i in range(1,n+1):
    if a[i-1]<a[i]>=a[i+1]:
        l[i]=1
    elif a[i-1]>a[i]<=a[i+1]:
        l[i]=-1
sto=[0,1000]
for i in range(n+2):
    if l[i]==-1:
        sto[0],sto[1]=divmod(sto[1],a[i])
    if l[i]==1:
        sto[1]+=sto[0]*a[i]
        sto[0]=0
if sto[0]!=0:
    for i in range(n+2):
        if l[n+2-i]==-1:
            print(sto[1]+sto[0]*a[n+2-1])
            exit()
else:
    print(sto[1])

### FIXED CODE ###

import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
a.insert(0,10000)
a.append(0)
i=0
m=len(a)
while i<m-1:
    if a[i]==a[i+1]:
        del a[i]
        i-=1
    i+=1
    m=len(a)

n=len(a)-2

l=[0]*(n+2)
for i in range(1,n+1):
    if a[i-1]<a[i]>a[i+1]:
        l[i]=1
    elif a[i-1]>a[i]<a[i+1]:
        l[i]=-1
sto=[0,1000]
for i in range(n+2):
    if l[n+1-i]==-1:
        l[n+1-i]=0
        break
    elif l[n+1-i]==1:
        break
for i in range(n+2):
    if l[i]==-1:
        sto[0],sto[1]=divmod(sto[1],a[i])
    if l[i]==1:
        sto[1]+=sto[0]*a[i]
        sto[0]=0
print(sto[1])
a,b = map(int,input().split())
c = [0]*(b-a+1)
j = 0
for i in range(a,b+1):
    c[j] = i%2019
    j += 1
x = min(c)
c.remove(x)
y = min(c)
print((x*y)%2019)

### FIXED CODE ###

a,b = map(int,input().split())
c = [2019]*2
p = 0
flag = 0
if (b-a) >= 2019:
    for j in range(a,a+2020):
        if j%2019 == 0:
            flag = 1
            break
        for l in range(j+1,a+2020):
            if l%2019==0:
                flag = 1
                break
            c[1] = (j*l)%2019
            c[0] = (j*l)%2019 if c[0] > c[1] else c[0]
else:
    for m in range(a,b+1):
        if m%2019 == 0:
            flag = 1
            break
        for n in range(m+1,b+1):
            if n%2019==0:
                flag = 1
                break
            c[1] = (n*m)%2019
            c[0] = (n*m)%2019 if c[0] > c[1] else c[0]
if flag == 1:
    print(0)
else:
    print(c[0])
a,b = map(raw_input().split())

if a > b:
  print "a > b"

elif a < b:
  print "a < b"

else:
  print "a == b"

### FIXED CODE ###

a,b = map(int, raw_input().split())
 
if a > b:
  print 'a > b'
 
elif a < b:
  print 'a < b'
 
else:
  print 'a == b'
a, b = map(int, input().split())
    if (a*b)% 2 == 0:
        print("Even")
    else:
        print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
if (a*b)% 2 == 0:
   print('Even')
else:
   print('Odd')
N = int(input())
s = list(map(int, input().split()))

count = 0

for i in range(N+1):
  if ((i+1)%2 == 1) and (s[i]%2 == 1):
    count = count + 1

print(count)

### FIXED CODE ###

N = int(input())
s = list(map(int, input().split()))

count = 0

for i in range(1,N+1):
  if (i%2 == 1) and (s[i-1]%2 == 1):
    count = count + 1
 

print(count)
a,b,c = [int(i) for i in input() split()]
if a < b < c:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a,b,c = [int(i) for i in input().split()]
if a < b < c:
  print('Yes')
else:
  print('No')
s = input()
ans = []
counter = 0
for i in s:
    if i in 'ATGC':
        counter += 1
    else:
        ans.append(counter)
        conuter = 0
print(max(ans))

### FIXED CODE ###

s = input()
ans = []
counter = 0
for i in s:
    if i in 'ATGC':
        counter += 1
    else:
        counter = 0
    ans.append(counter)
print(max(ans))
S = list(input())
result = []
if len(set(S))==2:
  for s in S:
    result.append(S.count(s))
    if result[0]==result[1]:
      print("Yes")
      exit()
print("No")

### FIXED CODE ###

S = list(input())
result = []
if len(set(S))==2:
  for s in list(set(S)):
    result.append(S.count(s))
  if result[0]==result[1]:
    print("Yes")
  else:
    print("No")
else:
  print("No")
n,w = map(int,input().split())
w_ls, v_ls = [0] * n, [0] * n
for i in range(n):
    w_ls[i], v_ls[i] = map(int,input().split())
V = sum(v_ls)
dp = [[float("inf")] * (V+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(n):
    for j in range(V+1):
        if j - v[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ans = 0
for j in range(V+1):
    if dp[N][j] <= W:
        ans = j

print(ans)

### FIXED CODE ###

n,w = map(int,input().split())
w_ls, v_ls = [0] * n, [0] * n
for i in range(n):
    w_ls[i], v_ls[i] = map(int,input().split())
V = sum(v_ls)
dp = [[float("inf")] * (V+1) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    for j in range(V+1):
        if j - v_ls[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j-v_ls[i]] + w_ls[i])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ans = 0
for j in range(V+1):
    if dp[n][j] <= w:
        ans = j

print(ans)
a=int(input())
n = math.floor(a/500)
total_price= n * 1000 + (a - n * 500)
print(total_price)

### FIXED CODE ###

import math
a=int(input())
n = math.floor(a/500)
m = math.floor((a - n * 500)/5)
total_price= n * 1000 + m*5
print(total_price)
import sys

N, M = map(int, input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))


cpi = [-1,0,0,1]
cpj = [0,-1,1,0]

smFlag = False

for i in range(N):
    for j in range(M):
        if a[i][j] == '#':
            for x,y in zip(cpi,cpj):
                if i + x > -1 and j + y > -1 and i + x < N  and j + y < M:
                    if a[i+x][j+y] == '#':
                        smFlag = True
            if not smFlag:
                print('No')
                sys.exit()

print('Yes')



### FIXED CODE ###

H, W = map(int, input().split())
a = []
tmp = []
for i in range(H):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            if j - 1 >= 0 and a[i][j - 1] == "#":
                continue
            elif j + 1 < W and a[i][j + 1] == "#" :
                continue
            elif i + 1 < H and a[i + 1][j] == "#" :
                continue
            elif i - 1 >= 0 and a[i - 1][j] == "#":
                continue
            else:
                print("No")
                exit()
 
print("Yes")
# -*- coding: utf-8 -*-
#ABC070C
import math

def lcm(x, y):
	ans=((x * y) // math.gcd(x, y))
	return ans

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

t=[]
for i in range(0,n):
	t.append(int(input()))
#print(t)

ans = t[0]
for i in range(1,n):
	ans = lcm(ans,t[i])

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
#ABC070C
import math

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n = int(input())

t=[]
for i in range(0,n):
	t.append(0)
for i in range(0,n):
    t[i] = int(input())

ans = t[0]
for i in range(1,n):
	j = gcd(ans,t[i])
	ans *= t[i]
	ans = ans//j

print(ans)
Total_dist = 0

#iterate through number of bals
for i in range(N):
	for Rtype in ['A','B']:
		dist = []
		if Rtype == 'A':
			dist.append(abs(X[i] - 0))
		if Rtype == 'B':
			dist.append(abs(X[i] - K))
	Total_dist += min(dist)

print(Total_dist)

### FIXED CODE ###

N = int(input())
K = int(input())
X = list(map(int, input().split()))
Total_dist = 0

#iterate through number of bals
for i in range(N):
	dist = []
	for Rtype in ['A','B']:
		if Rtype == 'A':
			dist.append(abs(X[i] - 0)*2)
		if Rtype == 'B':
			dist.append(abs(X[i] - K)*2)
	Total_dist += min(dist)

print(Total_dist)
N, M = map(int, input())
if N * 2 >= M:
  print(M // 2)
else:
  print(N + (M - N * 2) // 3)

### FIXED CODE ###

N, M = map(int, input().split())
if N * 2 >= M:
  print(M // 2)
else:
  print(N + (M - N * 2) // 4)
import bisect
import numpy as np
import scipy as sp
from sys import stdin

r, g, b, n = map(int, input().split())
count = 0

for i in range(n + 1):
    for j in range(n + 1):
        total = n - r * i - g * j
        if total < 0:
        	break
        if total % b == 0:
            count += 1

print(count)


### FIXED CODE ###

import bisect
import numpy as np
import scipy as sp
from sys import stdin

n, k = map(int, input().split())
print(n - k + 1)
n = int(input())
a = list(map(int, input().split()))
b = [0]*64
for i in range(n):
    c = bin(a[i])[2:]
    for j, q in enumerate(c):
        if q == '1':
            b[i] += 1
c = 0
b = b[::-1]
for i in range(64):
    c += b[i]*(n-b[i])*2**i
print(c % (10**9+7))


### FIXED CODE ###

MOD = 10 ** 9 + 7
t = [0] * 60
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        if (a[j] >> i) & 1:
            cnt += 1
    ans += cnt * (n - cnt) * pow(2, i, MOD)
print(ans % MOD)
N,M=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
l=[]
for b in a:
    for c in a:
        l.append(b + c)
print(sum(sorted(l)[len(l)-M:]))

### FIXED CODE ###

a,b=[i for i in input().split()]
print(b+a)
import heapq
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
if n == 1:
  print(0)
  exit()
if m*2 < n:
    print("Impossible")
    exit()

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

u = Unionfind(n)
a = list(map(int,input().split()))
for i in range(m):
    x,y = map(int,input().split())
    u.union(x,y)

l = [[] for i in range(n)]
for i in range(n):
    x = u.find(i)
    if x < 0:
        heapq.heappush(l[i],a[i])
    else:
        heapq.heappush(l[x],a[i])

h = []
for i in range(n):
    if l[i]:
        x = heapq.heappop(l[i])
        heapq.heappush(h,[x,i])
ans = 0
while len(h) > 1:
    a = heapq.heappop(h)
    b = heapq.heappop(h)
    ans += a[0]+b[0]
    l[a[1]] = list(heapq.merge(l[a[1]],l[b[1]]))
    x = heapq.heappop(l[a[1]])
    heapq.heappush(h,[x,a[1]])
    
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
from collections import deque

n,m = map(int,input().split())
if m == n-1:
  print(0)
  exit()
if 2*(n-m-1) > n:
    print("Impossible")
    exit()

e = [[] for i in range(n)]
a = list(map(int,input().split()))
for i in range(m):
    x,y = map(int,input().split())
    e[x].append(y)
    e[y].append(x)

def dfs(x):
    l = []
    d[x] = 1
    l.append(a[x])
    q = deque([])
    q.append(x)
    while q:
        now = q.pop()
        for nex in e[now]:
            if d[nex] > 0:
                continue
            l.append(a[nex])
            d[nex] = 1
            q.append(nex)
    l.sort()
    ans = l[0]
    
    for i in l[1:]:
        h.append(i)
    return ans
count = 2*(n-m-1)
d = [-1]*n
ans = 0
h = []
for i in range(n):
    if d[i] < 0:
        ans += dfs(i)
        count -= 1
if count > 0:
    h.sort()
    ans += sum(h[:count])
print(ans)
N,A,B = map(int,input().split())

r = ''
while True:
    r += "b"*A
    r += "r"*B
    if len(r) >= N:
        break
print(r[:N].count('b'))

### FIXED CODE ###

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

s = 0
s = int(N / (A+B))*A
if N % (A+B) > A:
    s += A
else:
    s += N % (A+B)
print(s)
l = map(int, input().split())
 
print(int(l[0] + l[1]/2))

### FIXED CODE ###

x, y = map(int, input().split())
print(x + y//2)
s = list(map(int, input().split()))
if s[0] > s[1]:
    print((s[1] * s[2] + (s[0] - s[1]) * s[3]))
          
else:
    print(s[0]*s[2])

### FIXED CODE ###

s = [int(input()) for i in range(4)]
if s[0] > s[1]:
    print((s[1] * s[2] + (s[0] - s[1]) * s[3]))
          
else:
    print(s[0]*s[2])
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from itertools import accumulate

fact = [1]

for i in range(1, 1001):
    fact.append(fact[-1] * i)


def comb(n, r):
    return int(fact[n] / fact[r] / fact[n-r])


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [[0] * 1001 for _ in range(1001)]
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += comb(nums[b], 3)
                tmp[b] = 1

            # if nums[b] >= 2 and a != b and tmp2[a][b] == 0:
            #     cnt += comb(nums[b], 2) * nums[a]
            #     tmp2[a][b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()
n,k=map(int,input().split())
l=[(int(i) for i in input().split())]
l.sort(reverse=True)
print(sum(l[:k]))


### FIXED CODE ###

n,k=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort(reverse=True)
print(sum(l[:k]))