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

import bisect
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
for i in range(m):
    b, c = [int(i) for i in input().split()]
    idx = bisect.bisect_left(a, c)
    a[idx:idx]=[c]*b
a = a[::-1]
print(sum(a[:n]))

### FIXED CODE ###

import bisect
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
d = []
cnt = 1
for i in range(n-1):
    if a[i+1] == a[i]:
        cnt += 1
    else:
        d.append([a[i], cnt])
        cnt = 1
d.append([a[n-1], cnt])


for i in range(m):
    b, c = [int(i) for i in input().split()]
    d.append([c, b])
d.sort(reverse=True)
ans = 0
j = 0
for i in range(n):
    if d[j][1] > 0:
        ans += d[j][0]
        d[j][1] -= 1
    if d[j][1] == 0:
        j += 1
print(ans)
### BUGGY CODE ###

n = int(input())
li = list(map(int,input().split()))
ans = 0

for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if li[i]<li[j]+li[k] and li[j]<li[k]+li[i] and li[k]<li[i]+li[j]:
                ans += 1

print(ans)

### FIXED CODE ###

from bisect import bisect_right

N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(N):
    for j in range(i):
        m = L[i]-L[j]
        k = bisect_right(L,m)
        n = max(0, j-k)
        ans += n

print(ans)
### BUGGY CODE ###

import copy

class UnionFind:
	def __init__(self, N):
		self._parent = [i for i in range(N)]
		self._rank = [0 for i in range(N)]

	def find(self, x):
		if self._parent[x] == x:
			return x
		else:
			return self.find(self._parent[x])

	def unite(self, a, b):
		ta = self.find(a)
		tb = self.find(b)
		if(ta == tb):
			return
		
		if self._rank[ta] < self._rank[tb]:
			self._parent[ta] = tb # make b as a parent of a
		else:
			self._parent[tb] = ta # make a as a parent of b
			if(ta == tb):
				rank[ta] += 1
			
	def check(self, a, b):
		return self.find(a) == self.find(b)
		
if __name__ == '__main__':
	N,K,L = map(int, input().split())
	uf1 = UnionFind(N)
	for _ in range(K):
		p,q = map(int, input().split())
		uf1.unite(p-1,q-1)
	uf2 = UnionFind(N)
	for _ in range(L):
		s,r = map(int, input().split())
		uf2.unite(s-1,r-1)
	from collections import defaultdict
	d = defaultdict(int)
	for i in range(N):
		d[(uf1.find(i), uf2.find(i))] += 1
	ans = []
	for i in range(N):
		ans.append( str(d[(uf1.find(i), uf2.find(i))]) )
	print(' '.join(ans))

### FIXED CODE ###

import copy

class UnionFind:
	def __init__(self, N):
		self._parent = [i for i in range(N)]

	def find(self, x):
		if self._parent[x] == x:
			return x
		else:
			return self.find(self._parent[x])

	def unite(self, a, b):
		ta = self.find(a)
		tb = self.find(b)
		if(ta != tb):
			self._parent[ta] = min(ta,tb)
			self._parent[tb] = self._parent[ta]
		
			
	def check(self, a, b):
		return self.find(a) == self.find(b)
		
if __name__ == '__main__':
	N,K,L = map(int, input().split())
	uf1 = UnionFind(N)
	for _ in range(K):
		p,q = map(int, input().split())
		uf1.unite(p-1,q-1)
	uf2 = UnionFind(N)
	for _ in range(L):
		s,r = map(int, input().split())
		uf2.unite(s-1,r-1)
	from collections import defaultdict
	d = defaultdict(int)
	for i in range(N):
		d[(uf1.find(i), uf2.find(i))] += 1
	ans = []
	for i in range(N):
		ans.append( str(d[(uf1.find(i), uf2.find(i))]) )
	print(' '.join(ans))
### BUGGY CODE ###

h, w = map(int, input().split())
s = [['#' for _ in range(w + 2)]]
s = s + [['#'] + list(input()) + ['#'] for _ in range(h)]
s = s + [['#' for _ in range(w + 2)]]
n_white = 0
for i in range(1, h + 1):
    n_white += s[i].count('.')
