Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import copy
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(b)]
s,t=map(int,input().split())
s=3*s
t=3*t
dd=[[]for i in range(a+1)]
for i in range(b):
  da=c[i][0]
  db=c[i][1]
  dd[da].append(db)
  

d=[[]for i in range(3*(a+1))]
for i in range(len(dd)):
  for j in dd[i]:
      d[3*i].append(3*j+1)
      d[3*i+1].append(3*j+2)
      d[3*i+2].append(3*j)
e=[s]
f=[s]
h=0
for i in range(1,3*a+3):
  g=[]
  for j in f:
    for k in d[j]:
      if k not in e:
        e.append(k)
        g.append(k)
        if k==t:
          print(i//3)
          h=1
          break
    if h==1:
      break
  if h==1:
    break
  if g==[]:
    print(-1)
    break
  f=copy.copy(g)

### FIXED CODE ###

import copy
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(b)]
s,t=map(int,input().split())
s=3*s
t=3*t
dd=[[]for i in range(a+1)]
for i in range(b):
  da=c[i][0]
  db=c[i][1]
  dd[da].append(db)
  

d=[[]for i in range(3*(a+1))]
for i in range(len(dd)):
  for j in dd[i]:
      d[3*i].append(3*j+1)
      d[3*i+1].append(3*j+2)
      d[3*i+2].append(3*j)
e=[-1 for i in range(3*a+3)]
f=[s]
h=0
for i in range(1,3*a+3):
  g=[]
  for j in f:
    for k in d[j]:
      if e[k]==-1:
        e[k]=1
        g.append(k)
        if k==t:
          print(i//3)
          h=1
          break
    if h==1:
      break
  if h==1:
    break
  if g==[]:
    print(-1)
    break
  f=copy.copy(g)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range(N):
    ans *= A[i]
if ans > 10**18:
    ans = -1
print(ans)

### FIXED CODE ###

import sys
N = int(input())
A = list(map(int, input().split()))
ans = 1
if 0 in A:
    print(0)
    sys.exit()
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)
### BUGGY CODE ###

import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
    R, C, K = MI()
    grid = make_grid_int(R, C, 0)

    for i in range(K):
        r_, c_, v_, = MI()
        grid[r_ - 1][c_ - 1] = v_


    dp = [[[0 for _ in range(4)] for _ in range(C + 2)] for _ in range(R + 2)]

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                try:
                    v = grid[i][j]
                except:
                    v = 0
                a = dp[i][j][k]
                if k == 3:
                    dp[i + 1][j][0] = max(a, dp[i + 1][j][0])
                    continue
                dp[i + 1][j][0] = max(a, a + v, dp[i + 1][j][0])
                dp[i][j + 1][k] = max(a, dp[i][j + 1][k])
                dp[i][j + 1][k + 1] = max(a + v, dp[i][j + 1][k + 1])

    ans = max(dp[R][C][0], dp[R][C][1], dp[R][C][2], dp[R][C][3])
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    R, C, K = NMI()
    item = [[0] * (C + 1) for i in range(R + 1)]

    for i in range(K):
        r_, c_, v_, = NMI()
        item[r_ - 1][c_ - 1] = v_

    dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)]

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                v = item[i][j]

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))

if __name__ == "__main__":
    main()
### BUGGY CODE ###

n,m,q=map(int,input().split())
line=sorted([list(map(int,input().split())) for i in range(m)])
question=[tuple(map(int,input().split())) for j in range(q)]
dis={}
for i in range(1,n+1):
    for j in range(1,n+1):
        dis[(i,j)]=0
        for x,y in line:
            if i<=x and y<=j:
                dis[(i,j)] +=1

for i in question:
    print(dis[i])

### FIXED CODE ###

import numpy as np
N, M, Q = map(int, input().split())

#input
lst = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    lst[R][L] += 1

lst = np.array(lst)
# print (lst)

#2次元累積和
for i in range(1, N + 1):
    lst[:,i] += lst[:, i - 1]
for j in range(1, N + 1):
    lst[j,:] += lst[j - 1, :]


