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

#ABC126D-EvenRelation.py

import sys
import numpy as np

def main():
    N = int(sys.stdin.readline())
    UVW = [list(map(int, sys.stdin.readline().split())) for _ in range(N-1)]
    distanceList = [0] + [-1]*(N-1)

    while True:
        s = len(UVW)
        if s == 0:
            break
        for i in range(s):
            u, v, w = UVW[i]
            if distanceList[u-1] != -1:
                if distanceList[v-1] == -1:
                    distanceList[v-1] = w + distanceList[u-1]
                UVW.pop(i)
                break
            elif distanceList[v-1] != -1:
                if distanceList[u-1] == -1:
                    distanceList[u-1] = w + distanceList[v-1]
                UVW.pop(i)
                break

    for d in distanceList:
        if d % 2 == 0:
            print(0)
        else:
            print(1)



if __name__ == "__main__":
    main()


### FIXED CODE ###

#ABC126D-EvenRelation.py

import sys
import collections
import numpy as np

def main():
    N = int(sys.stdin.readline())
    UVW = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = list(map(int, sys.stdin.readline().split()))
        UVW[u-1].append([v,w])
        UVW[v-1].append([u,w])
    answerList = [0] + [-1]*(N-1)
    edge = collections.deque([(1,0)])

    while edge:
        u, w1 = edge.pop()
        for v, w2 in UVW[u-1]:
            if answerList[v-1] == -1:
                answerList[v-1] = (w1 + w2) % 2
                edge.append((v,w1+w2))

    for answer in answerList:
        print(answer)



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

import sys
import heapq
def v():
    N,T=tuple(map(int,sys.stdin.readline().split()))
    A=list(map(int,sys.stdin.readline().split()))
    d=[]
    for i,a in enumerate(A[:-1]):
        b=max(A[i+1:])
        c=b-a if b>a else 0
        d.append(-c)
    heapq.heapify(d)
    res,x=1,heapq.heappop(d)
    while len(d)>0:
        y=heapq.heappop(d)
        if x==y:res+=1
    print(res)
if __name__=='__main__':v()

### FIXED CODE ###

import sys
import heapq
def v():
    N,T=tuple(map(int,sys.stdin.readline().split()))
    A=list(map(int,sys.stdin.readline().split()))
    ma=0
    d=[]
    heapq.heapify(d)
    for a in reversed(A):
        if a<ma:heapq.heappush(d,a-ma)
        else:ma=a
    res,x=1,heapq.heappop(d)
    while len(d)>0:
        y=heapq.heappop(d)
        if x==y:res+=1
    print(res)
if __name__=='__main__':v()
### BUGGY CODE ###

from sys import exit
N,Q = [int(n) for n in input().split()]
# a = [int(input()) for _ in range(N)]
S = str(input())
L = len(S)
dic ={'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6,
 'H': 7, 'I': 8, 'J': 9, 'K': 10,'L': 11, 'M': 12, 'N': 13, 'O': 14,
  'P': 15, 'Q': 16, 'R': 17, 'S': 18,'T': 19, 'U': 20, 'V': 21,
   'W': 22, 'X': 23, 'Y': 24, 'Z': 25}
adj = [set() for _ in range(26)]
gorem = [1 for _ in range(N)]
goremap = dict(enumerate(gorem))
# print(goremap)
ap = set()
for i in range(L):
    adj[dic[S[i]]].add(i)
# print(adj)
INF = 10**9
ans = N

for i in range(Q):
    #t == 文字、D = {L,R}
    t,d = [str(n) for n in input().split()]
    if d == "L":
        # print(adj[dic[t]])
        for mass in adj[dic[t]]:#その支持のマス
            gon = gorem[mass]
            gorem[mass]-=gon
            if mass == 0 :
                ans-=gon
                # print("die")
            else:
                gorem[mass-1]+=gon
    else:
        # print(adj[dic[t]])
        for mass in adj[dic[t]]:#その支持のマス
            gon = gorem[mass]
            gorem[mass]-=gon
            if mass == L-1:
                ans-=gon
                # print("die")
            else:
                gorem[mass+1]+=gon
    # print(gorem)

