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

def cordineatecompression(list):
    n=len(list)
    test=[(list[i],i) for i in range(0,n)]
    ans=[-1 for i in range(0,n)]
    test.sort()
    co=1
    val=test[0][0]
    ans[test[0][1]]=co
    for i in range(1,n):
        if val==test[i][0]:
            ans[test[i][1]]=co
        else:
            val=test[i][0]
            co+=1
            ans[test[i][1]]=co
    return ans

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

def median(num):
    data=[0]*N
    for i in range(N):
        if A[i]>num:
            data[i]=1
        else:
            data[i]=-1
    for i in range(1,N):
        data[i]+=data[i-1]
    data=[0]+data
    data=cordineatecompression(data)


    ans=0

    BIT=[0]*(N+2)
    n=N+1
    def BIT_query(idx):
        res_sum = 0
        while idx > 0:
            res_sum += BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    def BIT_update(idx,x):
        while idx <= n:
            BIT[idx] += x
            idx += idx&(-idx)
        return

    for i in range(0,N+1):
        val=data[i]
        ans+=BIT_query(val)
        BIT_update(val,1)
    test=N*(N+1)//2-ans
    return test>=((N*(N+1)//2)//2+1)

start=0
end=10**12
while end-start>1:
    test=(end+start)//2
    if median(test):
        end=test
    else:
        start=test

if median(start):
    print(start)
else:
    print(end)

### FIXED CODE ###

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

def median(num):
    row=[0]*N
    for i in range(N):
        if A[i]>num:
            row[i]=1
        else:
            row[i]=-1
    m=0
    data=[0]
    for i in range(0,N):
        data.append(data[-1]+row[i])
        m=min(m,data[i+1])
    data=[data[i]-m+1 for i in range(N+1)]
    ans=0
    BIT=[0]*(N+2)
    n=N+1
    def BIT_query(idx):
        res_sum = 0
        while idx > 0:
            res_sum += BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    def BIT_update(idx,x):
        while idx <= n:
            BIT[idx] += x
            idx += idx&(-idx)
        return

    for i in range(0,N+1):
        val=data[i]
        ans+=BIT_query(val)
        BIT_update(val,1)
    test=N*(N+1)//2-ans
    return test>=((N*(N+1)//2)//2+1)

start=0
end=10**9
while end-start>1:
    test=(end+start)//2
    if median(test):
        end=test
    else:
        start=test

if median(start):
    print(start)
else:
    print(end)
### BUGGY CODE ###

import math
s = list(input())
s = list(map(int, s))
s_ori = s.copy()
s_len = len(s)

s_new=[]
for _ in range(200000000):
    count=0
    for i in range(1,len(s)):
        if count %2==1:
            count +=1
            if i +1==len(s):
                s_new.append(s[-1])
            continue
        if s[i] is not s[i-1]:
            count +=1
        else:
            s_new.append(s[i-1])
            if i +1==len(s):
                s_new.append(s[-1])     
    if s==s_new:
        s = s_new
        break
    s = s_new
    s_new=[]

#print(s_ori)    
#print(s)
print(math.floor((len(s_ori)-len(s))/2)*2)

### FIXED CODE ###

import math
from collections import Counter
s = list(input())
s = list(map(int, s))
dict_s = Counter(s)
#print(dict_s)
print((min(dict_s[0], dict_s[1]))*2)
### BUGGY CODE ###

import math
N=int(input())
i=int(math.sqrt(N))
while(True):
    if N%i==0:
        S=i+N//i-2
        print(S)
        break
    i+=1

### FIXED CODE ###

import math
N=int(input())
n=int(math.sqrt(N))
S=0
for i in range(1,n+1):
    if N%i==0:
        s=i+N//i-2
        if S==0:
            S=s
        elif S>=s:
            S=s
print(S)
### BUGGY CODE ###

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

### FIXED CODE ###

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

n = int(input())
p=list(map(int, input().split()))
c=0
for i in range(n):
    for j in range(0,i+1):
        if p[i] <= p[j]:
            if i==j:
                c+=1
        else:
            break

print(c)

### FIXED CODE ###

n = int(input())
p=list(map(int, input().split()))
c=0
min=p[0]
for i in range(n):
    if min>=p[i]:
        c+=1
        min=p[i]
print(c)
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [float('inf') for _ in range(N + K)]
    h += [float('inf') for _ in range(K)]

    dp[0] = 0
    for i in range(N):
        for k in range(1, K + 1):
            dp[i + k] = min(dp[i + k], dp[i] + abs(h[i] - h[i + k]))

    print(dp[N - 1])

main()


### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [0 for _ in range(N)]

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

        dp[i] = min(tmp)

    print(dp[-1])

main()
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
dict={}
for _ in range(Q):
    l,r=map(int,input().split())
    string=S[l-1:r]
    if string in dict:
        print(dict[string])
    else:
        v=string.count('AC')
        print(v)
        dict[string]=v

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()

aclist=[0 for i in range(N+1)]
for i in range(2,N+1):
    aclist[i]=aclist[i-1]+(1 if S[i-2]=='A' and S[i-1]=='C' else 0)

for j in range(Q):
    l,r=map(int,input().split())
    print(aclist[r]-aclist[l])
### BUGGY CODE ###

N, M, Q = list(map(int, input().split()))
LR = []
pq = []
for i in range(M):
  LR.append(list(map(int, input().split())))
for i in range(Q):
  pq.append(list(map(int, input().split())))

C = [[0] * (N+1) for i in range(N+1)]
for i in range(M):
  for j in range(1, LR[i][0]+1):
    for k in range(LR[i][1], N+1):
      C[j][k] += 1
      
for i in range(Q):
  print(C[pq[i][0]][pq[i][1]])

### FIXED CODE ###

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

C = [[0] * (N+1) for i in range(N+1)]
for i in range(M):
  L, R = list(map(int, input().split()))
  C[L][R] += 1

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

inputs = raw_input().replace("\n", "").split(" ")
H, W = map(int, inputs)

m = [ [-1 for x in range(W)] for y in range(H)]

count = 0
zero_coords = []
for y in range(H):
    #line = list(input())
    line = list(raw_input().replace("\n", ""))
    for x, point in enumerate(line):
        if point == "#":
            m[y][x] = 0
            zero_coords.append([y, x])
            count += 1

tmp_coords = zero_coords
#mawari_soutais = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]
mawari_soutais = [[-1, 0], [0, -1], [0, 1], [1, 0]]

val = 0
while count < H*W:
    val += 1
    new_tmp_coords = []
    for center_coord in tmp_coords:
        for mawari_soutai in mawari_soutais:
            mawari_coord = [mawari_soutai[i] + center_coord[i] for i in range(2)]
            y, x = mawari_coord
            if y < 0 or H <= y or x < 0 or W <= x or m[y][x] != -1:
                continue
            else:
                m[y][x] = val
                count += 1
                new_tmp_coords.append([y, x])
    tmp_coords = new_tmp_coords
    #print(m)

out = val
print(out)

### FIXED CODE ###

inputs = raw_input().replace("\n", "").split(" ")
H, W = map(int, inputs)

m = [ [-1 for x in range(W)] for y in range(H)]

count = 0
zero_coords = []
for y in range(H):
    #line = list(input())
    line = list(raw_input().replace("\n", ""))
    for x, point in enumerate(line):
        if point == "#":
            m[y][x] = 0
            zero_coords.append([y, x])
            count += 1

tmp_coords = zero_coords
#mawari_soutais = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]
mawari_soutais = [[-1, 0], [0, -1], [0, 1], [1, 0]]

val = 0
while count < H*W:
    val += 1
    new_tmp_coords = []
    for center_coord in tmp_coords:
        for mawari_soutai in mawari_soutais:
            mawari_coord = [mawari_soutai[i] + center_coord[i] for i in range(2)]
            y, x = mawari_coord
            if y < 0 or H <= y or x < 0 or W <= x or m[y][x] != -1:
                continue
            else:
                m[y][x] = val
                count += 1
                new_tmp_coords.append([y, x])
    tmp_coords = new_tmp_coords
    #print(m)

out = val
print(out)
### BUGGY CODE ###

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

A.sort(reverse=True)
#print(A)

B=A[0:max(N,M)]

for i in range(M):
    idx = B.index(max(B))

    B[idx] = int(B[idx] / 2.0)
#    A.sort(reverse=True)

ans = 0
for i in range(N):
    if i < len(B):
        ans+=B[i]
    else:
        ans += A[i]

print(ans)

### FIXED CODE ###

import heapq

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

for i in range(N):
    A[i] = -A[i]

heapq.heapify(A)

for j in range(M):
    a = heapq.heappop(A)
    b = -1*((-a) // 2)
    heapq.heappush(A,b)

print(-sum(A))
### BUGGY CODE ###

N,K = map(int,input().split())
x = list(map(int,input().split()))

ans = 10**18
for i in range(N - K + 1):
    p = x[i:i+K]
    lr = abs(p[0]) + abs(p[-1] - p[0])
    rl = abs(p[-1]) + abs(p[0] - p[-1])
    if lr < rl:
        ans = min(ans,lr)
    else:
        ans = min(ans,rl)
print(ans)


### FIXED CODE ###

N,K = map(int,input().split())
x = list(map(int,input().split()))

ans = 10**18
for i in range(N - K + 1):
    p1 = x[i]
    p2 = x[i+K-1]
    lr = abs(p1) + abs(p2 - p1)
    rl = abs(p2) + abs(p1 - p2)
    if lr < rl:
        ans = min(ans,lr)
    else:
        ans = min(ans,rl)
print(ans)
### BUGGY CODE ###

s=input()
k=int(input())
str=[]
p=1
for i in range(k):
    for j in range(len(s)):
        if j+i+1<=len(s):
            str.append(s[j:j+i+1])
            str=list(set(str))
str.sort()
print(str[k-1])

### FIXED CODE ###

s=input()
k=int(input())
str=[]
p=1
for i in range(k):
    for j in range(0,len(s)-i):
        str.append(s[j:j+i+1])
str=list(set(str))
str.sort()
print(str[k-1])
### BUGGY CODE ###

n = int(input())
m = 0
a = []
for _ in range(n):
    _a = int(input())
    m = max(m, _a)
    a.append(_a)

for i in range(n):
    if a[i] == m:
        t = a[:]
        t.pop(i)
        print(max(t))
    else:
        print(m)


### FIXED CODE ###

n = int(input())
maxindex = maxvalue = 0
a = []
for i in range(n):
    _a = int(input())
    if maxvalue <= _a:
        maxvalue = _a
        maxindex = i
    a.append(_a)

for i in range(n):
    if i != maxindex:
        print(maxvalue)
        continue
    t = a[:]
    t.pop(i)
    print(max(t))
### BUGGY CODE ###

import sys
 
sys.setrecursionlimit(200000000)
 
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]
 
l = [[] for i in range(n+1)]
for pi in ab:  
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])

l_2 = [0 for i in range(n+1)]
for p, x in px:
    l_2[p] += x
'''
def dfs(graph, start, oya):
    if start != 1:
        graph[start].remove(oya)
    if len(graph[start]) == 0:
        return
    else:
        for i in graph[start]:
            dfs(graph, i, start)
 
dfs(l, 1, 1)
'''
 
def dfs_2(graph, start, ans, oya, x, l_2):
    ans[start] += x
    if len(graph[start]) == 1 and start == oya:
        return
    else:
        for i in graph[start]:
            if i != oya:
                dfs_2(graph, i, ans, start, x+l_2[i], l_2)
 
ans = [0 for i in range(n+1)]
dfs_2(l, 1, ans, 0, l_2[1], l_2)
        
for i in range(1, n+1):
    print(ans[i], end=' ')
print()

### FIXED CODE ###

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]
 
l = [[] for i in range(n+1)]
for a, b in ab:  
    l[a].append(b)

value = [0 for i in range(n+1)]
for p, x in px:
    value[p] += x

stack = [1]
while stack:
    label = stack.pop()
    for i in l[label]:
        value[i] += value[label]
    stack += l[label]
        
print(*value[1:])
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
A.reverse()
ans = []
left = True
while A:
    if left: ans.insert(0,A.pop())
    else: ans.append(A.pop())
    left = not left
if n % 2 == 0: ans.reverse()
print(' '.join(str(a) for a in ans))

### FIXED CODE ###

from collections import deque
n = int(input())
A = list(map(int,input().split()))
A.reverse()

left = True
ans = deque()
while A:
    if left: ans.appendleft(A.pop())
    else: ans.append(A.pop())
    left = not left
if n % 2 == 0: ans.reverse()
print(' '.join(str(a) for a in ans))
### BUGGY CODE ###

N = int(input())
import sys
sys.setrecursionlimit(1000000)
MOD = 10**9+7
E = {}
for i in range(0,N+1):
    E[i] = []
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    E[a].append(b)
    E[b].append(a)

dp = [ [0 for i in range(2)] for j in range(1000100)]

def dfs(c,p):
    dp[c][0],dp[c][1] = 1,1
    for to in E[c]:
        if to != p:
            dfs(to,c)
            dp[c][0] *= dp[to][0] + dp[to][1]
            dp[c][1] *= dp[to][0]
            dp[c][0] %= MOD
            dp[c][1] %= MOD

dfs(0,-1)

ans = (dp[0][0] + dp[0][1]) % MOD
print(ans)


### FIXED CODE ###

from heapq import heappush, heappop
import collections
import math
import heapq
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float("inf")


def main():
    N = int(input())
    E = {}
    for i in range(0, N+1):
        E[i] = []
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        E[a].append(b)
        E[b].append(a)

    dp = [[0 for i in range(2)] for j in range(100100)]

    def dfs(c, p):
        dp[c][0], dp[c][1] = 1, 1
        for to in E[c]:
            if to != p:
                dfs(to, c)
                dp[c][0] *= dp[to][0] + dp[to][1]
                dp[c][1] *= dp[to][0]

    dfs(0, -1)

    ans = (dp[0][0] + dp[0][1]) % MOD
    print(ans)


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

n, k, *A = map(int, open(0).read().split())
s = 1
for a in A[:k]:
    s *= a
s0 = s
for i in range(k, n):
    s //= A[i-k]
    s *= A[i]
    if s0 < s:
        print('Yes')
    else:
        print('No')
    s0 = s

### FIXED CODE ###

n, k, *A = map(int, open(0).read().split())
for i in range(k, n):
    if A[i-k] < A[i]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

N = int(input())
count = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:
            count += 1
print(count)

### FIXED CODE ###

N = int(input())
d = dict()
for i in range(1, 10):
    for j in range(1, 10):
        d[str(i) + str(j)] = 0

for i in range(1, N + 1):
    if str(i)[-1] != '0':
        d[str(i)[0] + str(i)[-1]] += 1

result = 0
for i in range(1, 10):
    for j in range(1, 10):
        result += d[str(i) + str(j)] * d[str(j) + str(i)]

print(result)
### BUGGY CODE ###

from bisect import *

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

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        lower = max(j+1, bisect_right(l, b-a))
        upper = bisect_left(l, a+b)
        cnt += max(0, upper-lower)

print(cnt)

### FIXED CODE ###

from bisect import *

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

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        lower = max(j+1, bisect_right(l, b-a))
        upper = bisect_left(l, a+b)
        cnt += max(0, upper-lower)

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

import sys
input = sys.stdin.readline
def main():
  s = input()
  t = input()
  a = len(s)
  b = len(t)
  dp = [[0]*(b+1) for _ in range(a+1)]
  prev_w = [[0]*(b+1) for _ in range(a+1)]
  for i in range(a):
    for j in range(b):
      if s[i]==t[j]:
        if dp[i][j]+1>dp[i+1][j+1]:
          dp[i+1][j+1] = dp[i][j]+1
          prev_w[i+1][j+1] = [i,j]
      else:
        if dp[i+1][j]>dp[i][j+1]:
          dp[i+1][j+1]=dp[i+1][j]
          prev_w[i+1][j+1] = (i+1,j)
        else:
          dp[i+1][j+1]=dp[i][j+1]
          prev_w[i+1][j+1] = (i,j+1)
  #print(dp[a][b])
  #print(prev_w[1][3])
  ans = []
  while a!=0 and b !=0:
    l = dp[a][b]
    a,b=prev_w[a][b]
    if l>dp[a][b]:
      ans.append(s[a])
  ans ="".join(ans)
  ans =ans[::-1]
  print(ans)
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
  import sys
  input = sys.stdin.readline
  ans = []
  ans_append = ans.append
  s = input()
  t = input()
  a = len(s)
  b = len(t)
  dp = [[0]*(b+1) for _ in range(a+1)]
  prev_w = [[None]*(b+1) for _ in range(a+1)]
  for i in range(a):
    for j in range(b):
      if s[i]==t[j]:
        if dp[i][j]+1>dp[i+1][j+1]:
          dp[i+1][j+1] = dp[i][j]+1
          prev_w[i+1][j+1] = (i,j)
      else:
        if dp[i+1][j]>dp[i][j+1]:
          dp[i+1][j+1]=dp[i+1][j]
          prev_w[i+1][j+1] = (i+1,j)
        else:
          dp[i+1][j+1]=dp[i][j+1]
          prev_w[i+1][j+1] = (i,j+1)
  while a!=0 and b !=0:
    l = dp[a][b]
    a,b=prev_w[a][b]
    if l>dp[a][b]:
      ans_append(s[a])
  ans ="".join(ans)
  ans =ans[::-1]
  print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())

