peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N, M = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
y = [list(map(int, input().split())) for _ in range(M)]
for a,b in x:
    z = [abs(a-c) + abs(b-d) for c,d in y]
    print(z.index(min(z))+1)
# Judge status: Accepted
N = int(input())
A = [int(input()) for c in range(N)]
A = sorted(A)

tmp = 1
cnt = 0
for i in range(N):    
    if i+1<N:
        if A[i] == A[i+1]:
            tmp += 1
        else:
            cnt += tmp%2
            tmp = 1
    else:
        cnt += tmp%2

print(cnt)
# Judge status: Wrong Answer
import statistics

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

bi = []
for i in range(n):
    bi.append(a[i] - (i + 1))

b = statistics.median(bi)

ans = 0
for i in range(n):
    ans += int(abs(bi[i] - b))

print(ans)
# Judge status: Accepted
x_n =list(map(int,input().split()))
for i in range(5):
    if x_n[i]==0:
        print(i+1)
# Judge status: Accepted
L = int(input())
print((L/3)**3)
# Judge status: Accepted
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])

ans = 0
mod = pow(10, 9)+7
for i in range(100):
  c = np.sum((a>>i)&1)
  ans += (c*(n-c)%mod)*pow(2, i, mod)%mod
  ans %= mod

print(ans)
# Judge status: Accepted
a, b, c = map(int, input().split())
if a - b >= c:
    x = 0
else:
    x = c - a + b
print(int(x))
# Judge status: Wrong Answer
n = int(input())
p = list(map(int, input().split()))
nl = list(range(n, 0, -1))
if nl == p:
    print("YES")
    exit()
res = []
for i in range(n):
    if p[i] != nl[i]: 
        res.append(i)
if len(res) == 2:
    if nl[res[0]] == res[1]+1 and nl[res[1]] == res[0]+1:
        print("YES")
        exit()
print("NO")
# Judge status: Accepted
A = [int(_) for _ in input().split()]

if len(set(A)) == 2:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n = int(input())
s = input()

an = s.count('R') *s.count('G') *s.count('B')

for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j-i
        if (k<n) and (s[i]!=s[j]) and (s[j]!=s[k])and(s[i]!=s[k]):
                an -= 1

print(an)
# Judge status: Accepted
n, m = map(int, input().split())

end = n
dif = set()
count = 0
for i in range(1, n+1):
    while end-i in dif or n+i-end in dif or end-i == n+i-end:
        end -= 1
    print(i, end)
    dif.add(end-i)
    dif.add(n+i-end)
    end -= 1
    count += 1
    if count == m:
        break
# Judge status: Accepted
S=[i for i in input()]
n=len(S)
for i in range(2,n-2+1,2):
  m=int((n-i)/2)
  SF=S[0:m]
  SR=S[m:m*2]
  if SF==SR:
    #print(SF,SR)
    print(len(SF+SR))
    break
# Judge status: Accepted
n, k = map(int, input().split())
ab = [int(input()) for _ in range(n)]

sab = sorted(ab)

res = 10**10

for i in range(n-k+1):
    res = min(res,sab[i+k-1]-sab[i])

print(res)
# Judge status: Wrong Answer
n = int(input())
print(n%1000)
# Judge status: Accepted
def resolve():
    s = input()
    if s[-1] == "s":
        print(s + "es")
    else:
        print(s+"s")
resolve()
# Judge status: Wrong Answer
def main():
    n, m = map(int, input().split())
    n -= 1
    m -= 1
    e = 0
    while n > 0:
        e += n
        print(n)
        n -= 1
    while m > 0:
        e += m
        m -= 1
    print(e)
 
main()
# Judge status: Wrong Answer
n,m = map(int ,input().split())
l=[list(map(int ,input().split())) for x in range(n)]
cnt=0
ans=0
if n==1:
    print(l[0][0])
    exit()
    
for i in range(n):
    del(l[i][0])

for i in range(n):
    cnt=0
    for j in range(1,m+1):
        if j in l[i]:
            cnt+=1
    
    if cnt==n:
        ans+=1