q = [[1, 1]]
a = []
d = 1
while(True):
    qq = []
    for i in range(len(q)):
        x = q[i][0]
        y = q[i][1]
        if s[x][y - 1] == '.' and [x, y - 1] not in a:
            qq.append([x, y - 1])
        if s[x - 1][y] == '.' and [x - 1, y] not in a:
            qq.append([x - 1, y])
        if s[x + 1][y] == '.' and [x + 1, y] not in a:
            qq.append([x + 1, y])
        if s[x][y + 1] == '.' and [x, y + 1] not in a:
            qq.append([x, y + 1])
    d += 1
    if [h, w] in qq:
        break
    elif qq == []:
        print(-1)
        exit()
    a = a + qq
    q = qq
print(n_white - d)

### FIXED CODE ###

h, w = map(int, input().split())
s = [['#' for _ in range(w + 2)]]
s = s + [['#'] + list(input()) + ['#'] for _ in range(h)]
s = s + [['#' for _ in range(w + 2)]]
n_white = 0
for i in range(1, h + 1):
    n_white += s[i].count('.')
q = [[1, 1]]
a = []
d = 1
while(True):
    qq = []
    for i in range(len(q)):
        if q[i] in a:
            continue
        x = q[i][0]
        y = q[i][1]
        if s[x][y - 1] == '.' and [x, y - 1] not in qq:
            qq.append([x, y - 1])
        if s[x - 1][y] == '.' and [x - 1, y] not in qq:
            qq.append([x - 1, y])
        if s[x + 1][y] == '.' and [x + 1, y] not in qq:
            qq.append([x + 1, y])
        if s[x][y + 1] == '.' and [x, y + 1] not in qq:
            qq.append([x, y + 1])
    d += 1
    if [h, w] in qq:
        break
    elif qq == []:
        print(-1)
        exit()
    a = a + q
    q = qq
print(n_white - d)
### BUGGY CODE ###

import math

X,K,D = map(int, input().split())
for i in range(K):
  if abs(X-D) < abs(X+D):
    X-=D
  else:
    X+=D
print(abs(X))

### FIXED CODE ###

X, K, D = map(int, input().split())
 
Xa = abs(X)
Xs = Xa // D
Xm = Xa % D
 
if (K <= Xs):
    print(abs(Xa-D*K))
elif (K-Xs) % 2 == 0:
    print(abs(Xm))
else:
    print(abs(D-Xm))
### BUGGY CODE ###

S = input()
S = S[::-1]
t = ['maerd','remaerd','esare','resare']
i = 0
frag = 0
while i <= len(S)-1 and frag == 0:
  k = 0
  for j in range(4):
    d = t[j]
    if S[i:len(d)+i] == d:
      break
      i = i + len(d)
    else:
      k = k + 1
      if k == 4:
        frag = 1
        print('NO')
if i == len(S):
  print('YES')

### FIXED CODE ###

S = input()
S = S[::-1]
t = ['maerd','remaerd','esare','resare']
i = 0
frag = 0
while i <= len(S)-1 and frag == 0:
  k = 0
  for j in range(4):
    d = t[j]
    if S[i:len(d)+i] == d:
      i = i + len(d)
    else:
      k = k + 1
      if k == 4:
        frag = 1
        print('NO')
if i == len(S):
  print('YES')
### BUGGY CODE ###

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


for gakki in range(k+1,n+1):
    pre = A[gakki-k-1:gakki-1]
    #pre_ = 1
    #for p in pre:
        #pre_ *= p

    
    k_gakki = A[gakki-k:gakki]
    #k_gakki_ = 1
    #for ga in k_gakki:
        #k_gakki_ *= ga
    
    #if pre_ < k_gakki_:
    if sum(pre)< sum(k_gakki):
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

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


for gakki in range(k+1,n+1):
    #pre = A[gakki-k-1:gakki-1]
    pre = A[gakki-k-1]
    #pre_ = 1
    #for p in pre:
        #pre_ *= p

    
    #k_gakki = A[gakki-k:gakki]
    k_gakki = A[gakki-1]
    #print(k_gakki)
    #k_gakki_ = 1
    #for ga in k_gakki:
        #k_gakki_ *= ga
    
    #if pre_ < k_gakki_:
    if pre < k_gakki:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