ans = [i for i in range(0, n)]
print(sum(ans))

### FIXED CODE ###

n = int(input())

ans = (n-1)*n // 2

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




def wantans(nowp,sc,rlis,ans):

    if len(rlis) == 0:
        ans = min(ans , sc)
        return ans

    for i in range(len(rlis)):

        nexsc = sc
        nexlis = rlis.copy()
        del nexlis[i]

        if nowp != None:
            nexsc += lis[nowp][rlis[i]]
            
        ans = wantans(rlis[i],nexsc,nexlis,ans)

    return ans
        




N,M,R = map(int,input().split())

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

lis = [ [float("inf")] * N for i in range(N) ]

for i in range(N):

    lis[i][i] = 0

for i in range(M):

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

    A -= 1
    B -= 1

    lis[A][B] = C
    lis[B][A] = C

for k in range(N):

    for i in range(N):

        for j in range(N):

            lis[i][j] = min(lis[i][j],lis[i][k]+lis[k][j])



for i in range(R):
    r[i] -= 1
    
ans = wantans(None,0,r,float("inf"))

print (ans)


### FIXED CODE ###




def wantans(nowp,sc,rlis,ans):

    if len(rlis) == 0:
        ans = min(ans , sc)
        return ans

    for i in range(len(rlis)):

        nexsc = sc

        nexlis = []
        for j in range(len(rlis)):
            if i != j:
                nexlis.append(rlis[j])

        if nowp != None:
            nexsc += lis[nowp][rlis[i]]
            
        ans = wantans(rlis[i],nexsc,nexlis,ans)

    return ans
        