#output
for _ in range(Q):
    p, q = map(int, input().split())
    print (lst[q, q] - lst[p-1, q] - lst[q, p-1] + lst[p-1, p-1])

# print (lst)
### BUGGY CODE ###


n = int(input())
s = list([input() for i in range(n)])
q = []
c = 0
for i in range(n):
	q.append(sorted(s[i]))

for i in range(n):
	for j in range(i+1,n):
		if i != j:
			if q[i] == q[j]:
				c += 1

print(int(c))

### FIXED CODE ###

n = int(input())
s = list([input() for i in range(n)])
q = [''.join(sorted(x)) for x in s]

c = 0
c1 =  0
p = sorted(q)
p.append("a")

for i in range(n):
	if p[i] == p[i+1]:
		c+=1
	else:
		
		if c>0:
			for j in range(c+1):
				c1+=j
				
		c=0
print(c1)
### BUGGY CODE ###

S = input()

suma,sumc,sumq=0,0,0
maxC=S.count("C")
maxQ=S.count("?")
mod=10**9+7  
ans=0

for i,s in enumerate(S):
  if s=="A":
    suma+=1
  elif s=="C":
    sumc+=1
  elif s=="?":
    sumq+=1
  
  if i==0 or i==len(S):
    continue
    
  if s=="?":
    k=maxQ-1
    ans+=suma*(maxC-sumc)*(3**k)%mod
    ans+=(sumq-1)*(maxC-sumc)*(3**(k-1))%mod
    ans+=suma*(maxQ-sumq)*(3**(k-1))%mod
    ans+=(sumq-1)*(maxQ-sumq)*(3**(k-2))%mod
  elif s=="B":
    k=maxQ
    ans+=suma*(maxC-sumc)*(3**k)%mod
    ans+=sumq*(maxC-sumc)*(3**(k-1))%mod
    ans+=suma*(maxQ-sumq)*(3**(k-1))%mod
    ans+=sumq*(maxQ-sumq)*(3**(k-2))%mod
  
print(int(ans%mod))

### FIXED CODE ###

S = input()
mod=10**9+7

suma,sumc,sumq=0,0,0
maxC=S.count("C")%mod
maxQ=S.count("?")%mod
ans1,ans2,ans3,ans4=0,0,0,0

for i,s in enumerate(S):
  if s=="A":
    suma+=1
    suma%=mod
  elif s=="C":
    sumc+=1
    sumc%=mod
  elif s=="?":
    sumq+=1
    sumq%=mod
  
  if i==0 or i==len(S):
    continue
  
  if s=="?":
    ans2+=suma    *(maxC-sumc)%mod
    ans3+=(sumq-1)*(maxC-sumc)%mod
    ans3+=suma    *(maxQ-sumq)%mod
    ans4+=(sumq-1)*(maxQ-sumq)%mod
  elif s=="B":
    ans1+=suma*(maxC-sumc)%mod
    ans2+=sumq*(maxC-sumc)%mod
    ans2+=suma*(maxQ-sumq)%mod
    ans3+=sumq*(maxQ-sumq)%mod
    
ans1*=3**maxQ%mod
ans2*=3**(maxQ-1)%mod
ans3*=3**(maxQ-2)%mod
ans4*=3**(maxQ-3)%mod
ans=ans1+ans2+ans3+ans4
print(int(ans%mod))
### BUGGY CODE ###

n=int(input())
count=0
dd=[]
for i in range(n):
  s=input()
  dic={}
  for j in range(0,10):
    k=s[j]
    if k in dic:
      dic[k]+=1
    else:
      dic[k]=1
  
  count+=dd.count(dic)
  dd.append(dic)
print(count)

### FIXED CODE ###

n=int(input())
count=0
dic={}
ppp=""
for i in range(n):
  s=list(input())
  s.sort()
  s=ppp.join(s)
  if s in dic:
    dic[s]+=1
  else:
    dic[s]=1
kouho=0
for j in range(len(dic)):
  kk=dic.popitem()
  c=kk[1]
  kouho+=(c*(c-1))//2