# print(adj)
print(ans)
# T = str(input())
# exit()


### FIXED CODE ###

n, q = [int(_) for _ in input().split()]
s = input()

Q = [(input().split()) for i in range(q)]
Q.reverse()
l = 0
r = n - 1
for t,d in Q:
    if s[l] == t and d == "L":
        l += 1
    elif l > 0 and s[l - 1] == t and d == "R":
        l -= 1
    if s[r] == t and d == "R":
        r -= 1
    elif r < n - 1 and s[r + 1] == t and d == "L":
        r += 1
    # print(r,l,r-l+1)
    if l > r:
        break
print(r - l + 1)
### BUGGY CODE ###

n = int(input())
x = int(input(),2)

def popcount(n):
    return bin(n).count("1")

pops = popcount(x)
x_pop_p = x%(pops + 1)
try:
    x_pop_m = x%(pops - 1)
except:
    x_pop_m = 0
#print(x_pop_p)
#print(x_pop_m)
#print()
for i in reversed(range(0,n)):
    bit = x^(1<<i)
    #print(bin(bit))
    #print(bit)
    #print(popcount(bit))
    if bit == 0:
        print(0)
        continue
    if x&(1<<i):
        tmp = (x_pop_m - 2**i)%(pops - 1)
    else:
        tmp = (x_pop_p + 2 ** i) % (pops + 1)
    #print(tmp)
    if tmp == 0:
        print(1)
        continue
    cnt = 2
    tmp_pop = popcount(tmp)
    if tmp_pop == 0:
        print(cnt-1)
        continue
    tmp = tmp % tmp_pop
    while tmp > 0:
        cnt += 1
        tmp_pop = popcount(tmp)
        if tmp_pop == 0:
            print(cnt-1)
            continue
        tmp %= tmp_pop
    print(cnt)
    #print()

### FIXED CODE ###

n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)
### BUGGY CODE ###

H, W = map(int, input().split())
T = [[] for i in range(H)]
d = []
for i in range(H):
    a = list(input())
    T[i] = a
    for j in range(W):
        if a[j] == '#':
            d.append((i, j, 0))

ma = 0
while len(d) > 0:
    x, y, k = d.pop(0)
    ma = max(ma, k)
    for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
        nx, ny = x + dx, y + dy
        if 0 <= nx < H and 0 <= ny < W and T[nx][ny] == '.':
            T[nx][ny] = '#'
            d.append((nx, ny, k + 1))

print(ma)


### FIXED CODE ###

import sys
H, W = map(int, sys.stdin.readline().split())
INF = float('inf')
S = [[INF] * W for i in range(H)]
for i in range(H):
    a = list(sys.stdin.readline())
    for j in range(W):
        if a[j] == '#':
            S[i][j] = 0

ma = 0
for i in range(1, H):
    for j in range(W):
        S[i][j] = min(S[i][j], S[i - 1][j] + 1)

for i in range(H - 2, -1, -1):
    for j in range(W):
        S[i][j] = min(S[i][j], S[i + 1][j] + 1)

for i in range(H):
    for j in range(1, W):
        S[i][j] = min(S[i][j], S[i][j - 1] + 1)

for i in range(H):
    for j in range(W - 2, -1, -1):
        S[i][j] = min(S[i][j], S[i][j + 1] + 1)

for i in range(H):
    for j in range(W):
        ma = max(ma, S[i][j])

print(ma)
### BUGGY CODE ###

import bisect
while True:
    n,S = map(int, raw_input().split())
    if n == 0 and S == 0:
        break
    r = []
    for i in range(n):
        r.append(input())
    ans = 0
    r.sort()
    for i in range(n):
        tmp = S - r[i] + 1
        if (tmp <= 0):
            ans += n - 1
        else:
            d = r[0:i] + r[i + 1:]
            index = bisect.bisect_right(d, tmp)
            ans += index
    print ans / 2

### FIXED CODE ###

