Harryxun/stf_run huggingface dataset:
def solv(S):
    c = []
    for i in range(25, 0, -1):
        for j in range(i-1, -1, -1):
            if S[i] > S[j]:
                c.append(S[:j]+S[i])
    print(sorted(c)[0])
    return


alph = "abcdefghijklmnopqrstuvwxyz"
S = input()
for c in S:
    alph = alph.replace(c, "")
if alph != "":
    print(S+alph[0])
else:
    if S == alph[::-1]:
        print(-1)
    else:
        solv(S)


### FIXED CODE ###

def solv(S):
    c = []
    for i in range(25, 0, -1):
        for j in range(i-1, -1, -1):
            if S[i] > S[j]:
                c.append(S[:j]+S[i])
    print(sorted(c)[0])
    return


alph = "abcdefghijklmnopqrstuvwxyz"
S = input()
for c in S:
    alph = alph.replace(c, "")
if alph != "":
    print(S+alph[0])
else:
    alph = "abcdefghijklmnopqrstuvwxyz"
    if S == alph[::-1]:
        print(-1)
    else:
        solv(S)
n = input()
s = raw_input()
if(n%2==1):
 	print "No"
else:
	if(s[0:n/2]==s[n/2:n]):
		print "Yes"
  	else:
    	print "No"

### FIXED CODE ###

n = input()
s = raw_input()
if(n%2==1):
	print "No"
else:
	if(s[0:n/2]==s[n/2:n]):
		print "Yes"
	else:
  		print "No"
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

a,b=map(int,input().split())
ad=set(make_divisors(a))
bd=set(make_divisors(b))
common=ad & bd
pr=set(primes(max(common)))
ans=common & pr 
print(len(ans)+1)



### FIXED CODE ###

#!/usr/bin/env python3
import numpy as np


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2, N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def prime3(n):
    counter = 0
    primes = [2, 3]

    for n in range(5, n, 2):
        isprime = True
        for i in range(1, len(primes)):
            counter += 1
            if primes[i] ** 2 > n:
                break
            counter += 1
            if n % primes[i] == 0:
                isprime = False
                break
        if isprime:
            primes.append(n)
    return primes

a,b=map(int,input().split())
# a=b=10**10
count=0
ad=set(make_divisors(a))
bd=set(make_divisors(b))
# print(ad)
common=ad & bd
# print(common)
l=[]
for s in common:
    if is_prime(s):
        count+=1
print(count+1)
# pr=set(seachPrimeNum(max(common)))
# ans=common & pr 
# print(ans)
# print(len(ans)+1)
N,M,C=map(int, input().split())
B = list(map(int,input().split()))

ans = 0
for i in range(N):
  A = list(map(int, input().split()))
  score = C
  for j in range(M):
    score += A[i] * B[i]
  if(score > 0):
    ans += 1
print(ans)

### FIXED CODE ###

N,M,C=map(int, input().split())
B = list(map(int,input().split()))

ans = 0
for i in range(N):
  A = list(map(int, input().split()))
  score = C
  for j in range(M):
    score += A[j] * B[j]
  if(score > 0):
    ans += 1
print(ans)
h, w = map(int, input().split())
mat = []
for i in range(h):
  a = list(map(int, input().split()))
  mat.append(a)
for i in range(h):
  b = list(map(int, input().split()))
  for j in range(w):
    mat[i][j] = abs(mat[i][j]-b[j])

dp = [[[False]*(80*(h+w)) for i in range(w)] for k in range(h)]
dp[0][0][mat[0][0]] = True
for y in range(h):
  for x in range(w):
      for k in range(sum(map(sum, mat[y][x]))):
        if x > 0 and dp[y][x-1][k] or y > 0 and dp[y-1][x][k]:
          d = dp[y][x]
          d[k+mat[y][x]] = True
          d[abs(k-mat[y][x])] = True

for k in range(80*(h+w)):
  if dp[h-1][w-1][k]:
    print(k)
    exit()


### FIXED CODE ###

h, w = map(int, input().split())
mat = []
for i in range(h):
  a = list(map(int, input().split()))
  mat.append(a)
for i in range(h):
  b = list(map(int, input().split()))
  for j in range(w):
    mat[i][j] = abs(mat[i][j]-b[j])