from sys import stdin
R, G, B, N = (int(i) for i in input().split())

count = 0
for i in range(N+1):
    for j in range(N+1):
        b = (N-i*R-j*G)/B
        if b.is_integer() and b >= 0:
            count +=1

print(count)


### FIXED CODE ###

from sys import stdin
R, G, B, N = (int(i) for i in input().split())

count = 0
for i in range(N+1):
    N1 = N - i*R
    for j in range(N1+1):
        b = (N1 - j*G)/B
        if b.is_integer() and b >= 0:
            count +=1

print(count)
### BUGGY CODE ###

import math
from itertools import permutations
import numpy as np
#from scipy.sparse import*
 
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    n=len(d[0])
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
 
N,M,R=[int(x) for x in input().split()]
r=[int(x)-1 for x in input().split()]
 
#route_list=[[10*9]*N for i in range(N)]
route_list = np.full((N,N),10**8,dtype=np.int)
 
 
for i in range(M):
    a,b,c=[int(x) for x in input().split()]
    route_list[a-1][b-1]=c
    route_list[b-1][a-1]=c
 
wa_list=warshall_floyd(route_list)
ans=10**9
 
for perm in permutations(r):
    #print(perm)
    cur = sum(wa_list[v][u] for v, u in zip(perm, perm[1:]))
    ans = min(ans, cur)
 
print(ans)

### FIXED CODE ###

import math
from itertools import permutations

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    n=len(d[0])
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

N,M,R=[int(x) for x in input().split()]
r=[int(x)-1 for x in input().split()]

route_list=[[10**9]*N for i in range(N)]

for i in range(M):
    a,b,c=[int(x) for x in input().split()]
    route_list[a-1][b-1]=c
    route_list[b-1][a-1]=c

wa_list=warshall_floyd(route_list)
ans=30**9

for perm in permutations(r):
    #print(perm)
    cur = sum(wa_list[v][u] for v, u in zip(perm, perm[1:]))
    ans = min(ans, cur)

print(ans)
### BUGGY CODE ###

# vim: fileencoding=utf-8


def main():
    n = int(input())
    li = list(map(int, input().split()))
    res = 0
    li.sort(reverse=True)
    tmp = [li[0]]
    for e in li[1:]:
        res += tmp[0]
        tmp = tmp[1:]
        tmp.append(e)
        tmp.append(e)
    print(res)


if __name__ == "__main__":
    main()


### FIXED CODE ###

# vim: fileencoding=utf-8


def main():
    n = int(input())
    li = list(map(int, input().split()))
    res = 0
    li = li + li
    li.sort()
    tmp = int(len(li) / 2)
    print(sum(li[-tmp:-1]))


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

N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N):
    B = set(A[0:i+1])
    if A[i] == min(B):
        count += 1
print(count)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
count = 0
min_number = A[0]
for i in range(N):
    if A[i] <= min_number:
        min_number = A[i]
        count += 1
print(count)
### BUGGY CODE ###

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

mod = 10 ** 9 + 7
com = [1]
table = [1]
inv_table = [1]
sums = 0

for i in range(1, n+1):
    table.append((table[i-1]*i) % mod)
    inv_table.append(pow(table[i], mod-2, mod))

for i in range(1,n+1):
    com.append((table[n] * inv_table[i] * inv_table[n-i]) % mod)

for i in range(1,n+1):
    if i == a or i == b:continue
    sums +=com[i]

print(sums % mod)

### FIXED CODE ###

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

mod = 10 ** 9 + 7
k = max(a,b)
com = [1]

for i in range(1,k+1):
    com.append((com[i-1]*(n-i+1)*pow(i,mod-2,mod))%mod)

print((pow(2,n,mod)-1-com[a]-com[b])%mod)
### BUGGY CODE ###

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

h.sort(reverse = True)
t = 0

while (k > 0) and len(h)>0:
    del h[0]
    k -= 1
if len(h) == 0 :
    print(0)
else:
    t += sum(h)
    print(t)    