import bisect
while True:
    n,S = map(int, raw_input().split())
    if n == 0 and S == 0:
        break
    r = [input() for i in range(n)]
    ans = 0
    r.sort()
    for i in range(n):
        tmp = S - r[i] + 1
        if (tmp <= 0):
            ans += n - 1
        else:
            index = bisect.bisect_left(r, tmp)
            if (index <= i):
                ans += n - index - 1
            else:
                ans += n - index
    print ans / 2
### BUGGY CODE ###

from collections import deque
H, W, M = map(int, input().split())
grid = [[0 for _ in range(W)] for _ in range(H)]
counth = deque([0 for k in range(H)])
countw = deque([0 for k in range(W)])
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  grid[h][w] = 1
  counth[h] += 1 
  countw[w] += 1

maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = deque([])
k = 0
while len(counth) > 0:
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
  k += 1
k = 0
while len(countw) > 0:
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)
  k += 1
ans = maxh + maxw - 1
if len(index_h)*len(index_w) > M:
  ans += 1
else:  
  while len(index_h) > 0:
    h = index_h.pop()
    while len(index_w) > 0:
      w = index_w.pop()
      if grid[h][w] == 0:
        ans += 1
        break
    else:
      continue
    break
print(ans)


### FIXED CODE ###

from collections import deque
H, W, M = map(int, input().split())
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1
counth = deque(counth)
countw = deque(countw)

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            #return mid
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    #return None
    return False


maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)

for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)

ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)


if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  for K in kouho:
    if binary_search(bomb, K):
      continue
    else:
      ans += 1
      break
    
print(ans)
### BUGGY CODE ###

import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD=10**9+7
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
if n==1:
  print(1)
  exit()
if 1 in a and 2 in a:
  print(0)
  exit()
elif 1 in a:
  ans=[0,0,1]
elif 2 in a:
  ans=[0,1,0]
else:
  ans=[0,1,2]

@lru_cache(maxsize=None)
def cnt(x):
  if x<3:
    return ans[x]
  if x in a:
    return 0
  else:
    return (cnt(x-1)+cnt(x-2))%MOD

print(cnt(n))

### FIXED CODE ###

N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
a.sort(reverse=True)

if 1 in a:
  a.pop()
  fibs = [1,0]
else:
  fibs = [1,1]

for i in range(2,N+1):
  if len(a) > 0 and i == a[-1]:
    a.pop()
    fibs[0] = fibs[1]
    fibs[1] = 0
  else:
    next = fibs[1] + fibs[0]
    if next > 1000000007:
      next -= 1000000007
    fibs[0] = fibs[1]
    fibs[1] = next

print(fibs[-1])
### BUGGY CODE ###

from collections import defaultdict
from copy import copy
n = int(input())
a = list(map(int, input().split()))

ok, ng = n, 0
while ok-ng > 1:
	x = (ok+ng)//2
	d = defaultdict(int)
	last = 0
	valid = True
	if x == 1:
		for i in range(n-1):
			if a[i] >= a[i+1]:
				valid = False
				break
		if valid:
			ok = x
		else:
			ng = x
		continue

	for i in range(n-1):
		if a[i] > a[i+1]:
			if a[i+1] > last:
				d[a[i+1]] = 1
			else:
				j = a[i+1]
				while d[j] == x-1 and j > 0:
					d[j] = 0
					j -= 1
				d[j] += 1
			last = a[i+1]
			e = copy(d)
			for k in d.keys():
				if k > last:
					e.pop(k)
			d = copy(e)
		elif a[i] == a[i+1]:
			j = a[i+1]
			while d[j] == x-1 and j > 0:
				d[j] = 0
				j -= 1
			d[j] += 1
			last = a[i+1]

		if d[0] > 0:
			valid = False
			break

	if valid:
		ok = x
	else:
		ng = x
print(ok)

### FIXED CODE ###

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