m = max(map(max, mat))
dp = [[0b0 for i in range(w)] for k in range(h)]
dp[0][0] |= 0b1 << mat[0][0]
for y in range(h):
  for x in range(w):
        if x > 0:
          dp[y][x] |= dp[y][x-1] << mat[y][x]
          dp[y][x] |= dp[y][x-1] >> mat[y][x]
          anded = dp[y][x-1] & int('1'*(mat[y][x]+1), 2)
          reverse = format(anded, "0"+str(mat[y][x]+1)+"b")[::-1]

          dp[y][x] |= int(reverse, 2)
        if y > 0:
          dp[y][x] |= dp[y-1][x] << mat[y][x]
          dp[y][x] |= dp[y-1][x] >> mat[y][x]
          anded = dp[y-1][x] & int('1'*(mat[y][x]+1), 2)
          reverse = format(anded, "0"+str(mat[y][x]+1)+"b")[::-1]

          dp[y][x] |= int(reverse, 2)
        #print(bin(dp[y][x]))

keta = 0
while dp[h-1][w-1] % 2 == 0:
  keta += 1
  dp[h-1][w-1] //= 2
print(keta)
N,x=map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans=0


if sum(a)<x:
    print(N-1)
else:
    for i in range(len(A)):
        if X>=a[i]:
            x -= a[i]
            ans += 1
        else:
            break
            



### FIXED CODE ###

N,x=map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans=0


if sum(a)<x:
    print(N-1)
else:
    for i in range(len(a)):
        if x>=a[i]:
            x -= a[i]
            ans += 1
        else:
            break
    print(ans)
T = list(input())

num = T.count('?')
for _ in range(num):
    T[num] = 'D'

print(''.join(T))

### FIXED CODE ###

T = input()
print(T.replace('?', 'D'))
import numpy as np

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

worker = list(np.zeros(n, dtype=int))

for i in range(n-1):
    worker[A[i]-1] += 1

for i in range(n):
    print(worker[i])


### FIXED CODE ###

import numpy as np

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

worker = list(np.zeros(n, dtype=int))

for i in range(n-1):
    worker[A[i]-1] += 1

for i in range(n):
    print(worker[i])
N = int(raw_input())

found = False
for i in xrange(1, 10):	
  for j in xrange(1, 10):
  	if i*j == N:
      found = True
      
print "Yes" if found else "No"


### FIXED CODE ###

N = int(raw_input())

found = False
for i in xrange(1, 10):	
  for j in xrange(1, 10):
    if i*j == N:
      found = True
      
print "Yes" if found else "No"
N=int(input())
listS=[]
for i in range(N):
  S=input()
  listS+=[S]
listS.sort()
counter=[]
count=1
for i in range(N-1):
  if listS[i]==listS[i+1]:
    count+=1
  else:
    counter+=[count]
    count=1
    
MAX=max(counter)

for i in range(N-1):
  if listS[i]==listS[i+1]:
    count+=1
    if count==MAX:
      print(listS[i+1])
  else:
    counter+=[count]
    count=1

### FIXED CODE ###

N=int(input())
listS=[]
for i in range(N):
  S=input()
  listS+=[S]
listS.sort()
counter=[]
count=1
for i in range(N-1):
  if listS[i]==listS[i+1]:
    count+=1
  else:
    counter+=[count]
    count=1
    
counter+=[count]    
MAX=max(counter)
count=1

for i in range(N-1):
  if listS[i]==listS[i+1]:
    count+=1
  else:
    count=1
  if count==MAX:
    print(listS[i])
    
if MAX==1:
  print(listS[-1])
a = input()
print(a+a ** 2+a ** 3)

### FIXED CODE ###

a = int(input())
print(a+a**2+a**3)
k=input()  
odd=1
even=0
for i in range(2,k+1): 
     if i%2==0:
        even+=1
     else:
           odd+=1
print(odd*even)

### FIXED CODE ###