### FIXED CODE ###

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

h.sort(reverse = True)
t = 0

del h[0:k]
    
if len(h) == 0 :
    print(0)
else:
    t += sum(h)
    print(t)
### BUGGY CODE ###

from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
dij = [(1, 0), (-1, 0), (0, 1), (0, -1)]

def main():
    n=II()
    s=SI()
    for w in range(n//2,0,-1):
        for i in range(n-w):
            t=s[i:i+w]
            if t in s[i+w:]:
                print(w)
                exit()
    print(0)

main()


### FIXED CODE ###

# YouTube
def main():
    n = int(input())
    s = input()
    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i, c in enumerate(s):
        for j in range(n):
            if c == s[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
    ans = 0
    for i in range(n):
        for j in range(i+1,n+1):
            tmp=min(dp[i][j],j-i)
            ans=max(tmp,ans)
    print(ans)

main()
### BUGGY CODE ###

import sys
from collections import deque
import copy
import heapq

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] =  [int(input_raw[0]), int(input_raw[1])]
    graph = {}
    for i in range(M):
        input_raw = read_func().strip().split()
        [a, b, c] =  [int(input_raw[0]), int(input_raw[1]), -long(input_raw[2])]
        if a not in graph:
            graph[a] = [(b, c)]
        else:
            graph[a].append((b, c))

    #dummy_inf = long(sys.maxint) * long(sys.maxint)
    dist_list =[long(sys.maxint) * long(sys.maxint) for i in range(N + 1)]
    dist_list[1] = 0L

    for i in range(0, 2 * N):
        for j in range(1, N + 1):
            if j not in graph:
                continue
            for edge in graph[j]:
                if dist_list[j] < long(sys.maxint) * long(sys.maxint):
                    new_cost = dist_list[j] + edge[1]
                    if new_cost < dist_list[edge[0]]:
                        dist_list[edge[0]] = new_cost
                        if (i >= N - 1 and edge[0] == N):
                            print "inf"
                            return
    print -dist_list[N]


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from collections import deque
import copy
import heapq

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] =  [int(input_raw[0]), int(input_raw[1])]
    graph = {}
    for i in range(M):
        input_raw = read_func().strip().split()
        [a, b, c] =  [int(input_raw[0]), int(input_raw[1]), -long(input_raw[2])]
        if a not in graph:
            graph[a] = [(b, c)]
        else:
            graph[a].append((b, c))

    dummy_inf = long(sys.maxint) * long(sys.maxint)
    dist_list =[dummy_inf for i in range(N + 1)]
    dist_list[1] = 0L

    for i in range(0, 2 * N):
        for j in range(1, N + 1):
            if j not in graph:
                continue
            for edge in graph[j]:
                if dist_list[j] < dummy_inf:
                    new_cost = dist_list[j] + edge[1]
                    if new_cost < dist_list[edge[0]]:
                        dist_list[edge[0]] = new_cost
                        if (i >= N - 1 and edge[0] == N):
                            print "inf"
                            return
    print -dist_list[N]


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

input()
da = list(map(int,input().split()))
al = 0
ta = [0]*len(da)
for i in range(len(da)):
  for j in range(len(da)-i):
    if j == 0:
      ta[0] = da[i]
    else:
      ta[j] = ta[j-1] + da[i+j]
    if ta[j] == 0:
      al += 1
print(al)

### FIXED CODE ###

from collections import defaultdict
 
n = int(input())
a = [int(i) for i in input().split()]
 
s = 0
d = defaultdict(int)
ans = 0
d[0] = 1
 
for i in a:
    s += i
    ans += d[s]
    d[s] += 1
 
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]
print(*b)

### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = deque([a[0]])
for i in range(1, n):
    if i % 2 == 1:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if n % 2 == 1:
    print(* list(b))
else:
    print(* list(b)[::-1])
### BUGGY CODE ###

n = int(input())
word = [input() for i in range(n)]
test = list([x,0] for x in set(word))

for i, num in enumerate(test):
  test[i][1] = word.count(num[0])

num_max = int(max(test, key=lambda x: x[1])[1])

print('\n'.join(sorted([num[0] for num in test if int(num[1]) == num_max])))