ok, ng = n, 0
while ok-ng > 1:
	x = (ok+ng)//2
	#d = defaultdict(int)
	d = dict()
	last = 0
	valid = True
	if x == 1:
		for i in range(n-1):
			if a[i] >= a[i+1]:
				valid = False
				break
		if valid:
			ok = x
		else:
			ng = x
		continue

	for i in range(n-1):
		dels = []
		if a[i] < a[i+1]:
			last = a[i+1]
			continue

		j = a[i+1]
		for k in d.keys():
			if j < k:
				dels.append(k)

		while j > 0:
			if j in d and d[j] == x-1:
				#d[j] = 0
				dels.append(j)
				j -= 1
			else:
				break

		if j in d:
			d[j] += 1
		else:
			d[j] = 1

		for k in dels:
			del d[k]

		if 0 in d:
			valid = False
			break
		last = j

	if valid:
		ok = x
	else:
		ng = x
print(ok)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

div = 1000000007

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

f = [0] * (n + 1)
f[0] = 1

if 1 not in a:
    f[1] = 1

for i in range(2, n + 1):
    if i in a:
        continue
    f[i] = (f[i - 1] + f[i - 2]) % div

print(f[-1])


### FIXED CODE ###

def main():
    N, M, *a = map(int, open(0).read().split())
    div = 1000000007
    broken = set(a)
 
    comb_list = [0] * (N + 1)
    comb_list[0] = 1
    if 1 not in broken:
        comb_list[1] = 1
 
    for i in range(2, N + 1):
        if i in broken:
            continue
        comb_list[i] = (comb_list[i - 1] + comb_list[i - 2]) % div
 
    print(comb_list[-1])
 
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

a = input()

ans = [a]

for i in range(len(a)):
    for j in range(i, len(a)):
        rev = a[0:i] + a[j:i:-1] + a[i] + a[j+1:]
        if rev not in ans:
            ans.append(rev)

print(len(ans))


### FIXED CODE ###