print(kouho)
### BUGGY CODE ###

#coding:utf-8
import numpy as np
n,k = map(int,input().split())
ls = list(map(int,input().split()))

# n, k = 5, 3
# ls = [-30,-10,10,20,50]
#
# n,k = 3,2
# ls=[10,20,30]

# n,k = 1,1
# ls = [0]

# n,k=8,5
# ls=[-9,-7,-4,-3,1,2,3,4]

def set_max(ls):
    if len(ls)>0:
        return set([max(ls)])
    else:
        return set()
def set_min(ls):
    if len(ls)>0:
        return set([min(ls)])
    else:
        return set()


plus = list(filter(lambda n:n>=0, ls))
minus = list(filter(lambda n:n<=0, ls))

neighbor = set_max(minus) | set_min(plus)

#print (neighbor)
answer = []
for i in range(n-k+1):
    if len(set(ls[i:i+k])&neighbor)>0:
        #print (ls[i:i+k])
        #print (np.sign(ls[i]*ls[i+k-1]))
        temp = [abs(ls[i]),abs(ls[i+k-1])]
        if np.sign(ls[i]*ls[i+k-1])<0:

            answer.append(2*min(temp)+max(temp))
        else:
            answer.append(max(temp))
print (min(answer))

# first = -1
# for i,point in enumerate(ls):
#     if point >= 0:
#         first = i
#         break
# size=k+1
# ans = []
# for i in range(size):
#     if first-size+i+1>=0 and first+i-1< len(ls):
#         temp = [0,ls[first-size+i+1],ls[first+i-1]]
#         temp = [abs(min(temp)),abs(max(temp))]
#         ans.append((2*min(temp)+max(temp)))
# print (min(ans))


### FIXED CODE ###

#coding:utf-8
import numpy as np
n,k = map(int,input().split())
ls = list(map(int,input().split()))

# n, k = 5, 3
# ls = [-30,-10,10,20,50]
#
# n,k = 3,2
# ls=[10,20,30]

# n,k = 1,1
# ls = [0]

# n,k=8,5
# ls=[-9,-7,-4,-3,1,2,3,4]
if not (0 in ls):
    ls.append(0)
    k+=1
#print (ls)

ls = np.array(ls)
ls.sort()
#print (ls)

idx = np.where(ls==0)[0][0]
#print (idx,k)
#print (idx+k)
start = max(0,idx-k)
goal = min(idx+k,len(ls)-1)

#print (start,goal)
answer = []
for i in range(goal-(k-1)+1):
    #print (i,i+k-1)
    mi = min(abs(ls[i]),abs(ls[i+k-1]))
    ma = max(abs(ls[i]),abs(ls[i+k-1]))
    #print (mi,ma)
    answer.append(2*mi+ma)
print (min(answer))
# def set_max(ls):
#     if len(ls)>0:
#         return set([max(ls)])
#     else:
#         return set()
# def set_min(ls):
#     if len(ls)>0:
#         return set([min(ls)])
#     else:
#         return set()
#
#
# plus = list(filter(lambda n:n>=0, ls))
# minus = list(filter(lambda n:n<=0, ls))
#
# neighbor = set_max(minus) | set_min(plus)
#
# #print (neighbor)
# answer = []
# cnt = 0
# for i in range(n-k+1):
#     if len(set(ls[i:i+k])&neighbor)>0:
#
#         #print (ls[i:i+k])
#         #print (np.sign(ls[i]*ls[i+k-1]))
#         temp = [abs(ls[i]),abs(ls[i+k-1])]
#         if np.sign(ls[i]*ls[i+k-1])<0:
#
#             answer.append(2*min(temp)+max(temp))
#         else:
#             answer.append(max(temp))
#         cnt += 1
#         if cnt == k + 1:
#             break
# print (min(answer))

# first = -1
# for i,point in enumerate(ls):
#     if point >= 0:
#         first = i
#         break
# size=k+1
# ans = []
# for i in range(size):
#     if first-size+i+1>=0 and first+i-1< len(ls):
#         temp = [0,ls[first-size+i+1],ls[first+i-1]]
#         temp = [abs(min(temp)),abs(max(temp))]
#         ans.append((2*min(temp)+max(temp)))
# print (min(ans))
### BUGGY CODE ###