### FIXED CODE ###

from collections import Counter
n = int(input())
word = Counter([input() for i in range(n)]).most_common()
print('\n'.join(sorted([num[0] for num in word if int(num[1]) == word[0][1]])))
### BUGGY CODE ###

n = int(input())
s = input()
ans = float("inf")
for i in range(n):
    move = 0
    move += s[:i].count("W")
    move += s[i + 1:].count("E")
    ans = min(ans, move)
print(ans)

### FIXED CODE ###

n = int(input())
s = list(input())
for i in range(n):
    if i:
        s[i] = s[i - 1] + int(s[i] == "E")
    else:
        s[i] = int(s[i] == "E")
s.append(s[n - 1])
ans = float("inf")
for i in range(n):
    rightE = s[n] - s[i]
    if i == 0:
        ans = min(ans, rightE)
    else:
        leftW = i - s[i - 1]
        ans = min(ans, leftW + rightE)
print(ans)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

for i in range(n):
    tmp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = tmp

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

max_ = -1
max_2 = -1
for i in range(n):
    if i == 0:
        tmp = a[i]
        a[i] = 0
        max_ = max(a)
        print(max_)
        a[i] = tmp
        if a[0]>=max_:
            max_ = a[0]
        continue
    else:
        if max_<=a[i]:
            if max_2 == -1:
                tmp = a[i]
                a[i] = 0
                max_2 = max(a)
                print(max_2)
                a[i] = tmp
            else:
                print(max_2)
        else:
            print(max_)
### BUGGY CODE ###

import itertools

def checkXOR(a, b, c):
  if bin(b) == bin(a ^ c):
    return False
  else:
    return True
    
n = int(input())
a = list(map(int, input().split()))
ff = False
for p in list(itertools.permutations(a)):
  for i in range(0, n):
    if i == 0:
      ff = checkXOR(p[n-1],p[i],p[i+1])
    elif i == n-1:
      ff = checkXOR(p[i-1],p[i],p[0])
    else:
      ff = checkXOR(p[i-1],p[i],p[i+1])
    if ff:
      break
  if ff:
    break

if ff:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

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

for i in range(n):
  aa = aa ^ a[i]

if aa == 0:
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
for i in range(1,N+1):
  print(A.count(i))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
for i in A:
  B[i]+=1
for j in range(1,N+1):
  print(B[j])
### BUGGY CODE ###

N,M = map(int,input().split())
L = [0]*M
R = [0]*M

for i in range(M):
    L[i],R[i] = map(int,input().split())
    

d={}

for i in range(M):
    l = L[i]
    r=R[i]
    
    for j in range(l,r+1):
        
        if j in d:
            d[j] += 1
        else:
            d[j] = 1
    
cnt = 0
for i in d.values():
    if i >=M:
        cnt+=1
        
print(cnt)
    

### FIXED CODE ###

N,M = map(int,input().split())
L = [0]*M
R = [0]*M

for i in range(M):
    L[i],R[i] = map(int,input().split())
    
L.sort()
R.sort()

l= L[len(L)-1]
r = R[0]

cnt =0 

for i in range(l,r+1):
    cnt+=1

print(cnt)
### BUGGY CODE ###