print(ans)
# Judge status: Accepted
#InfiniteCoins
n = int(input())
a = int(input())

r = n % 500
if r <= a:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
import math
a, b = list(map(int, input().split()))
a,b = 5,5
print(math.ceil((a+b)/2))
# Judge status: Wrong Answer
s=input()
if s=='SUN':
    print(7)
if s=='MON':
    print(6)
if s=='TUE':
    print(5)
if s=='WED':
    print(4)
if s=='THU':
    print(3)
if s=='FRI':
    print(2)
else:
    print(1)
# Judge status: Accepted
import numpy as np
n = int(input())
hList = np.array(list(map(int, input().split())))
mFlag = np.diff(hList) <= 0
#bFlag = False
cnt=0
ret =0
for f in mFlag:
    if f:
        cnt += 1
        if( ret<cnt):
            ret = cnt
    else:
        cnt=0
    
print(ret)
# Judge status: Accepted

N,K = map(int,input().split())
S,A = divmod(N,K)
print(min(A,abs(A-K)))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
sum = 0
for i in range(n):
    sum = sum + a[i*2+1]
print(sum)
# Judge status: Accepted
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict

geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

N = gete(int)
a1, a2, i1 = 0, -1, -1

for i in range(N):
    ai = gete(int)
    if ai >= a1:
        a1, a2 = ai, a1
        i1 = i
    elif ai >= a2:
        a2 = ai

if a1 == a2:
    print(*[a1] * N, sep="\n")
else:
    print(*[a2 if i == i1 else a1 for i in range(N)], sep="\n")
# Judge status: Accepted
import numpy as np
from numba import njit

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

@njit
def main(N, K, A):
  for _ in range(min(K, 42)):
    A_ = np.zeros_like(A)
    for n in range(N):
      A_[max(0, n - A[n])] += 1
      if n + A[n] + 1  < N:
        A_[n + A[n] + 1] -= 1
    A = A_.cumsum()
        
  return A