N,M,R = map(int,input().split())

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

lis = [ [float("inf")] * N for i in range(N) ]

for i in range(N):

    lis[i][i] = 0

for i in range(M):

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

    A -= 1
    B -= 1

    lis[A][B] = C
    lis[B][A] = C

for k in range(N):

    for i in range(N):

        for j in range(N):

            lis[i][j] = min(lis[i][j],lis[i][k]+lis[k][j])



for i in range(R):
    r[i] -= 1
    
ans = wantans(None,0,r,float("inf"))

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

a,b,c,k = map(int,input().split())
x = 0
y = 0
z = 0
o = 0
for i in range(k):
  x = b + c
  y = c + a
  z = a + b
  a = x
  b = y
  c = z
  
o = a - b
if o > 1000000000000000000 or o < -1000000000000000000:
  print("Unfair")
else:
  print( o )

### FIXED CODE ###

a,b,c,k = map(int,input().split())
x = k%2
if x == 0:
  print(a-b)
else:
  print(b-a)
### BUGGY CODE ###

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

### FIXED CODE ###

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

n,m = map(int, input().split())
List = sorted(list(map(int, input().split())))
cand = []
for _ in range(m):
  b,c = map(int,input().split())
  for i in range(b):
    cand.append(c)
cand = sorted(cand)[::-1]
chan = []
for i in range(min(len(List),len(cand))):
  if cand[i] >=List[i]:
    chan.append(cand[i])
  else:
    break