k = int(input())
if k % 2 == 0:
    print((k // 2)**2)
else:
    print((k - (k // 2)) * (k // 2))
L=map(int,raw_input().split())

m = max(L)
i = L.index(L)
score=m*10
for j in range(3):
    if j!=i:
        score+=L[j]
print score

### FIXED CODE ###

L=map(int,raw_input().split())

m = max(L)
i = L.index(m)
score=m*10
for j in range(3):
    if j!=i:
        score+=L[j]
print score
s=input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
elif
    print("No")

### FIXED CODE ###

s=input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")
s = input()
print("".join([s[i] for i in range(0, len(s), 2)))


### FIXED CODE ###

s = input()
print("".join([s[i] for i in range(0, len(s), 2)]))
import heapq
from sys import stdin

n,m = map(int,stdin.readline().rstrip().split())
jobs = [[] for i in range(m)]

for i in range(n):
    tmp,tmp2 = map(int,stdin.readline().rstrip().split())
    if(tmp>m):
        continue
    jobs[m-tmp].append(tmp2)
print(jobs)
ans = 0
h=[]
for i in range(m-1,-1,-1):
    for b in jobs[i]:
        heapq.heappush(h,-b)
    print(h)
    if(len(h)!=0):
        a = -heapq.heappop(h)
        ans += a
print(ans)

### FIXED CODE ###

import heapq
from sys import stdin

n,m = map(int,stdin.readline().rstrip().split())
jobs = [[] for i in range(m)]

for i in range(n):
    tmp,tmp2 = map(int,stdin.readline().rstrip().split())
    if(tmp>m):
        continue
    jobs[m-tmp].append(tmp2)
ans = 0
h=[]
for i in range(m-1,-1,-1):
    for b in jobs[i]:
        heapq.heappush(h,-b)
    if(len(h)!=0):
        a = -heapq.heappop(h)
        ans += a
print(ans)
from collections import Count
s = input()
n = len(s)
d = Count(s)
c = 0
for x in d:
  c += d[x]*(d[x]-1)//2
print(n*(n-1)//2 - c)

### FIXED CODE ###

from collections import Counter
s = input()
n = len(s)
d = Counter(s)
c = 0
for x in d:
  c += d[x]*(d[x]-1)//2
print(1 + n*(n-1)//2 - c)
import collections
n = int(input())
a = list(map(int,input().split()))
b = [0]*(n//2)
c = [0]
d = [0]*(n//2)
e = []
for i in range(n):
    b[i] = n-(2*i+1)
    if b[i] == 1 or b[i] == 2:
        break
for i in range(n):
    d[i] = n-(2*i+1)
    if d[i] == 1 or b[i] == 2:
        break
if n%2 == 0:
    e = b + d
else:
    e = b + c + d

count1 = collections.Counter(a)
count2 = collections.Counter(e)

if count1 == count2:
    print(2**(n//2))
else:
    print(0)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 2**(n//2)%mod
if n % 2 == 0:
    l = n ** 2
else:
    l = (n - 1) * (n + 1)
if sum(a) == l // 2:
    print(ans)
else:
    print(0)
n,m = map(int,input().split())
L = []

for i in range(m):
    L.append(list(((map(int,input().split())))))
#print(L)
if len(L) == 0:
    print(-1)
    exit()
li = [-1]*n
dic = {}
for i in range(m):
    if L[i][0] not in dic:
        dic[L[i][0]] = L[i][1]
#print(dic)
for i in range(m):
    if dic[L[i][0]] != L[i][1]:
        print(-1)
        exit()
    try:
        li[L[i][0]-1] = L[i][1]
    except IndexError:
        print(-1)
        exit()
#print(li)
if n == 1:
    print(li[0])
    exit()
else:
    for i in range(m):
        if li[i] == -1:
            li[i] = 0
    if li[0] == 0:
        print(-1)
        exit()
    else:
        li = [str(x) for x in li]
print("".join(li))

### FIXED CODE ###

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

for i in range(1000):
    p = str(i)
    flag = False
    for j in range(m):
        if len(p) >= L[j][0]:
            if int(p[L[j][0]-1]) != L[j][1]:
                break
    else:
        if len(p) == n:
            flag = True

    if flag:
        print(i)
        exit()
print(-1)
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    [n, m] = li()
    broken = [int(input()) for _ in range(m)]

    pattern = [0] * (n + 1)
    pattern[0] = 1
    pattern[1] = 1 if broken[0] != 1 else 0
    for i in range(2, n + 1):
        if broken.count(i) == 0:
            pattern[i] = (pattern[i - 2] + pattern[i - 1]) % (10 ** 9 + 7)
        else:
            pattern[i] = 0
    print(pattern[-1])


### FIXED CODE ###

def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    [n, m] = li()
    broken = [int(input()) for _ in range(m)]
    mod = 10 ** 9 + 7

    pattern = [0] * (n + 1)
    pattern[0] = 1
    broken_index = 0
    checking = broken[broken_index] if len(broken) > broken_index else -1
    if checking != 1:
        pattern[1] = 1
    else:
        pattern[1] = 0
        broken_index = broken_index + 1
        checking = broken[broken_index] if len(broken) > broken_index else -1

    for i in range(2, n + 1):
        if checking != i:
            pattern[i] = (pattern[i - 2] + pattern[i - 1]) % mod
        else:
            pattern[i] = 0
            broken_index = broken_index + 1
            checking = broken[broken_index] if len(broken) > broken_index else -1
    print(pattern[n])
import collections
import sys
n=int(input())
a=list(map(int,input().split()))
A=collections.Counter(a)
b=list(A.items())
b.sort()
cnt=0
if len(b)==1:
  print(b[0][1])
  sys.exit()
if len(b)==2:
  if int(b[1][0])-int(b[0][0])==1:
    print(b[1][1]+b[0][1])
    sys.exit()
  else:
    print(max(b[1][1],b[0][1]))
    sys.exit()
for i in range(len(b)-2):
  if int(b[i+2][0])-int(b[i+1][0])==1 and int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i][1]+b[i+1][1]+b[i+2][1]) 
  elif int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i+1][1]+b[i][1])
  else:
    cnt=max(cnt,b[i])
    
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1 and int(b[len(b)-2][0])-int(b[len(b)-3][0])!=1:
  cnt=cnt
elif int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  cnt=max(cnt,b[len(b)-1][1]-b[len(b)-2][1])
else:
  cnt=max(cnt,max(b[len(b)-1][1],b[len(b)-2][1]))
print(cnt)
  


### FIXED CODE ###

import collections
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(collections.Counter(a).items())
b.sort(key=lambda x:int(x[0]))
if len(b)==1:
  print(n)
  sys.exit()
lst=[]
num=b[0][1]
if int(b[1][0])-int(b[0][0])==1:
  num+=b[1][1]
lst.append(num)
for i in range(1,len(b)-1):
  num=b[i][1]
  if int(b[i+1][0])-int(b[i][0])==1:
    num+=b[i+1][1]
  if int(b[i][0])-int(b[i-1][0])==1:
    num+=b[i-1][1]
  lst.append(num)
num=b[len(b)-1][1]
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  num+=b[len(b)-2][1]
lst.append(num)
print(max(lst))
N,M=map(int,input().split())
X=list(map(int,input().split()))
#print(N,M,X)
sort_X=sorted(X)
#print(sort_X)
#print(sort_X[1:],sort_X[0:len(sort_X)-1])
X_sa=[x - y for (x, y) in zip(sort_X[1:], sort_X[0:len(X)-1])]
#print(X_sa)
sort_X_sa=sorted(X_sa)
#print(sort_X_sa)
#print(sort_X_sa[0:M-N])
print(sum(sort_X_sa[0:M-N]))

### FIXED CODE ###

T,X=map(int,input().split())
print(T/X)
n = int(input())
d,x = map(int,input(),split())
count += x
a = []
for i in range(n):
  a.append(int(input()))
  for j in range(n):
    if 1 + a[i]*j <= n:
      count += 1
print(count)

### FIXED CODE ###

n = int(input())
m, k = [int(_) for _ in input().split()]
    
for i in range(n):
    for j in range(1, m+1, int(input())):
        k += 1
print(k)
a, b, k = map(int, raw_input().split())

if b - a + 1 <= k * 2:
    for i in range(a, b+1):
        print(i)
else:
    l = list(range(a, b+1))
    for i in l[:k]:
        print(i)
    for i in l[-k:]:
        print(i)


### FIXED CODE ###

a, b, k = map(int, raw_input().split())

if b - a + 1 <= k * 2:
    for i in range(a, b+1):
        print(i)
else:
    for i in range(a, a+k):
        print(i)
    for i in range(b-k+1, b+1):
        if i >= 1:
            print(i)
n, k = [int(x) for x in input().split()]

vs = [int(x) for x in input().split()]

ns = [-v for v in vs if v < 0][::-1]
ps = [v for v in vs if v >= 0]

res = float('inf')
if len(ps) >= k:
    res = ps[k-1]
for i in range(min(k, len(ns))):
    if len(ps) + i + 1 < k: continue
    res = min(res, ns[i] * 2 + ps[k - i - 2])
    res = min(res, ns[i] + ps[k - i - 2] * 2)

print(res)


### FIXED CODE ###

n, k = [int(x) for x in input().split()]

vs = [int(x) for x in input().split()]

ns = [-v for v in vs if v < 0][::-1]
ps = [v for v in vs if v >= 0]

res = float('inf')
if len(ps) >= k:
    res = ps[k-1]
for i in range(min(k, len(ns))):
    if len(ps) + i + 1 < k: continue
    res = min(res, ns[i] * 2 + (ps[k - i - 2] if k > i + 1 else 0))
    res = min(res, ns[i] + (ps[k - i - 2] if k > i + 1 else 0) * 2)

print(res)
S = list( map( int, input.split()))

S[3] += 1

print(S)

### FIXED CODE ###

S = input()

S = S.replace('2017', '2018')

print(S)
N = int(input())
ans = 0
if 1 <= N <= 10000:
    if N%1000 != 0:
        ans = 1000 - int(str(N)[1:])
    else:
        ans = 0
else:
    ans = "choose another number"
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0
if 1 <= N <= 10000:
    if N%1000 != 0:
        ans = ((N//1000) + 1)*1000 - N
    else:
        ans = 0
else:
    ans = "choose another number"
print(ans)
n=[int(i) for i in input().split]
if(n[0]>=n[1]):
  print(10)
else:
  print(0)

### FIXED CODE ###

n=[int(i) for i in input().split()]
if(n[0]>=n[1]):
  print(10)
else:
  print(0)
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 10000
for i in range(1,N):
  ans = min(ans, abs(sum(A[:i]-A[i+1:]))
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = 10000
for i in range(1,N):
  ans = min(ans, abs(sum(A[:i])-sum(A[i:])))
print(ans)
import math

s = input()

print(math.ceil(s/2)*math.floor(s/2))

### FIXED CODE ###

import math

s = int(input())

print(math.ceil(s/2)*math.floor(s/2))
S=str(input())
size=len(S)

print(S[0]+(int(size)-2)+S[-1])

### FIXED CODE ###

S=str(input())
size=len(S)

print(S[0]+str(int(size)-2)+S[-1])
K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=[]
                    X_Y_=list(X_)
                    X_Y_.append(y)
                    for z in Z:
                        if z<=S:
                            X_Y_Z_=list(X_Y_)
                            X_Y_Z_.append(z) 
                            wa_=sum(X_Y_Z_)
                            wa.append(wa_)
    for j in wa:
        if j==S:
            count+=1
    print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        if S-(x+y)>=0 and S-(x+y)<=K: count+=1
print(count)
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = abs(min(x+d*k, x-d*k))
else:
  for _ in range(k):
    xi -= d
    if xi < 0:
      m = abs(min(xi,xi+d,xi-d))
      break
print(m)

### FIXED CODE ###

from math import ceil 
x,k,d = list(map(int,input().split()))

xi = abs(x)
if abs(x) > d*k:
  m = min(abs(x+d*k),abs(x-d*k))
else:
  n = ceil(xi / d)
  if (n+k) % 2 == 0:
    m = abs(xi-d*n)
  else:
    m = abs(xi-d*(n-1))
print(m)
import numpy as np

def main():
    n = int(input())
    ball = [list(map(int, input().split(' '))) for i in range(n)]
    ball = np.array(ball, dtype=int)
    # print(ball)

    l1 = []
    l2 = []
    for i in range(n):
        for j in range(i, n):
            if i == j: continue
            dis1 = ball[i] - ball[j]
            dis2 = ball[j] - ball[i]
            l1.append(list(dis1))
            l2.append(list(dis2))
    # print(l1, l2)
    # c1 = collections.Counter(l1)
    # c2 = collections.Counter(l2)

    c1 = []
    c2 = []
    for i in range(len(l1)):
        c1.append(l1.count(l1[i]))
        c2.append(l2.count(l2[i]))
    m1 = np.max(np.array(c1, dtype=int))
    m2 = np.max(np.array(c2, dtype=int))

    print(max(1,n-max(m1,m2)))

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np

def main():
    n = int(input())
    ball = [list(map(int, input().split(' '))) for i in range(n)]
    ball = np.array(ball, dtype=int)
    if n == 1:
        print(1)
        exit()

    l1 = []
    for i in range(len(ball)):
        for j in range(len(ball)):
            if i == j: continue
            dis1 = ball[i] - ball[j]
            l1.append(list(dis1))

    c1 = []
    for i in range(len(l1)):
        c1.append(l1.count(l1[i]))
    m1 = np.max(np.array(c1, dtype=int))

    print(n-m1)

if __name__ == "__main__":
    main()
class UnionFind:
    def __init__(self, num):
        self.p = [x for x in range(num)]
    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx != ry:
            self.p[ry] = rx

def main():
    N, M = (int(x) for x in input().split())
    u = UnionFind(N)

    for i in range(M):
        x,y,_ = map(int, input().split())
        u.unite(x-1, y-1)

    rlist = set()
    for i in range(N):
        rlist.add(u.root(i))

    print(len(rlist))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

class UnionFind:
    def __init__(self, num):
        self.p = [x for x in range(num)]
    def root(self, x):
        if self.p[x] == x:
            return x
        else:
            self.p[x] = self.root(self.p[x])
            return self.p[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx != ry:
            self.p[ry] = rx

def main():
    N, M = (int(x) for x in input().split())
    u = UnionFind(N)

    for i in range(M):
        x,y,_ = map(int, input().split())
        u.unite(x-1, y-1)

    rlist = set()
    for i in range(N):
        rlist.add(u.root(i))

    print(len(rlist))

if __name__ == '__main__':
    main()
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  ans+=1/a[i]
print(1/ans)


### FIXED CODE ###

a=int(input())
s=input()
if a>=2800 and a<3200:
  print('red')
if a>=3200 and a<5000:
  print(s)
from functools import reduce

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

def nCr(N,R,DIV):
  f=lambda x,y:x*y%DIV
  if R>N-R:
    R=N-R
  X=reduce(f,range(N-R+1,N+1))
  Y=reduce(f,range(1,R+1))
  return X*pow(Y,DIV-2,DIV)%DIV

DIV=10**9+7
ans=pow(2,n,DIV)-1
ans-=nCr(n,a,DIV)
ans-=nCr(n,b,DIV)
print(ans%DIV)

### FIXED CODE ###

from functools import reduce
def nCr(n,r,DIV):
  # X/Y mod DIV == X*Y**(DIV-2)
  X=reduce(lambda x,y:x*y%DIV,range(n-r+1,n+1))
  Y=reduce(lambda x,y:x*y%DIV,range(1,r+1))
  return X*pow(Y,DIV-2,DIV)%DIV

DIV=10**9+7
n,a,b=map(int,input().split())
ans=pow(2,n,DIV)-1
ans-=nCr(n,a,DIV)
ans-=nCr(n,b,DIV)
print(ans%DIV)
n = input()
a = list(map(int, input().split())
while True:
	sum += a[num for num in len(a)]
	if sum % 2:
		break
	for num in a:
		num /= 2
	i += 1
print(i)

### FIXED CODE ###

from time import sleep
n = input()
A = list(map(int, input().split()))
i = 0
while True:
    if len([a for a in A if a % 2]) > 0:
        break
    A = list(map(lambda x: x/2, A))
    i+=1
print(i)
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[0]*q
c=[0]*q
for i in range(q):
  b[i],c[i]=map(int,input().split())

s=sum(a)

#このコードはO(10**10)になる可能性があり、重すぎる
"""
for i in range(q):
  while b[i] in a:
    s+=c[i]-b[i]
    a.remove(b[i])
    a.append(c[i])
  print(s)
"""

cnt_list=[0]*(10**5)
for i in range(n):
  cnt_list[a[i]]+=1

for i in range(q):
  s+=(c[i]-b[i])*cnt_list[b[i]]
  cnt_list[c[i]]+=cnt_list[b[i]]
  cnt_list[b[i]]=0
  print(s)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[0]*q
c=[0]*q
for i in range(q):
  b[i],c[i]=map(int,input().split())

s=sum(a)

#このコードはO(10**10)になる可能性があり、重すぎる
"""
for i in range(q):
  while b[i] in a:
    s+=c[i]-b[i]
    a.remove(b[i])
    a.append(c[i])
  print(s)
"""

cnt_list=[0]*(10**5+1)
for i in range(n):
  cnt_list[a[i]]+=1

for i in range(q):
  s+=(c[i]-b[i])*cnt_list[b[i]]
  cnt_list[c[i]]+=cnt_list[b[i]]
  cnt_list[b[i]]=0
  print(s)