import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if num[0]!=num[1] and any([x%num[1]!=0 for x in data[1::]])==True:
    count=int(num[1]/2)+1
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

### FIXED CODE ###

from fractions import gcd
import numpy as np
n=int(input())
data=list(map(int,input().split()))
left=np.zeros(n+1,dtype=np.int)
right=np.zeros(n+1,dtype=np.int)
kotae=1
for i in range(n):
    left[i+1]=gcd(left[i],data[i])
    right[n-i-1]=gcd(right[n-i],data[n-i-1])
for j in range(n):
    num=gcd(left[j],right[j+1])
    kotae=max(num,kotae)
print(kotae)
### BUGGY CODE ###

import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))

    A.sort()
    lenA = len(A)
    ans = 0

    if K == 1:
        print(0)
        sys.exit()

    def com(n, r, mod):
        r = min(r, n - r)
        if r == 0:
            return 1
        res = ilist[n] * iinvlist[n - r] * iinvlist[r] % mod
        return res

    ilist = [0]
    iinvlist = [1]

    def modinv(a, mod=10 ** 9 + 7):
        return pow(a, mod - 2, mod)

    tmp = 1
    for i in range(1, N + 1):
        tmp *= i
        tmp %= mod
        ilist.append(tmp)
        iinvlist.append(modinv(tmp, mod))

    for front in range(lenA):
        for last in range(lenA-front-K+1):
            last = last + front + K - 1
            f_x = A[last] - A[front]
            count = last - front - 1
            ans += com(count, K-2, mod) * f_x
    ans %= mod
    print(ans)

if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))

    A.sort()
    lenA = len(A)
    ans = 0

    if K == 1:
        print(0)
        sys.exit()

    def com(n, r, mod):
        r = min(r, n - r)
        if r == 0:
            return 1
        res = ilist[n] * iinvlist[n - r] * iinvlist[r] % mod
        return res

    def modinv(a, mod=10 ** 9 + 7):
        return pow(a, mod - 2, mod)

    ilist = [0]
    iinvlist = [1]
    tmp = 1
    for i in range(1, N + 1):
        tmp *= i
        tmp %= mod
        ilist.append(tmp)
        iinvlist.append(modinv(tmp, mod))

    sum_of_com = []
    now = 0

    for i in range(K-2, N+1):
        now += com(i, K-2, mod)
        sum_of_com.append(now)

    ans = 0
    for first in range(lenA-K+1):
        ans -= A[first] * sum_of_com[lenA-first-K]
    for last in range(K-1, lenA):
        ans += A[last] * sum_of_com[last-K+1]
    ans %= mod
    print(ans)

if __name__ == '__main__':
    solve()
### BUGGY CODE ###

import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

ans_list = [0] * (N+1)

dq = collections.deque()

dq.append(1)

print("Yes")
while 0 in ans_list[2:]:
    i = dq.popleft()
    iList = [temp for temp in ABs if i in temp]

    iList = list(itertools.chain.from_iterable(iList))
    iList = [temp for temp in iList if iList !=i]

    for hoge in iList:
        if(ans_list[hoge] == 0):
            ans_list[hoge] = i
        dq.append(hoge)

for ans in ans_list[2:]:
    print(ans)    



### FIXED CODE ###

import collections
import itertools
N, M = list(map(int, input().split()))
ABs = [list(map(int, input().split())) for _ in range(M)]

loads = [[] for _ in range(N+1)]

for AB in ABs:
    loads[AB[0]].append(AB[1])
    loads[AB[1]].append(AB[0])


dq = collections.deque()

dq.append(1)
ans_list = [0 for _ in range(N+1)]

#print(loads)
print("Yes")
while len(dq) != 0:
    i = dq.popleft()

    for vec in loads[i]:
#        print(vec)
        if(ans_list[vec] == 0):
            ans_list[vec] = i
            dq.append(vec)