print(*main(N, K, A))
# Judge status: Wrong Answer
import math
x,y=map(int,input().split())
print(math.floor(math.log2(y//x))+1)
# Judge status: Accepted
n, a, b = map(int, input().split())

q = n // (a + b)

x = a * q

w = n % (a + b)
if w >= a:
    y = a
else:
    y = w

ans = x + y

print(ans)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))

t=sum(a)
m=10**9
flag=0
for i in range(len(a)-1):
    t-=2*a[i]
    m=min(abs(t),m)
print(m)
# Judge status: Accepted
k = int(input())
s = input()

if len(s) <= k:
    print(s)
else:
    print(f"{s[:k]}...")
# Judge status: Accepted
N,K = map(int, input().split())
print(-(-(N-1)//(K-1)))
# Judge status: Accepted
A = int(input())
p = A % 10
A //= 10
q = A % 10
A //= 10
r = A % 10
s = A // 10
if p == q == r or q == r == s:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
n = int(input())
res = 0
for i in range(n + 1):
  if len(str(i)) % 2 == 1:
    res += 1
print(res)
# Judge status: Accepted
s, t = map(str, input().split())
a, b = map(int, input().split())
u = str(input())

if u == s:
    print(a - 1, b)
elif u == t:
    print(a, b - 1)
# Judge status: Accepted
a,b,c = map(int, input().split())
k = int(input())
x = 0
while b <= a:
    b *= 2
    x += 1
while c <= b:
    c *= 2
    x += 1
if x <= k:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n=int(input())
h=list(map(int,input().split()))

ans=0
tmp=0
for i in range(n-1):
  if h[i] >= h[i+1]:
    tmp+=1
    ans=max(ans,tmp) 
  else:
    tmp=0
print(ans)
# Judge status: Accepted
#ABC172 C Tsundoku 22:34
from itertools import accumulate

n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
s_A = [0]+list(accumulate(A))
s_B = [0]+list(accumulate(B))

ans,j = 0, m
for i in range(n+1):
    if s_A[i] > k: break
    while s_B[j] > k - s_A[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
# Judge status: Wrong Answer
import itertools
n=int(input())
pp=input().split()
qq=input().split()
p=[]
q=[]
p.append(pp)
q.append(qq)
a=[]
for v in itertools.permutations(pp,n):
    a.append(v)
a=sorted(a)
for j in range(len(a)):
  a[j]=list(a[j])

b=0
c=0
for i in range(len(a)):
  if a[i]==pp:
    b+=i
  elif a[i]==qq:
    c+=i
print(max(b-c,c-b))
# Judge status: Wrong Answer
import numpy as np
A,B,H,M = map(int,input().split())

th_a = 30 * H
th_b = 6 * M

theta = th_a - th_b

C = np.sqrt(A**2 + B**2 - 2*A*B*np.cos(theta))
# Judge status: Accepted
n = [input() for i in range(int(input()))]
m = [input() for i in range(int(input()))]
words = list(set(n))
print(max(0,max(n.count(words[i])-m.count(words[i]) for i in range(len(words)))))
# Judge status: Wrong Answer
W,H,N = map(int,input().split())
x_r = W
x_l = 0
y_r = H
y_l = 0

for _ in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        x_l = max(x,x_l)
    elif a == 2:
        x_r = min(x,x_r)
    elif a == 3:
        y_l = max(y,y_l)
    else:
        y_r = min(y,y_r)

print(max(0,(x_r-x_l)*(y_r-y_l)))
# Judge status: Accepted
lst = input()
lst = lst.split()


for i in range(len(lst)):
    lst[i]= int(lst[i])
N = lst[0]
L = lst[1]
q = L
l = 0
lste = [abs(L)]
tlst = []
for i in range(2,N+1):
    t = L+i-1
    q += t
    tlst.append(t)
    t = abs(t)
    lste.append(t)


slst = sorted(lste)
l = slst[0]
if tlst.count(-l) > 0:
    print(q+l)
else:
    print(q-l)
# Judge status: Accepted
N, M = tuple(int(n) for n in input().split())

As = [int(n) for n in input().split()]

for A in As:
    N -= A

print(max(N, -1))
# Judge status: Accepted
X = int(input())
print(1000*(X//500) + 5*((X%500)//5))
# Judge status: Accepted
n = int(input())
s = list(map(int,input().split()))
print(min([abs(sum(s[:i+1]) - sum(s[i+1:])) for i in range(n)]))
# Judge status: Accepted
N,Q =map(int,input().split())
S = input()
lr = [list(map(int,input().split())) for _ in range(Q)]

ans = 0
ans_ls = []
ans_ls.append(0)

for n in range(N-1):
  if S[n] == "A" and S[n+1] =="C":
    ans += 1
  ans_ls.append(ans)

for q in range(Q):
  print(ans_ls[lr[q][1]-1]-ans_ls[lr[q][0]-1])
# Judge status: Accepted
import sys
readline = sys.stdin.buffer.readline
MOD = 10**9+7
INF = float('inf')

def main():
    S = input()
    T = input()
    L = len(S)
    bl = False
    for i in range(L):
        s = S[-i:] + S[:-i]
        if T == s:
            bl = True
    print('Yes' if bl else 'No')





if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
N = int(input())
ans = 0
if N % 2 == 1:
    print(ans)
else:
    for i in range(1, 20):
        a = N // (2 * (5**i))
        ans += a
        if a == 0:
            break
    print(ans)
# Judge status: Wrong Answer
p,q,r = map(int,input().split())
print(min(p+q,q+r,r+q))
# Judge status: Accepted
n,c,k = map(int,input().split())
t = [0]*n
for i in range(n):
    t[i] = int(input())
t = sorted(t)
ans = 0
s = 0
u = float("Inf")
for i in range(n-1):
    s += 1
    u = min(u, t[i])
    if s == c or t[i+1] > u + k:
        ans += 1
        s = 0
        u = float("Inf")
print(ans+1)
# Judge status: Wrong Answer
n = int(input())
ans = {'AC': 0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(n):
    s = input()
    ans[s] = ans[s] + 1

for s in ans.keys():
    print("{} × {}".format(s, ans[s]))
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))
a.sort()
s = [0]*(a[-1]+1)
for i in range(n):
    s[a[i]] += 1
ans = 0
for i in range(2,a[-1]):
    ans = max(ans, s[i] + s[i-1] + s[i+1])
print(ans)
# Judge status: Accepted
x, y = map(int, input().split())
ans = x + y // 2
print(ans)
# Judge status: Accepted
def main():
    N = int(input())
    mod = 10 ** 9 + 7
    return (pow(10, N, mod) - pow(9, N, mod) - pow(9, N, mod) + pow(8, N, mod)) % mod

print(main())
# Judge status: Accepted
X,K,D=map(int,input().split())
if X<0:
  X*=-1
if X-K*D>0:
  print(X-K*D)
else:
  p=X-(X//D)*D
  K-=X//D
  q=abs(p-D)
  if K%2==0:
    print(p)
  else:
    print(q)
# Judge status: Wrong Answer
s,t=input().split()
a,b=map(int,input().split())
u=input()
if s==u:
  print(a-1,b)
elif s==t:
  print(a,b-1)
# Judge status: Wrong Answer
otoshidama = list(map(int,input().split()))
flg = True
for i in range(otoshidama[0]):
    yukichi =i
    for n in range(otoshidama[0]-yukichi):
        higuchi = n
        noguchi = otoshidama[0] - yukichi - higuchi

        if 10000*yukichi+5000*higuchi+1000*noguchi==otoshidama[1]:
            print("{} {} {}".format(yukichi,higuchi,noguchi))
            flg = False

if flg:
    print("-1 -1 -1")
# Judge status: Wrong Answer
a=list(input())
b =len(a)


if  a[b-1]==2 or a[b-1]==4 or a[b-1]==5 or a[b-1]==7 or a[b-1]==9 :  #abが２で割り切れたら、Evenと入力
    print('hon')  

elif a[b-1]==0 or a[b-1]==1 or a[b-1]==6 or a[b-1]==8  :
    print('pon')
    
else :           #それ以外なら,Oddと入力
    print('bon')
# Judge status: Wrong Answer
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop

import collections

a,b = map(int,input().split())
if a>9  or b >9:
    print(":(")
else:
    print("Yay!")
# Judge status: Accepted
if int(input()):
    print(0)
else:
    print(1)
# Judge status: Accepted
n=int(input())
s=list(input())
ins=0
app=0
for i in range(n):
    if s[i]=='(':
        app += 1
    else:
        if app>0:
            app -= 1
        else:
            ins += 1
inL=['(']*ins
app=[')']*app
ans=inL+s+app
print(''.join(ans))
# Judge status: Wrong Answer
s = input()
if s[len(s) - 1] == 's':
  print(s[:len(s) - 1] + 'es')
else:
  print(s + 's')
# Judge status: Accepted
n = int(input())
c = 0
for p in range(2, int(n**0.5)+1): #nが合成数
  e = 0
  while n%p == 0:
    n //= p
    e += 1
  i = 1
  while e >= i:
    e -= i
    c += 1
    i += 1
if n != 1: #nが素数 or nがn^0.5より大きい素数を因数に持つ合成数
  c += 1
print(c)
# Judge status: Wrong Answer
k, x = map(int, input().split())
a = x-k+1
b = x+k-1
print(i for i in range(a, b+1))
# Judge status: Wrong Answer
k, n = map(int, input().split())
ls = list(map(int, input().split()))

distance_list = []

i = 0
while i < n:
    if i == 0:
        distance_list.append(ls[i])
        i += 1
        continue
    distance_list.append(ls[i] - ls[i-1])
    i += 1

distance_list.append(k - ls[n-1])
distance_list.remove(max(distance_list))
if 0 not in distance_list:
    distance_list.remove(max(distance_list))
print(sum(distance_list))
# Judge status: Accepted
N, W = map(int, input().split())
w_list = []
v_list = []
for i in range(N):
    w, v = map(int, input().split())
    w_list.append(w)
    v_list.append(v)
dp = [[0 for i in range(W+1)] for i in range(N)]
for i in range(N):
    w = w_list[i]
    v = v_list[i]
    for j in range(W+1):
        if j-w >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
        else:
            dp[i][j] = dp[i-1][j]
print(dp[N-1][W])
# Judge status: Accepted
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

food = []

for _ in range(5):
    food.append(inint())

all = sum(food)
loss = []

for f in food:
    loss_t = 200
    for i in range(0,131, 10):
        if 0 <= i-f < loss_t:
            loss_t = abs(f-i)
    loss.append(loss_t)

print(all+sum(loss)-max(loss))
# Judge status: Accepted
N = int(input())
ans = ''
for _ in range(1000):
    r = N % 2
    if r < 0:
        r += 2
    N = (N-r)//(-2)
    ans = str(r) + ans
print(int(ans))
# Judge status: Accepted
N,M=map(int,input().split())

ans=0
if 2*N<=M:
    ans=N+(M-2*N)//4
else:
    b=M//2
    ans=b
print(ans)
# Judge status: Accepted
n, m = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
lst = [True]*n
for _ in range(m):
    a, b = [int(i) for i in input().split()]
    if h[a-1] > h[b-1]:
        lst[b-1] = False
    elif h[a-1] < h[b-1]:
        lst[a-1] = False
    elif h[a-1] == h[b-1]:
        lst[a-1] = False
        lst[b-1] = False
ans = 0
for i in lst:
    if i:
        ans += 1
print(ans)
# Judge status: Accepted
H1,M1,H2,M2,K=map(int,input().split())

HM1=H1*60+M1
HM2=H2*60+M2
print(max(HM2-HM1-K,0))
# Judge status: Accepted
N = int(input())
p = 1
for i in range(N):
    p = (p*(i+1))%(10**9+7)
print(p)
# Judge status: Accepted
A, B, C, D = map(int, input().split())
d = min(B,D) - max(A,C)
if d < 0:
    print(0)
else:
    print(d)
# Judge status: Accepted
n, m = map(int, input().split())
ans = 1

if abs(n - m) > 1:
    print(0)
    exit()

for i in range(1, n + 1):
    ans = ans*i%(10**9 + 7)

for i in range(1, m + 1):
    ans = ans*i%(10**9 + 7)

if (n + m)%2 == 0:
    ans = ans*2%(10**9 + 7)

print(ans)
# Judge status: Accepted
A,B=map(int,input().split())
if ((A+B)<24):
    print (A+B)
else:
    print ((A+B)-24)
# Judge status: Accepted

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

cnt=0
for i in range(N):
    if (i+1)%2==1 and a[i]%2==1:
        cnt+=1

print(cnt)
# Judge status: Accepted
d, n = map(int,input().split())
print( (n+1)*100**d if n%100==0 else n*100**d)
# Judge status: Wrong Answer
N,K=map(int,input().split())
a=list(map(int,input().split()))
index=a.index(1)
l=index
r=index
cnt=0
while l!=0:
  l=max(0,l-K+1)
  cnt+=1
while r!=N-1:
  r=min(N-1,r+K-1)
  cnt+=1
print(cnt)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

if 1 not in a:
    print(-1)
    exit()

now = 1
ans = 0
for i in a:
    if i != now:
        ans += 1
    else:
        now += 1

print(ans)
# Judge status: Accepted
n=int(input())
a=[]
b=[]
for i in range(n):
    aa,bb=map(int,input().split())
    a.append(aa)
    b.append(bb)

ans=0

for ii in range(n):
    i=n-ii-1
    aa=a[i]
    bb=b[i]
    ama=(bb-(aa+ans)%bb)%bb
    ans+=ama

print(ans)
# Judge status: Accepted
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

diff = [0] * n
for i in range(n):
    diff[i] = abs(a - (t - (h[i] * 0.006)))

print(diff.index(min(diff)) + 1)
# Judge status: Accepted
n,a,b=map(int, input().split())
s=input()

for i in range(n):

    if (a>0 or b>0) and s[i]=='a':
        print('Yes')
        if a>0 and b>=0:
            a-=1
        else:
            b-=1

    elif b>0 and s[i]=='b':
        print('Yes')
        b-=1
    else:
        print('No')
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
MINUS = 0
B = []

for i in A:
  if i < 0:
    MINUS += 1
  else:
    B.append(i)
  
if min(A) > 0:
  print(sum(A))
  exit(0)
  
ans = 0
if MINUS % 2 == 0:
  for a in A:
    ans += abs(a)
else:
  minB = max(A)
  for a in A:
    ai = abs(a)
    if ai < minB:
      minB = ai
    ans += ai
  ans -= minB

print(ans)
# Judge status: Wrong Answer
A, B, C = map(int, input().split())
cnt = 0
flag_cnt=0
while(1):
    A_tmp = A
    B_tmp = B
    C_tmp = C
    A = (B_tmp+C_tmp)/2
    B = (A_tmp+C_tmp)/2
    C = (A_tmp+C_tmp)/2
    cnt += 1
    if A%2!=0 or B%2!=0 or C%2!=0:
        break
    if A_tmp==A and B_tmp==B and C_tmp==C:
        flag_cnt+=1
        if flag_cnt==2:
            cnt = -1
            break
print(cnt)
# Judge status: Accepted
import sys,math,collections,itertools
input = sys.stdin.readline

N,M=list(map(int,input().split()))
mn = M//N
ml = M%N
if ml == 0:
    print(mn)
    exit()
ans = 0
for i in range(mn+1,0,-1):
    if i < ans:
        break
    tmp = math.gcd(i,M-i*(N-1))
    ans = max(ans,tmp)
print(ans)
# Judge status: Wrong Answer
n = input()
nlist =list(n)

if 9 in nlist:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N = int(input())

A = [int(s) for s in input().split()]

MOD = 10**9 + 7
sums = [A[0]]
for a in A[1:]:
    sums.append((a + sums[-1]) % MOD )

alls = 0
for i in range(1, len(A)):
    # print(A[i], sums[i-1])
    alls += A[i] * sums[i-1]
    alls %= MOD
print(alls)
# Judge status: Accepted
import math
a,b=map(int,input().split())
if (a+b)%2==0:
    print(math.floor(abs((a-b)/2)+min(a,b)))
else:
    print("IMPOSSIBLE")
# Judge status: Accepted
N, A, B = map(int, input().split())
if A > (N % (A + B)):
    print((N // (A + B)) * A + N % (A + B))
else:
    print((N // (A + B)) * A + A)
# Judge status: Accepted
X, Y = map(int, input().split())
flag = False
for tsuru in range(X+1):
    kame = X - tsuru
    if kame*4 + tsuru*2 == Y:
        flag = True
        break

if flag:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))
a.sort()
print(sum(a[n:n+n]))
# Judge status: Wrong Answer
a,b=(map(int,input().split()))
if 0<a<=b:
    print('Positive')
elif a<=0<=b:
    print('0')
elif a<=b<0:
    x=b-a+1
    if x%2==0:
        print('Positive')
    else:
        print('Negative')
# Judge status: Accepted
import math
def main():
	n ,d = map(int,input().split())
	arr = [ ]
	for _ in range(n):
		arr.append(list(map(int,input().split())))
	ans = 0
	for i in range(n):
		for j in range(i+1,n):
			cnt  = 0	
			for k in range(d):
				cnt += (arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k])
			if math.sqrt(cnt)==int(math.sqrt(cnt)):
				ans+=1
	print(ans)
	return



main()
# Judge status: Accepted
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()

def main():
    N=ii()
    A = list(mi())

    counter = [0]*(10**5+5)

    for a in A:
        counter[a] += 1

    ans = sum(A)

    Q=ii()
    for q in range(Q):
        B,C=mi()
        ans -= B * counter[B]
        ans += C * counter[B]

        counter[C] += counter[B]
        counter[B] = 0
        print(ans)




if __name__ == "__main__":
  main()
# Judge status: Accepted
def ans(N, Y):
    for m in range(N + 1):
        for g in range(N + 1 - m):
            s = N - m - g
            sum = m * 10000 + g * 5000 + s * 1000
            if sum == Y:
                return m, g, s
    return -1, -1, -1

def read():
    N, Y = [int(a) for a in input().split(' ')]
    return N, Y

def write(a):
    print(a[0], a[1], a[2])

if __name__ == '__main__':
    N, Y = read()
    write(ans(N, Y))
# Judge status: Accepted
sx,sy,tx,ty=map(int,input().split())
ans=""
for i in range(ty-sy):ans+="U"
for i in range(tx-sx):ans+="R"
for i in range(ty-sy):ans+="D"
for i in range(tx-sx):ans+="L"
ans+="L"
for i in range(ty-sy+1):ans+="U"
for i in range(tx-sx+1):ans+="R"
ans+="D"
ans+="R"
for i in range(ty-sy+1):ans+="D"
for i in range(tx-sx+1):ans+="L"
ans+="U"
print(ans)
# Judge status: Accepted
w, h, n = map(int, input().split())
W = [0, w]
H = [0, h]
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1 and W[0] < x:
        W[0] = x
    elif a == 2 and W[1] > x:
        W[1] = x
    elif a == 3 and H[0] < y:
        H[0] = y
    elif a == 4 and H[1] > y:
        H[1] = y

if W[1]-W[0] < 0 or (H[1]-H[0]) < 0:
    print(0)
else:
    print((W[1]-W[0]) * (H[1]-H[0]))
# Judge status: Accepted
A,B,K = map(int,input().split())

ans_lst = []
for i in range(1,min(A,B)+1):
    if A%i==0 and B%i==0:
        ans_lst += [i]
ans_lst.reverse()
print(ans_lst[K-1])
# Judge status: Wrong Answer
values = input().split()
print(values)

num_animals = int(values[0])
num_legs = int(values[1])

max_possible_legs = num_animals*4
min_possible_legs = num_animals*2

if num_legs%2 != 0:
    print ("No")

elif (num_legs <= max_possible_legs) and (num_legs >= min_possible_legs):
    print("Yes")

else:
    print("No")
# Judge status: Accepted
N = int(input())
alp = "abcdefghijklmnopqrstuvwxyz"
output = ""
while N>0:
  N -= 1
  output += alp[N%26]
  N = N//26
  
print(output[::-1])
# Judge status: Accepted
A, B = input().split()
A = int(A)
C = int(B[0])*100 + int(B[2])*10 + int(B[3])
print(A*C//100)
# Judge status: Accepted
w=input()

for i in w:
    if w.count(i)%2!=0:
        print("No")
        exit()

print("Yes")
# Judge status: Accepted
h, a = map(int, input().split())
print(h // a if h % a == 0 else h // a + 1)
# Judge status: Accepted
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
n = len(s)
ans = 'Yes'
if s != s[::-1]:
    ans = 'No'
x = math.floor(n/2)
y = math.ceil(n/2)
a = s[0:x]
b = s[y:]
if a != a[::-1] or b != b[::-1]:
    ans = 'No'
print(ans)
# Judge status: Wrong Answer
n, d = map(int, input().split())
distances = [list(map(int, input().split())) for _ in range(n)]
ans = 0

for i in range(n):
    for j in range(i + 1, n):
        diff_total = 0
        for k in range(d):
            diff = abs(distances[i][k] - distances[j][k])
            diff_total = diff * diff

        flag = False
        for k in range(diff_total + 1):
            if (k ** 2) == diff_total:
                flag = True
        if flag:
            ans += 1
print(ans)