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

import math
n = int(input())
S = list(map(int,input().split()))
M = 10**9 + 1
def merge(A, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1+1)
    R = [0] * (n2+1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = M
    R[n2] = M
    i = 0
    j = 0
    for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

count = 0
mergeSort(S,0,len(S))
print(*S)
print(count)

### FIXED CODE ###

n = int(input())
S = list(map(int,input().split()))
M = 10**9 + 1
def merge(A, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = A[left:left + n1]
    R = A[mid:mid + n2]
    L.append(M)
    R.append(M)
    i = 0
    j = 0
    for k in range(left,right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

count = 0
mergeSort(S,0,len(S))
print(*S)
print(count)
### BUGGY CODE ###



N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
           
time = 0
result = "Yes"
jobs.sort(key=lambda x:x[1])

while jobs:
    job = jobs.pop(0)
    time += job[0]
    if(time > job[1]):
        result = "No"
        break

print(result)

    


### FIXED CODE ###



N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
           
time = 0
result = "Yes"
jobs.sort(key=lambda x:x[1])

for job in jobs:
    time += job[0]
    if(time > job[1]):
        result = "No"
        break

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

n,m=map(int,input().split())
A=[]
for i in range(m):
  a,b=map(int,input().split())
  C=[int(i) for i in input().split()]
  x=0
  for c in C:
    x|=(1<<(c-1))
  A.append((a,x))
DP=[float("inf")]*(2**n)
DP[0]=0
for i in range(m):
  a,x=A[i]
  for j in range(2**n):

    DP[j|x]=min(DP[j|x],DP[j]+a)

print(-1 if DP[2**n-1]==float("inf") else DP[2**n-1])


### FIXED CODE ###

n,m=map(int,input().split())
A=[]
for i in range(m):
  a,b=map(int,input().split())
  C=[int(i) for i in input().split()]
  x=0
  for c in C:
    x|=(1<<(c-1))
  A.append((a,x))
DP=[float("inf")]*(2**n)
DP[0]=0
for i in range(m):
  a,x=A[i]
  for j in range(2**n):

    DP[j|x]=min(DP[j|x],DP[j]+a)

print(-1 if DP[2**n-1]==float("inf") else DP[2**n-1])
### BUGGY CODE ###

from collections import deque

N = int(input())
l = [deque([])]+[deque(map(int, input().split())) for _ in range(N)]

v = 0
ans = 0
t = N*(N-1)//2

while v<t and ans<t:
    used = set()
    for n in range(1, N+1):
        if n in used:continue
        if not l[n]:continue
        pair = l[n][0]
        b = l[pair][0]
        if pair in used:continue

        if b==n:
            l[n].popleft()
            l[pair].popleft()
            used|={n,pair}
            v += 1
    ans += 1

if ans==t and ans!=v:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

from collections import deque

N = int(input())
l = [deque([])]+[deque(map(int, input().split())) for _ in range(N)]

v = 0
ans = 0
t = N*(N-1)//2

last_used = set(range(1, N+1))
while v<t and ans<t:
    used = set()
    for n in last_used:
        if n in used:continue
        if not l[n]:continue
        pair = l[n][0]
        b = l[pair][0]
        if pair in used:continue

        if b==n:
            l[n].popleft()
            l[pair].popleft()
            used|={n,pair}
            v += 1
    last_used = used
    ans += 1

if ans==t and ans!=v:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

s,c = map(int,input().split())

ass = 0
while True:
    if s > 0 and c > 1:
        ass += 1
        s -= 1
        c -=2
    elif s == 0 and c >= 4:
        ass += 1
        c -= 4
    else:
        break
print(ass)

### FIXED CODE ###

s,c = map(int,input().split())

ass = 0
if s >= c//2:
    print(c//2)
else:
    ass += s
    c -= s*2
    
    ass += c//4
    print(ass)
### BUGGY CODE ###

import copy

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

N = 13
MOD = 1000000000 + 7
s = input()
dp = [0 for i in range(N)]
nextdp = [0 for i in range(N)]
dp[0] = 1

for i, si in enumerate(reversed(s)):
    nextdp = [0 for j in range(N)]

    for j in range(10):
        c = 0
        if si == "?":
            c = (j * 10 ** i) % N
        elif j == 0:
            c = (int(si) * 10 ** i) % N
        else:
            break

        for k in range(N):
            nextdp[(k + c) % N] += dp[k]
            nextdp[(k + c) % N] %= MOD

    dp = copy.copy(nextdp)

print(dp[5])


### FIXED CODE ###

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

N = 13
MOD = 10 ** 9 + 7

s = input()[::-1]

dp = [0 for i in range(N)]
nextdp = [0 for i in range(N)]
zeros = [0 for i in range(N)]
dp[0] = 1

r = 1
for i, si in enumerate(s):
    nextdp = zeros[:]

    for j in range(10):
        jj = j
        if si == "?":
            pass
            # c = (j * 10 ** i) % N
        elif j == 0:
            jj = int(si)
        else:
            break

        for k in range(N):
            l = (k + r * jj) % N
            nextdp[l] = (nextdp[l] + dp[k]) % MOD

    dp = nextdp
    r = r * 10 % N

print(dp[5])
### BUGGY CODE ###

N=int(input())
L=list(map(int,input().split()))
L_i=[i+1 for i in range(len(L))]

cnt=0
for i in range(N):
    P_L= [m+L[i] for m in L[i:]]
    P_L_i = [x for x in range(N-i)]
    cnt = cnt + sum([P_L[w]==P_L_i[w] for w in range(N-i)])
    
print(cnt)

### FIXED CODE ###

def main():
    N=int(input())
    L=list(map(int,input().split()))
    L_i,L_j=[],[]
    L_memo = [0]*N
    cnt=0
    for i, j in enumerate(L):
        if i+j<N:
            L_memo[i+j]+=1
        if i-j>0:
            cnt+=L_memo[i-j]        
    print(cnt)
main()
### BUGGY CODE ###

def solve(N, K, As):
    alls = []
    for i in range(N):
        for j in range(i + 1, N + 1):
            alls.append("{:061b}".format(sum(As[i:j])))
    def find(i, alls):
        if i > 60:
            return []
        ones = [a for a in alls if a[i] == "1"]
        if len(ones) < K:
            return find(i + 1, alls)
        elif len(ones) == K:
            return ones
        elif len(ones) > K:
            ret = find(i + 1, ones)
            if len(ret) == 0:
                return ones[0:K]
            else:
                return ret

    ans = find(0, alls)
    if len(ans):
        a = 0xFFFFFFFFFF
        for p in ans:
            a &= int(p, 2)
        return a
    else:
        return 0

if __name__ == "__main__":
    l = input()
    N = int(l.split(" ")[0])
    K = int(l.split(" ")[1])
    As = [int(c) for c in input().split()]
    print(solve(N, K, As))


### FIXED CODE ###

def solve(N, K, As):
    alls = []
    for i in range(N):
        for j in range(i + 1, N + 1):
            alls.append("{:041b}".format(sum(As[i:j])))
    def find(i, alls):
        if i > 40:
            return []
        ones = [a for a in alls if a[i] == "1"]
        if len(ones) < K:
            return find(i + 1, alls)
        elif len(ones) == K:
            return ones
        elif len(ones) > K:
            ret = find(i + 1, ones)
            if len(ret) == 0:
                return ones[0:K]
            else:
                return ret

    ans = find(0, alls)
    if len(ans):
        a = 0xFFFFFFFFFFF
        for p in ans:
            a &= int(p, 2)
        return a
    else:
        return 0

if __name__ == "__main__":
    l = input()
    N = int(l.split(" ")[0])
    K = int(l.split(" ")[1])
    As = [int(c) for c in input().split()]
    print(solve(N, K, As))
### BUGGY CODE ###

import copy
from functools import reduce

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

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)
def gcd_array(a):#aは配列
  return reduce(gcd, a)

ans = 0
lst_t = []
for i in range(n):
  lst_t = copy.deepcopy(lst)
  del lst_t[i]
  x = gcd_array(lst_t)
  if ans < x:
    ans = x
  
print(ans)

### FIXED CODE ###

import fractions

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

ans = 0
left = [0]
right = [0] * (n+1)

for i in range(n):
  left.append(fractions.gcd(left[-1],lst[i]))
  right[n-1-i] = fractions.gcd(right[n-i],lst[n-1-i])

for i in range(n):
  x = fractions.gcd(left[i], right[i+1])
  if ans < x:
    ans = x
print(ans)
### BUGGY CODE ###

n=int(input())
l=list(set([int(input()) for d in range(n)]))  
a=l[0]
sd=0
for i in l[1:]:
  for h in range(min(i,a)+1)[:0:-1]:
    if (a%h,i%h)==(0,0):
      sd=h
      break
  a=a*i//sd
print(a)

### FIXED CODE ###

n=int(input())
l=list(set([int(input()) for d in range(n)]))  
a=l[0]
def gcd(a,s):
  a,s=min(a,s),max(a,s)
  if a==0:return s
  else:return gcd(s%a,a)

for i in l[1:]:
  a=a*i//gcd(a,i)
print(a)
### BUGGY CODE ###

n,k=(int(i) for i in input().split())

e = [[int(i) for i in input().split()] for j in range(n)]
#print(e)

dp=[[0 for i in range(k+1)] for j in range(n)]

for j in range(k+1):
    if j >= e[0][0]:
      dp[0][j]=e[0][1]

for i in range(1,n):
  for j in range(k+1):
    if j < e[i][0]:
      dp[i][j]=dp[i-1][j]
    else:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-e[i][0]]+e[i][1])

print(max(dp[n-1]))


### FIXED CODE ###

n,k=(int(i) for i in input().split())

e = [[int(i) for i in input().split()] for j in range(n)]
#print(e)

dp=[[0 for i in range(k+1)] for j in range(n+1)]

for i in range(n-1,-1,-1):
  for j in range(k+1):
    if j < e[i][0]:
      dp[i][j]=dp[i+1][j]
    else:
      dp[i][j]=max(dp[i+1][j],dp[i+1][j-e[i][0]]+e[i][1])

print(max(dp[0]))
### BUGGY CODE ###

#coding: UTF-8
import time
N=int(input())
lis=list(map(int, input().split()))
kind=set(lis)
kindn=len(kind)
#start_time=time.clock()
out=0
for i in kind:
    if lis.count(i)%2==0:
        out+=1
#stop_time=time.clock()
if out%2==0:
    print(kindn)
else:
    print(kindn-1)
#print(stop_time-start_time)

### FIXED CODE ###

#coding: UTF-8
import time
import collections
N=int(input())
lis=list(map(int, input().split()))
#kind=set(lis)
#kindn=len(kind)
kind_dict=collections.Counter(lis)
kindn=len(kind_dict)
out=0
for i in kind_dict:
    if kind_dict[i]%2==0:
        out+=1
if out%2==0:
    print(kindn)
else:
    print(kindn-1)
### BUGGY CODE ###

H,W = map(int,input().rstrip().split())
M = [[False for _ in range(W)]for _ in range(H)]
que = []
k = [0,0,0]
counter = 0
for i in range(H):
    S = input()
    for i2 in range(W):
        if S[i2] == "#":
            M[i][i2] = True
            que.append([i,i2,0])
while counter != H * W:
    k = que[counter]
    if(k[0] + 1 != H and M[k[0] + 1][k[1]] == False):
        M[k[0] + 1][k[1]] = True
        que.append([k[0] + 1,k[1],k[2] + 1])
    if(k[0] - 1 != -1 and M[k[0] - 1][k[1]] == False):
        M[k[0] - 1][k[1]] = True
        que.append([k[0] - 1,k[1],k[2] + 1])
    if(k[1] + 1 != W and M[k[0]][k[1] + 1] == False):
        M[k[0]][k[1] + 1] = True
        que.append([k[0],k[1] + 1,k[2] + 1])
    if(k[1] - 1 != -1 and M[k[0]][k[1] - 1] == False):
        M[k[0]][k[1] - 1] = True
        que.append([k[0],k[1] - 1,k[2] + 1])
    counter += 1
print(k[2])

### FIXED CODE ###

H,W = map(int,input().rstrip().split())
M = [[False for _ in range(W)]for _ in range(H)]
que = []
k = [0,0,0]
counter = 0
for i in range(H):
    S = input()
    for i2 in range(W):
        if S[i2] == "#":
            M[i][i2] = True
            que.append([i,i2,0])
while counter != H * W:
    k = que[counter]
    if(k[0] + 1 != H and M[k[0] + 1][k[1]] == False):
        M[k[0] + 1][k[1]] = True
        que.append([k[0] + 1,k[1],k[2] + 1])
    if(k[0] - 1 != -1 and M[k[0] - 1][k[1]] == False):
        M[k[0] - 1][k[1]] = True
        que.append([k[0] - 1,k[1],k[2] + 1])
    if(k[1] + 1 != W and M[k[0]][k[1] + 1] == False):
        M[k[0]][k[1] + 1] = True
        que.append([k[0],k[1] + 1,k[2] + 1])
    if(k[1] - 1 != -1 and M[k[0]][k[1] - 1] == False):
        M[k[0]][k[1] - 1] = True
        que.append([k[0],k[1] - 1,k[2] + 1])
    counter += 1
print(k[2])
### BUGGY CODE ###

import math
S = int(input())
a = math.ceil(S ** (1/2))
for i in range(1, a + 1):
  b = S / i
#  print(b)
  if b % 1 == 0 and b <= 10**9:
    print(0,0,0,i,int(b),0)
    exit()

### FIXED CODE ###

inf = 10**9
 
S = int(input())
 
if S == 10 ** 18:
    print(0, 0, inf, 0, inf, inf)
else:
    S1 = S // inf + 1
    S2 = inf - (S % inf)
 
    print(0, 0, S1, 1, S2, inf)
### BUGGY CODE ###

import sys
import numpy as np

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = [[0 if c == '.' else 1 for c in input().strip()] for _ in range(H)]

    A = np.array(A)
    B = np.array(np.nonzero(A))
    _, n = B.shape
    Bx = np.array([list(B[0])]*(H*W))
    By = np.array([list(B[1])]*(H*W))

    x = list(range(H)) * W
    x.sort()
    X = np.array([x]*n)

    y = list(range(W)) * H
    Y = np.array([y]*n)

    d = np.abs(X - Bx.T) + np.abs(Y - By.T)
    return np.max(np.min(d, axis=0))

if __name__ == '__main__':
    print(main())


### FIXED CODE ###

#ref: https://atcoder.jp/contests/agc033/submissions/5260580

import sys
import numpy as np

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    INF = H * W
    dp = [[INF if c == '.' else 0 for c in input().strip()] for _ in range(H)]
    dp = np.array(dp)

    for i in range(1, H):
        dp[i, :] = np.minimum(dp[i, :], dp[i-1, :] + 1)

    for i in range(H-2, -1, -1):
        dp[i, :] = np.minimum(dp[i, :], dp[i+1, :] + 1)

    for i in range(1, W):
        dp[:, i] = np.minimum(dp[:, i], dp[:, i-1] + 1)

    for i in range(W-2, -1, -1):
        dp[:, i] = np.minimum(dp[:, i], dp[:, i+1] + 1)

    return np.max(dp)

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

from collections import deque
s = list(input())
data = [0] * (len(s) + 1)
k = deque()
for i in range(len(s) + 1):
    l, r = i - 1, i
    while l >= 0:
        if s[l] != "<":
            break
        l -= 1
    while r < len(s):
        if s[r] != ">":
            break
        r += 1
    data[i] = max(i - l - 1, r - i)
print(sum(data))

### FIXED CODE ###

s = list(input())
data = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == "<":
        data[i + 1] = data[i] + 1

for i in range(len(s) - 1, -1, -1):
    if s[i] == ">":
        data[i] = max(data[i], data[i + 1] + 1) 
print(sum(data))
### BUGGY CODE ###

N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
for i in range(0,N):
    for j in range(i+1,N):
        if s[i] == s[j]:
            t +=1
print(t)



### FIXED CODE ###

N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
s = sorted(s)
t = 0
i = 0
while i<N:
    for j in range(i+1,N):
        if s[i]==s[j]:
            t = t+j-i
        else:
            break
    i = j
    if i==N-1:
        break
print(t)
### BUGGY CODE ###

import itertools

N,X,Y = map(int,input().split())
n = list(range(1,N+1))
m = []
l = []
for v in itertools.combinations(n,2):
  m.append(v)
for u in range((N*(N-1))//2):
  if m[u][1] - m[u][0] > abs(Y-m[u][1]) + abs(X-m[u][0]) + 1:
    l.append(abs(Y-m[u][1]) + abs(X-m[u][0]) + 1)
  else:
    l.append(m[u][1] - m[u][0])
    
for k in range(1,N):
  print(l.count(k))

### FIXED CODE ###

import itertools

N,X,Y = map(int,input().split())
n = list(range(1,N+1))
l = [0]*N
for v in itertools.combinations(n,2):
  l[min(abs(Y-v[1]) + abs(X-v[0]) + 1,v[1] - v[0])] += 1
for k in range(1,N):
  print(l[k])
### BUGGY CODE ###

from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N, M = makeMultiInteger(input_string[0])
    A = makeMultiInteger(input_string[1])
    S = makeIntMatrix(input_string[2:])
    cards = sorted(A)

    for s in S:
        b = s[0]
        c = s[1]
        for i in range(b):
            if c > cards[i]:
                cards[i] = c
            else:
                break
        cards = sorted(cards)
    return sum(cards)
    #else:
    #    return len(ra)



def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# from sys import exit
N, M = [int(n) for n in input().split()]
# N = int(input())
a = [(int(n), 1) for n in input().split()]
B = [0 for _ in range(M)]
C = [0 for _ in range(M)]
for i in range(M):
    B[i], C[i] = [int(n) for n in input().split()]
    a.append((C[i], B[i]))

a = sorted(a, key=lambda x: -x[0])
i = 0
ans = 0
# print(a)
while(N != 0):
    num = min(N, a[i][1])
    ans += num*a[i][0]
    # print(num*a[i][0])
    N -= num
    i += 1

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

def gcd(x,y):
  while (y):
    x, y = y, x%y
  return x

def tgcd(x,y,z):
  return gcd(x,gcd(y,z))

a = int(input())
s = 0
for i in range(1,a+1):
  for j in range(1,a+1):
    for k in range(1,a+1):
      s+=tgcd(i,j,k)
print(s)


### FIXED CODE ###

l=[1,9,30,76,141,267,400,624,885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,1691292,1726717,1782111,1827492,1887772,1925853,1986837,2033674,2089776,2145333,2197483,2246640,2332104,2379085,2434833,2490534,2554600,2609625,2693919,2742052,2813988,2875245,2952085,3003306,3096024,3157249,3224511,3306240,3388576,3444609,3533637,3591322,3693924,3767085,3842623,3912324,4027884,4102093,4181949,4270422,4361548,4427853,4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692]
print(l[int(input())-1])
### BUGGY CODE ###

import fractions
from functools import reduce

N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm, numbers, 1)         
         
lcm_ans = lcm_list(A)
ans = 0

for i in range(N):
  ans += (lcm_ans // A[i]) % MOD
  ans = ans % MOD
        
print(ans)         


### FIXED CODE ###

from fractions import gcd
from functools import reduce
 
N = int(input())
A = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
 
lcm = reduce(lambda x,y: x*(y//gcd(x,y)), A)
 
answer = sum(lcm//x for x in A)
answer %= MOD
print(answer)
### BUGGY CODE ###

S = input()
n = len(S)
DP = [- float('inf')] * (n + 1)
DP[0] = 0

for s in S:
    D = [-float('inf')] * (n + 1)
    for i in range(n):
        if s == 'g':
            if i == 0:
                D[i + 1] = max(D[i + 1], DP[i])
            else:
                D[i + 1] = max(D[i + 1], DP[i])
                D[i - 1] = max(D[i - 1], DP[i] + 1)
        if s == 'p':
            if i == 0:
                D[i + 1] = max(D[i + 1], DP[i] - 1)
            else:
                D[i + 1] = max(D[i + 1], DP[i] - 1)
                D[i - 1] = max(D[i - 1], DP[i])
    DP = D
print(max(DP))

### FIXED CODE ###

S = input()
N = len(S)

print(N // 2 - S.count('p'))
### BUGGY CODE ###

n, m, k = map(int, input().split())
connect = [[] for _ in range(n)]
cCnt = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    connect[a - 1].append(b - 1)
    cCnt[a - 1] += 1
    connect[b - 1].append(a - 1)
    cCnt[b - 1] += 1

group = [0 for _ in range(n)]
gNum = 0
import queue
for i in range(n):
    if group[i]:
        continue
    gNum += 1
    next = queue.Queue()
    for j in connect[i]:
        next.put(j)
    group[i] = gNum

    while not next.empty():
        j = next.get()
        group[j] = gNum
        for l in connect[j]:
            if not group[l]:
                next.put(l)

hunaka = [0 for i in range(n)]
for i in range(k):
    c, d = map(int, input().split())
    if group[c - 1] != group[d - 1]:
        continue
    hunaka[c - 1] += 1
    hunaka[d - 1] += 1

groupCnt = [0 for _ in range(gNum + 1)]
for i in group:
    groupCnt[i] += 1

for i in range(n):
    tmp = groupCnt[group[i]]
    tmp -= cCnt[i]
    tmp -= hunaka[i]
    tmp -= 1
    print(tmp, end = " ")

### FIXED CODE ###

n, m, k = map(int, input().split())
connect = [[] for _ in range(n)]
cCnt = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    connect[a - 1].append(b - 1)
    cCnt[a - 1] += 1
    connect[b - 1].append(a - 1)
    cCnt[b - 1] += 1

group = [0 for _ in range(n)]
gNum = 0
import queue
for i in range(n):
    if group[i]:
        continue
    gNum += 1
    next = queue.Queue()
    for j in connect[i]:
        group[j] = gNum
        next.put(j)
    group[i] = gNum

    while not next.empty():
        j = next.get()
        group[j] = gNum
        for l in connect[j]:
            if not group[l]:
                group[l] = gNum
                next.put(l)

hunaka = [0 for i in range(n)]
for i in range(k):
    c, d = map(int, input().split())
    if group[c - 1] != group[d - 1]:
        continue
    hunaka[c - 1] += 1
    hunaka[d - 1] += 1

groupCnt = [0 for _ in range(gNum + 1)]
for i in group:
    groupCnt[i] += 1

for i in range(n):
    tmp = groupCnt[group[i]]
    tmp -= cCnt[i]
    tmp -= hunaka[i]
    tmp -= 1
    print(tmp, end = " ")
### BUGGY CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
for _ in range(M):
  B,C = map(int,input().split())
  A += [C]*B
print(sum(sorted(A)[len(A)-N:]))

### FIXED CODE ###

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Ap = {}
for _ in range(M):
  B,C = map(int,input().split())
  if C in Ap.keys():
    Ap[C] = Ap[C]+B
  else:
    Ap[C] = B
Clist = sorted(Ap.keys())
nc = len(Clist)
i,j,k = 0,0,0
count = 0
a = A[N-1]
while i+j < N:
  if k<nc:
    c = Clist[nc-k-1]
    b = Ap[c]
  else:b,c = 0,0
  if a>=c:
    count += a
    i += 1
    a = A[N-i-1]
  elif c>a:
    count += b*c if i+j+b<N else c*(N-i-j)
    j += b
    k += 1
print(count)
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]
Al = list(set(A))
Al.sort(reverse = True)
HW = []
for i in Al:
  n = A.count(i)
  for j in range(min(n//2,2)):
    HW.append(i)
  if len(HW)>=2:
    break
HW = HW + [0,0]
print(HW[0]*HW[1])

### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse = True)
HW = []
i = 1
while i<N:
  if A[i]==A[i-1]:
    n = A.count(A[i])
    HW += [A[i]]*(min(n//2,2))
    i = i + n -1
  else:
    i = i + 1
  if len(HW)>=2:
    break
if len(HW)<2:
  print(0)
else:
  print(HW[0]*HW[1])
### BUGGY CODE ###

n = int(input())
s = [int(i) for i in input().split()]
S = sorted(set(s), key=s.index)
q = int(input())
t = [int(i) for i in input().split()]
T = sorted(set(t))

count = 0
for v in T:
    if v in S:
        count += 1
        S[:] = S[S.index(v)+1:]

print(count)

### FIXED CODE ###

n = int(input())
S = set(int(i) for i in input().split())
q = int(input())
T = set(int(i) for i in input().split())
print(len(S & T))