from queue import Queue
N, M, K = map(int, input().split())
F = [set([]) for _ in range(N+1)]
B = [set([]) for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    F[a].add(b)
    F[b].add(a)

for _ in range(K):
    c, d = map(int, input().split())
    B[c].add(d)
    B[d].add(c)

checked = [False] * (N+1)
checked[0] = True
ans = ['0'] * (N+1)
for v in range(1, N+1):
    if checked[v]:
        continue
    A = []
    q = Queue()
    for u in F[v]:
        q.put(u)

    while not q.empty():
        u = q.get()
        if not checked[u]:
            A.append(u)
            for w in F[u]:
                q.put(w)
            checked[u] = True
    
    for a in A:
        ans[a] = str(len(set(A) - set(B[a]) - set(F[a]) - set([a])))
    
    checked[v] = True

print(' '.join(ans[1:]))

### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, v):
        if self.parents[v] < 0:
            return v
        else:
            self.parents[v] = self.find(self.parents[v])
            return self.parents[v]

    def unite(self, u, v):
        u = self.find(u)
        v = self.find(v)

        if u == v:
            return

        if self.parents[u] > self.parents[v]:
            u, v = v, u

        self.parents[u] += self.parents[v]
        self.parents[v] = u

    def size(self, v):
        return -self.parents[self.find(v)]

    def same(self, u, v):
        return self.find(u) == self.find(v)

N, M, K = map(int, input().split())
uf = UnionFind(N+1)
F = [0] * (N+1)
B = [0] * (N+1)
for _ in range(M):
    a, b = map(int, input().split())
    uf.unite(a, b)
    F[a] += 1
    F[b] += 1

for _ in range(K):
    c, d = map(int, input().split())
    if uf.same(c, d):
        B[c] += 1
        B[d] += 1

for i in range(1, N+1):
    ans = uf.size(i) - F[i] - B[i] - 1
    print(ans, end=' ')

print()
### BUGGY CODE ###

N=int(input())

d = {}
for i in range(N):
  s = input()
  if s in d:
    d[s] += 1
  else:
    d[s]  = 1

d_ =[k for k, v in d.items() if v == max(d.values())]
d_.sort()
for st in d_:
  print(st)

### FIXED CODE ###

from collections import defaultdict
import collections
N=int(input())
ss = []
for i in range(N):
  ss.append(input())
#d = defaultdict(lambda: 0)
c = collections.Counter(ss)
d_=c.most_common()
mx = d_[0][1]
d_.sort()
#print(d_)
m=len(d_)
for i in range(m):
  if d_[i][1] == mx:
    print(d_[i][0])
  else:
    pass
### BUGGY CODE ###

def main():
    N=int(input())
    A=[int(x) for x in input().split()]
    Q=int(input())
    ans=[]
    for _ in range(Q):
        B,C=map(int, input().split())
        A=[C if x==B else x for x in A]
        ans.append(str(sum(A)))
    print('\n'.join(ans))
    return

if __name__=='__main__':
    main()


### FIXED CODE ###

def main():
    N=int(input())
    l=[0]*10**5
    sm=0
    A=map(int, input().split())
    for a in A:
        l[a-1]+=1
        sm+=a
    Q=int(input())
    BC=[list(map(int,input().split())) for _ in range(Q)]
    for bc in BC:
        cnt=l[bc[0]-1]
        l[bc[0]-1]=0
        l[bc[1]-1]+=cnt
        sm=sm-bc[0]*cnt+bc[1]*cnt
        print(sm)
    return

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

import math


def combinations_count(n, r, d):
    if d.get((n, r)):
        return d[(n, r)]
    else:
        x = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        d[(n, r)] = x
    return x

d=dict()
n, k = map(int, input().split())
A = sorted(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
for i, Ma in enumerate(A[::-1]):
    i = n - i
    for j, ma in enumerate(A):
        if ma == Ma or i - j < k:
            break
        ans += (combinations_count(i - j - 2, k - 2,d) * (Ma - ma)) % mod
        ans %= mod
print(ans)

### FIXED CODE ###

from functools import lru_cache
n, k = map(int, input().split())
A = sorted(map(int, input().split()))
mod = 10 ** 9 + 7
# 階乗とその逆元の計算
factrial = [0 for _ in range(n + 1)]
factrial[0] = 1
for i in range(1, n + 1):
    factrial[i] = (factrial[i - 1] * i) % mod
inverse_factrial = list()
for f in factrial:
    inverse_factrial.append(pow(f, -1, mod))


@lru_cache(maxsize=None)
def nCr(n, r):
    return (factrial[n] * inverse_factrial[r] * inverse_factrial[n - r]) % mod


ans = 0
# 最大値の和
for i, a in enumerate(A[k - 1:], k - 1):
    ans += ((a % mod) * nCr(i, k-1)) % mod
    ans %= mod
# 最小値の和
A.reverse()
for i, a in enumerate(A[k - 1:], k - 1):
    ans -= ((a % mod) * nCr(i, k-1)) % mod
    ans %= mod
print(ans)