leng = len(chan)
ans = chan +List[leng:]
print(sum(ans))

### FIXED CODE ###

n,m = map(int, input().split())
List = list(map(int, input().split()))
List.sort()
cand = []
for _ in range(m):
  b,c = map(int,input().split())
  cand.append((b,c))
bc = sorted(cand, key=lambda x: x[1], reverse=True)
i = 0
for b, c in bc:
    while b:
        if i < n and List[i] < c:
            List[i] = c
            b -= 1
        else:
            break
        i += 1
print(sum(List))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
p = 1
for i in range(n):
    p *= a[i]
    if(p == 0):
        break
if(p > 10**18):
    print(-1)
else:
    print(p)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
p = 1
if(0 in a):
    print(0)
else:
    for i in range(n):
        p *= a[i]
        if(p > 10**18):
            p = -1
            break
    print(p)
### BUGGY CODE ###

import math
K=int(input())
ans=0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            a=math.gcd(i,j)
            b=math.gcd(a,k)
            ans +=b
print(ans)

### FIXED CODE ###

from math import gcd
K=int(input())
ans=0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(gcd(i,j),k)
print(ans)
### BUGGY CODE ###

import collections
N = int(input())
A = list(map(int, input().split()))
for x in range(N):
  ans = 0
  b = A.pop(x)
  c = collections.Counter(A)
  v = [k for j,k in c.items()]
  for i in v:
    ans += int(i*(i-1)/2)
  print(ans)
  A.insert(x,b)