a = input()
total = 1 + (len(a) * (len(a) - 1) // 2)
trash = 0

for i in range(97, 97 + 26):
    atoz = (a.count(chr(i)) * (a.count(chr(i)) - 1)) // 2
    trash += atoz

print(total - trash)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = []
for i in range(q):
    bc.append(list(map(int, input().split())))

for i in range(q):
    a = [bc[i][1] if bc[i][0] == j else j for j in a]
    print(sum(a))



### FIXED CODE ###

n = int(input())
a_series = list(map(int, input().split()))
q = int(input())
bc = []
for i in range(q):
    bc.append(list(map(int, input().split())))

summed = sum(a_series)
num = [0 for i in range(100005)]

for a in a_series:
    num[a] += 1

for i in range(q):
    summed += ((bc[i][1] - bc[i][0]) * num[bc[i][0]])
    num[bc[i][1]] += num[bc[i][0]]
    num[bc[i][0]] = 0
    print(summed)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import numpy as np
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
BC = [[int(x) for x in input().split()] for _ in range(M)]
A = np.array(sorted(A),np.int64)
BC = sorted(BC,reverse=True,key=lambda x:x[1])
for i in BC:
    B,C = i
    for j in range(B):
        if A[j] < C:
            A[j] = C
        else:
            break
    A.sort()
print(A.sum())

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
BC = [[int(x) for x in input().split()] for _ in range(M)]
BC = sorted(BC, reverse = True, key = lambda x:x[1])
N2 = N
D = []
for i in BC:
    temp = min(N2,i[0])
    D += [i[1]] * temp
    N2 -= temp
    if not N2:
        break
A += D
A.sort()
print(sum(A[len(A) - N:]))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M, L = map(int,input().split())
rd = [[] for _ in range(N+1)]
rc = [[] for _ in range(N+1)]

ZO = [[-1 for i in range(N+1)] for i in range(N+1)]
NP = [[10**9+1 for i in range(N+1)] for i in range(N+1)]

for _ in range(M):
    a,b,c = map(int,input().split())
    if c <= L:
        rd[a].append(b)
        rc[a].append(c)
        rd[b].append(a)
        rc[b].append(c)
        NP[a][b] = 0
        NP[b][a] = 0
        ZO[a][b] = L - c
        ZO[b][a] = L - c

Q = int(input())
S = []
T = []
for _ in range(Q):
    s,t = map(int,input().split())
    S.append(s)
    T.append(t)

for i in range(1,N+1):
    up = True
    while up:
        up = False
        for j in range(1,N+1):
            if ZO[i][j] < 0: continue
            for d,c in zip(rd[j], rc[j]):
                if d == i: continue
                if ZO[i][j] < c:
                    nnp = NP[i][j] + 1
                    nzo = L - c
                else:
                    nnp = NP[i][j]
                    nzo = ZO[i][j] - c
                if NP[i][d] > nnp or NP[i][d] == nnp and ZO[i][d] < nzo:
                    ZO[i][d] = nzo
                    NP[i][d] = nnp
                    up = True

for i in range(Q):
    if NP[S[i]][T[i]] > 10**9:
        print (-1)
    else:
        print(NP[S[i]][T[i]])

### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq


def wf(d,n):
    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

def main():
    INF = 10**18
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,M,L = LI()
    road = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a,b,c = LI()
        if c <= L:
            road[a-1][b-1] = c
            road[b-1][a-1] = c

    road = wf(road,N)


    gas = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if road[i][j] <= L:
                gas[i][j] = 1

    gas = wf(gas,N)

    Q = NI()
    for _ in range(Q):
        s,t = LI()
        if gas[s-1][t-1] == INF:
            print(-1)
        else:
            print(gas[s-1][t-1]-1)


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

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(0,M):
    A[N-1]=int(A[N-1]/2)
    A.sort()
count=0

print(sum(A))

### FIXED CODE ###

import heapq
N, M = map(int, input().split())
A = list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(A)
for i in range(0,M):
    a=heapq.heappop(A)
    heapq.heappush(A,(-1)*(-a//2))
print(-sum(A))

#　優先度付きキューが難しい
### BUGGY CODE ###

import math
N = int(input())

def minus_2(n):
    ans = ''
    if n == 1:
        ans += '1'
    else:
        for i in range(10**9):
            if n % 2 == 0:
                ans += '0'
            else:
                ans += '1'
            n = math.ceil(n/-2)
            if n == 1:
                break
        ans += '1'
        ans = ans[::-1]
        
    return ans

print(minus_2(N))

### FIXED CODE ###

import math
N = int(input())
 
def minus_2(n):
    ans = ''
    if n == 1:
        ans += '1'
    elif n == 0:
        ans += '0'
    else:
        while n != 1:
            if n % 2 == 0:
                ans += '0'
            else:
                ans += '1'
            n = math.ceil(n/-2)
        ans += '1'
        ans = ans[::-1]
        
    return ans
 
print(minus_2(N))
### BUGGY CODE ###

import copy
N = int(input())
X = list(map(int, input().split()))

for i in range(N):
    tmp = copy.deepcopy(X)
    tmp.pop(i)
    tmp.sort()
    if len(tmp)%2 == 0:
        print(tmp[len(tmp)//2-1])
    else:
        print(tmp[(len(tmp)+1)//2-1])


### FIXED CODE ###

import copy
N = int(input())
X = list(map(int, input().split()))
tmp = copy.deepcopy(X)
tmp.sort()

a = tmp[int(len(tmp)/2)-1]
b = tmp[int(len(tmp)/2)]

for i in X:
    print(b if i<(a+b)/2 else a)
### BUGGY CODE ###

from collections import deque

def search(now):   #今いる頂点からけんけんぱでいける点を列挙する
    ret = []
    for v in edge[now]:
        for v2 in edge[v]:
            ret += edge[v2]
    return list(set(ret))

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
    u, v = map(int,input().split())
    edge[u-1].append(v-1)
S,T = map(int,input().split())
S -=1
T -=1

edge2 = [search(u) for u in range(N)]

distance = [10**9 for _ in range(N)]
distance[S] = 0

queue = deque([S])
while queue:
    u = queue.popleft()
    for next in edge2[u]:
        if distance[u]+1 < distance[next]:
            distance[next] = distance[u]+1
            queue.append(next)
if distance[T] < 10**9:
    print(distance[T])
else:
    print(-1)

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
edge = [[] for _ in range(3*N)]
for i in range(M):
    u, v = map(int,input().split())
    for i in range(3):
        edge[i*N + u-1].append(((i+1)%3)*N + (v-1))
S,T = map(int,input().split())
S -=1
T -=1

distance = [10**9 for _ in range(3*N)]
distance[S] = 0

queue = deque([S])
while queue:
    u = queue.popleft()
    for next in edge[u]:
        if distance[u]+1 < distance[next]:
            distance[next] = distance[u]+1
            queue.append(next)
if distance[T] < 10**9:
    print(distance[T]//3)
else:
    print(-1)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc =[list(map(int, input().split())) for _ in range(q)]
temp = [0] * (10**5 + 1)

for i in a:
    temp[i] += i

for i in range(q):
    b,c = bc[i][0],bc[i][1]
    temp[c] += (temp[b]//b) * c
    temp[b] = 0
    print(sum(temp))


### FIXED CODE ###


  
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    bc =[list(map(int, input().split())) for _ in range(q)]
    temp = [0] * (10**5 + 1)
    
    for i in a:
        temp[i] += 1
    ans = sum(a)
    for i in range(q):
        b,c = bc[i][0],bc[i][1]
        ans = ans - temp[b] * b + temp[b] * c 
        print(ans)
        temp[c] += temp[b]
        temp[b] = 0
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

isDiff = True
cache = [0] * n 

for i in range(n) :

    for j in range(n) :
        if i == j :
            continue

        if cache[j] == -1 :
            continue

        if a[i] == a[j] :
            isDiff = False
            break

    cache[i] = -1


if isDiff :
    print('YES')
else :
    print('NO')


### FIXED CODE ###

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

aa = set(a)

if len(a) == len(aa) :
    print('YES')
else :
    print('NO')
### BUGGY CODE ###

n,m=map(int,input().split())
*q, = map(int,input().split())
#print(q)
l = []
for _ in range(m):
  b,c = map(int,input().split())
  for i in range(b):
    l.append(c)
li = sorted(q+l,reverse=True)
#print(li)

ans = 0
for i in range(len(q)):
  ans += li[i]
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
*q, = map(int,input().split())
#print(q)
l = [list(map(int,input().split())) for _ in range(m)]
l.sort(key=lambda x:x[1], reverse=True)
#print(l)
for b,c in l:
  q.extend([c]*b)
  if len(q) > n*2:
    break

print(sum(sorted(q,reverse=True)[:n]))
### BUGGY CODE ###

n,m=map(int,input().split())#n:num m:ticket
a=[int(_) for _ in input().split()]
for i in range(m):
	a[a.index(max(a))]=max(a)//2
print(sum(a))

### FIXED CODE ###

from heapq import heapify,heappop,heappush
n,m=map(int,input().split())#n:num m:ticket
a=[-int(_) for _ in input().split()]
heapify(a)
for i in range(m):
	num=heappop(a)*-1
	heappush(a,(num//2)*-1)
print(sum(a)*-1)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10**9)
N, Q = map(int, input().split())
connections = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    pa, ki = map(int, input().split())
    connections[pa].append(ki)
    connections[ki].append(pa)

scores = [0 for _ in range(N + 1)]
for _ in range(Q):
    tag, p = map(int, input().split())
    scores[tag] += p

i = 1
fins = []

def dfs(k=1):
    global scores
    global fins
    if k in fins:
        return
    fins.append(k)
    kids = connections[k]
    if not kids:
        return
    for kid in kids:
        if kid in fins:
            continue
        scores[kid]+=scores[k]
        dfs(kid)


dfs()



print(*scores[1:])

### FIXED CODE ###

import sys

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

N, Q = map(int, input().split())
connections = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    pa, ki = map(int, input().split())
    connections[pa].append(ki)
    connections[ki].append(pa)

scores = [0 for _ in range(N + 1)]
for _ in range(Q):
    tag, p = map(int, input().split())
    scores[tag] += p

i = 1

def dfs(k=1,bef=-1):
    global scores
    global fins
    kids = connections[k]
    if len(kids)==1 and bef==kids[0]:
        return
    for kid in kids:
        # print(f'k:{k} kids:{kids}')
        if bef==kid:
            continue
        scores[kid]+=scores[k]
        dfs(kid,k)


dfs()



print(*scores[1:])