#        print(ans_list)
#        print(dq)


for ans in ans_list[2:]:
    print(ans)
### BUGGY CODE ###

N, K = map(int, input().split(" "))
h_arr = list(map(int, input().split(" ")))
dp = [0]*N

for i in range(1, N):
	dp[i] = min(abs(h_arr[i]-h_arr[j]) + dp[j] for j in range(max(i-K, 0), i))
print(dp[-1])

### FIXED CODE ###

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]
s_set = list(set(s))
d = [None]*len(s_set)
for i in range(len(s_set)):
    d[i] = s.count(s_set[i])
maxn = max(d)
lst = [i for i, x in enumerate(d) if x == maxn]
ans = []
for i in lst:
    ans.append(s_set[i])
ans = sorted(ans)
print("\n".join(ans))

### FIXED CODE ###

import collections
n = int(input())
s = [input() for i in range(n)]
lst = collections.Counter(s)
max_val = max(lst.values())
keys_of_max_val = [key for key in lst if lst[key] == max_val]
print("\n".join(sorted(keys_of_max_val)))
### BUGGY CODE ###

from sys import stdin
input = stdin.readline

r, c, k = map(int, input().split())
vals = [[0]*c for _ in range(r)]
for _ in range(k):
    x, y, v = map(int, input().split())
    vals[x-1][y-1] = v
dp = [[[0]*4 for j in range(c)] for i in range(r)]
for i in range(r):
    for j in range(c):
        if vals[i][j] != 0:
            for k in range(3, 0, -1):
                if dp[i][j][k] < dp[i][j][k-1] + vals[i][j]:
                    dp[i][j][k] = dp[i][j][k-1] + vals[i][j]
        if i < r-1:
            tmp = 0
            for k in range(4):
                if tmp < dp[i][j][k]:
                    tmp = dp[i][j][k]
            dp[i+1][j][0] = tmp
        if j < c-1:
            for k in range(4):
                if dp[i][j+1][k] < dp[i][j][k]:
                    dp[i][j+1][k] = dp[i][j][k]
print(max(dp[r-1][c-1]))


### FIXED CODE ###

from sys import stdin
input = stdin.readline

r, c, k = map(int, input().split())
vals = [[0]*c for _ in range(r)]
for _ in range(k):
    x, y, v = map(int, input().split())
    vals[x-1][y-1] = v
dp = [[0]*4 for j in range(c)]
for j in range(c):
    if j > 0:
        for k in range(4):
            dp[j][k] = dp[j-1][k]
    if vals[0][j] > 0:
        for k in reversed(range(3)):
            if dp[j][k+1] < dp[j][k] + vals[0][j]:
                dp[j][k+1] = dp[j][k] + vals[0][j]
for i in range(1, r):
    tmp = [[max(dp[j]), 0, 0, 0] for j in range(c)]
    for j in range(c):
        if j > 0:
            for k in range(4):
                if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
        if vals[i][j] > 0:
            for k in reversed(range(3)):
                if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
    dp = tmp
print(max(dp[-1]))
### BUGGY CODE ###

from numba import jit

a=[]

@jit
def dp(a):
    aaset=set()
    while True:
        aaset.add(a[0])
        a2=[]
        for i,ai in enumerate(a,1):
            if ai%a[0]!=0:
                a2.append(ai)
        a=a2.copy()
        if len(a2)==0:
          break
    return aaset

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

a.sort()

import collections
c = collections.Counter(a)

d=[]
for ck,cv in c.items():
    if cv>=2:
       d.append(ck) 
dset=set(d)
    
aaset=dp(a)
aaset=aaset-dset    
print(len(aaset))


### FIXED CODE ###

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

a.sort()
amax=max(a)
dp=[True]*(amax+1)

import collections
c = collections.Counter(a)

d=[]
for ck,cv in c.items():
    if cv>=2:
       d.append(ck) 
dset=set(d)
    
aa=set()
for ai in a:
    if dp[ai]:
        aa.add(ai)
        for aj in range(ai*2,amax+1,ai):
            dp[aj]=False