### FIXED CODE ###

from collections import Counter

n = int(input())
a = [int(x) for x in input().split()]
s = 0
c = Counter(a)
# print(c)
for i in c.values():
    s += i*(i-1)// 2
    
# print(s)
for j in range(n):
    t = c[a[j]]
    print(s-t+1)
### BUGGY CODE ###

import numpy as np
n, m = list(map(int, input().split()))

ranges = np.array([0] * (n))
for i in range(m):
  r, l = list(map(int, input().split()))
  ranges[r-1:l] += 1
  
print((ranges == m).sum())

### FIXED CODE ###

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

R, L = [], []
for i in range(m):
  l, r = list(map(int, input().split()))
  R.append(r)
  L.append(l)
  
print(max(min(R) - max(L) + 1, 0))
### BUGGY CODE ###

import sys
from collections import Counter
readline = sys.stdin.buffer.readline

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

s = sum(a)
for b, c in L:
  # print(a)
  if b in a:
    a[c] += a[b]
    del a[b]
  print(sum(x * y for x, y in a.items()))



### FIXED CODE ###

import sys
from collections import Counter
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))
 
s = sum(x * y for x, y in a.items())
for b, c in L:
  # print(a)
  if b in a:
    s += (c - b) * a[b]
    a[c] += a[b]
    del a[b]
  print(s)