aa=aa-dset    
print(len(aa))
### BUGGY CODE ###

n=list(map(int,input().strip().split()))
m=list(map(int,input().strip().split()))
a=[]
c=0
x=1
for i in range(0,n[1]):
  x*=m[i]
a.append(x)
#print(a)
l=0
k=n[1]
for i in range(0,n[0]-n[1]):
  x//=m[l]
  x*=m[k]
  a.append(x)
  #print(a)
  l+=1
  k+=1
for i in range(0,len(a)-1):
    if(a[i]<a[i+1]):
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n=list(map(int,input().strip().split()))
m=list(map(int,input().strip().split()))
for i in range(n[0]-n[1]):
    if(m[i+n[1]]>m[i]):
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
B = []
C = []
CB = []
for _ in range(M):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
    CB.append((c, b))
CB.sort()
for c, b in CB:
    for j in range(b):
        tmp = heapq.heappop(A)
        if tmp >= c:
            heapq.heappush(A, tmp)
            break
        else:
            heapq.heappush(A, c)
print(sum(A))


### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
B = []
C = []
CB = []
for _ in range(M):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
    CB.append((c, b))
CB.sort(reverse=True)
for c, b in CB:
    for j in range(b):
        tmp = heapq.heappop(A)
        if tmp >= c:
            heapq.heappush(A, tmp)
            break
        else:
            heapq.heappush(A, c)
print(sum(A))
### BUGGY CODE ###

n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()

for i in range(m):
  b, c = map(int, input().split())
  lp = l[:b]
  lp = [c if x < c else x for x in lp]
  l[:b] = lp
  l.sort()

print(sum(l))

### FIXED CODE ###

n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()

bc = [list(map(int, input().split())) for i in range(m)]
bc = sorted(bc, key=lambda x: x[1], reverse=True)
count = 0

for i in range(m):
  b, c = bc[i][0], bc[i][1]
  l += [c]*b
  count += b
  if count >= n:
    break

l.sort(reverse=True)
print(sum(l[:n]))
### BUGGY CODE ###

import numpy as np

n,m,Q= map(int, input().split())

a = np.zeros((n+1,n+1))

for i in range(m):
    l,r = map(int,input().split())
    a[r:,:l+1] += 1

for i in range(Q):
    p,q = map(int, input().split())
    print(int(a[q][p]))

### FIXED CODE ###

n,m,q = map(int, input().split())

a = [[0]*(n+1) for i in range(n+1)]

for i in range(m):
    l,r = map(int, input().split())
    a[l][r]+=1

b = [[0]*(n+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,n+1):
        b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+a[i][j]

for i in range(q):
    p,q = map(int, input() .split())
    ans = b[q][q]-b[p-1][q]-b[q][p-1]+b[p-1][p-1]
    print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
def main():
	c = 0
	k, s = map(int, input().split())
	#k, s = map(int, "2 2".split())
	for x in range(k + 1):
		for y in range(k + 1):
			for z in range(k + 1):
				if s == x + y + z:
					c += 1
	print(c)
	return

if __name__ == '__main__':
	main()


### FIXED CODE ###

K, S = map(int, input().split())
c = 0
for X in range(K + 1):
	for Y in range(K + 1):
		if S - K <= X + Y <= S:
			c += 1
print(c)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
D = {}
for i in A:
  if i in D:
    D[i] += 1
  else:
    D[i] = 1
for i in range(Q):
  s = 0
  bi, ci = map(int, input().split())
  if bi in D:
    if ci in D:
      D[ci] += D[bi]
    else:
      D[ci] = D[bi]
    del D[bi]
  for j in D:
    s += j * D[j]
  print(s)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
D = {}

for i in A:
  if i in D:
    D[i] += 1
  else:
    D[i] = 1
s = 0
for j in D:
  s += j * D[j]
for i in range(Q):
  bi, ci = map(int, input().split())
  if bi in D:
    if ci in D:
      D[ci] += D[bi]
    else:
      D[ci] = D[bi]
    s += (ci - bi) * D[bi]
    del D[bi]
  print(s)