Harryxun/stf_run huggingface dataset:
n=int(input())
a=list(map(int,input().split()))
q=int(input())

summ=sum(a)
num=[a.count(i) for i in range(1,100000)]
for i in range(q):
    b,c=map(int,input().split())
    b_num=num[b]
    num[c] += num[b]
    num[b]=0
    summ +=(c-b)*b_num
    print(summ)

### FIXED CODE ###

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

summ=sum(a)
num=[0 for i in range(10**5+1)]
for i in range(n):
    num[a[i]] += 1
for i in range(q):
    b,c=map(int,input().split())
    b_num=num[b]
    num[c] += b_num
    num[b]=0
    summ +=(c-b)*b_num
    print(summ)
from math import sqrt
from itertools import product

import numpy as np

def helper(N,D):
  if D%2 == 1:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
    grid[:,1::2] = ~grid[:,1::2]
  elif D%4 == 2:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
  else:
    M = (N-1)//2+1
    D //= 4
    g = helper(M, D)
    grid = np.zeros((M,M),dtype=bool)
    grid[::2,::2] = g
    grid[1::2,::2] = g
    grid[::2,1::2] = g
    grid[1::2,1::2] = g
    grid = grid[:N,:N]
  return grid


N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N*2,D1)
g2 = helper(N*2,D2)
ans = g1&g2


for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)


### FIXED CODE ###

from math import sqrt
from itertools import product

import numpy as np

def helper(N,D):
  if D%2 == 1:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
    grid[:,1::2] = ~grid[:,1::2]
  elif D%4 == 2:
    grid = np.zeros((N,N),dtype=bool)
    grid[::2,:] = True
  else:
    M = (N-1)//2+1
    D //= 4
    g = helper(M, D)
    grid = np.zeros((2*M,2*M),dtype=bool)
    grid[::2,::2] = g
    grid[1::2,::2] = g
    grid[::2,1::2] = g
    grid[1::2,1::2] = g
    grid = grid[:N,:N]
  return grid


N,D1,D2 = map(int,input().split())
M = N*2
g1 = helper(N*2,D1)
g2 = helper(N*2,D2)
ans = g1&g2


for x,y in np.transpose(np.nonzero(ans))[:N*N]:
  print(x,y)
hoe

### FIXED CODE ###

import sys
import time
#1.2 2.8 4.12 1.5 3.0 4.5
for line in sys.stdin:
    a1,b1,c1,a2,b2,c2 = map(float,line.split())
    i=0
    x = (c1*b2-c2*b1) / (a1*b2-a2*b1)
    y = (a1*c2-a2*c1) / (a1*b2-a2*b1)
    if "-0" in str(x):
        x = 0.0
    print "%.3f %.3f"%(x,y)
K, X = map(int, input().split())
 for i in range(X - K + 1, X + K):
 if i < X + K - 1:
 print(i, end=' ')
 else:
 print(i)

### FIXED CODE ###

a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))
print(input().replace(',',' ')

### FIXED CODE ###

print(input().replace(',',' '))
N, X=map(int, input().split())
ans=[]
for _ in range(X-N+1, X+N):
  ans.append(_)
print(" ".join(ans))

### FIXED CODE ###

N, X=map(int, input().split())
ans=[]
for _ in range(X-N+1, X+N):
  ans.append(str(_))
print(" ".join(ans))
N=int(input())
a=0
b=0
c=0
d=0
for i in range(N):
    if input()=="AC":
        a+=1
    elif input()=="WA":
        b+=1
    elif input()=="TLE":
        c+=1
    else:
        d+=1
print("AC ×",a)
print("WA ×",b)
print("TLE ×",c)
print("RE ×",d)

### FIXED CODE ###

N=int(input())
a=0
b=0
c=0
d=0
for i in range(N):
    A=input()
    if A=="AC":
        a+=1
    elif A=="WA":
        b+=1
    elif A=="TLE":
        c+=1
    else:
        d+=1
print("AC x",a)
print("WA x",b)
print("TLE x",c)
print("RE x",d)
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
lcm = A[0]
for i in range(1,N):
    lcm = (lcm*A[i])//gcd(lcm,A[i])

MOD = 10**9+7
ans = 0
for a in A:
    b = lcm//a
    ans += b
print(ans%MOD)

### FIXED CODE ###

N,M = map(int,input().split())
if N == M:
    print('Yes')
else:
    print('No')
S = list(str(input()))
if S[0]==S[1]==S[2]==S[3:
    print('No')]
elif (S[0]==S[1]) and (S[2]==S[3]):
    print('Yes')
elif (S[0]==S[2]) and (S[1]==S[3]):
    print('Yes')
elif (S[0]==S[3]) and (S[1]==S[2]):
    print('Yes')
else:


### FIXED CODE ###

S = list(str(input()))
if (S[0]==S[1]) and (S[0]==S[2]) and (S[0]==S[3]):
    print('No')
elif (S[0]==S[1]) and (S[2]==S[3]):
    print('Yes')
elif (S[0]==S[2]) and (S[1]==S[3]):
    print('Yes')
elif (S[0]==S[3]) and (S[1]==S[2]):
    print('Yes')
else:
    print('No')
N,K=map(int,input().split())
h_i=(int(x) for x in input().split())
count=0
for i in range(N):
  if h_i[i] => K:
    count+=1
print(count)

### FIXED CODE ###

N,K=map(int,input().split())
h_i=list(int(x) for x in input().split())
count=0

for i in range(N):
  if h_i[i] >= K:
    count+=1
print(count)
S = str(input())
A = S.split()

for i in A:
    if A[i] == A[i + 1]:
        print('Bad')
    else:
        print('Good')


### FIXED CODE ###

S = input()

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
    print('Bad')
else:
    print('Good')
N,P=list(map(int,input().split()))
 
root=P**(1/N)
x=round(root)
 
if n==1:
    print(p)
else:
	for i in range(x):
		if P%((x-i)**N)==0:
			print(x-i)
			break

### FIXED CODE ###

N, P = map(int, input().split())
ans = 1
 
if N >= 45:
  print(ans)
elif N == 1:
  print(P)
  
 
  
else:
  i = 1
  while(i**N <= P):
    if P % (i**N) == 0:
      ans = i
    i += 1
  print(ans)
N = int(input())
b_list = list(map(int,input().split()))
s = True
if (b_list[0] > 1):
  b_list -= 1
for i in range(1,len(b_list)):
  if (b_list[i-1] < b_list[i]):
    b_list[i] -= 1
for i in range(len(b_list)-1):
  if (b_list[i] > b_list[i+1]):
    s = False
if (s):
  print('Yes')
else:
  print('No')
  

### FIXED CODE ###

N = int(input())
b_list = list(map(int,input().split()))
s = True
if (b_list[0] > 1):
  b_list[0] -= 1
for i in range(1,len(b_list)):
  if (b_list[i-1] < b_list[i]):
    b_list[i] -= 1
for i in range(len(b_list)-1):
  if (b_list[i] > b_list[i+1]):
    s = False
if (s):
  print('Yes')
else:
  print('No')
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate
import sys
import bisect

sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
lmsi = lambda: list(map(str, input().split()))
smii = lambda: sorted(map(int, input().split()))

# ----------

N, K = mii()

X, Y = [], []
for i in range(N):
    x, y = mii()
    X.append(x)
    Y.append(y)

ans = INF

for left in range(N):
    for right in range(N):
        for top in range(N):
            for bottom in range(N):
                if X[right]-X[left] <= 0:
                    continue
                if Y[top]-Y[bottom] <= 0:
                    continue
                cnt = 0
                for i in range(N):
                    if X[left] <= X[i] <= X[right] and Y[bottom] <= Y[i] <= Y[top]:
                        cnt += 1
                if cnt >= K:
                    ans = min(ans, (X[right]-X[left])*(Y[top]-Y[bottom]))

print(ans)




### FIXED CODE ###

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

X, Y = [], []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

ans = float('INF')

for left in range(N):
    for right in range(N):
        for top in range(N):
            for bottom in range(N):
                if X[right]-X[left] <= 0:
                    continue
                if Y[top]-Y[bottom] <= 0:
                    continue
                cnt = 0
                for i in range(N):
                    if X[left] <= X[i] <= X[right] and Y[bottom] <= Y[i] <= Y[top]:
                        cnt += 1
                if cnt >= K:
                    ans = min(ans, (X[right]-X[left])*(Y[top]-Y[bottom]))

print(ans)
s = sorted(input())
t = reversed(sorted(input()))
print('Yes' if s<t else 'No')

### FIXED CODE ###

s = sorted(list(str(input())))
t = reversed(sorted(list(str(input()))))
S = str()
T = str()
for i in s:
    S += i
for k in t:
    T += k
print('Yes' if S<T else 'No')
S = input()
T = input()

cnt = 0
for i in range(len(S)):
    if S[i] != T[i]:
        cnt += 1
print(cnt)b

### FIXED CODE ###

S = input()
T = input()

cnt = 0
for i in range(len(S)):
    if S[i] != T[i]:
        cnt += 1
print(cnt)
#!/usr/bin/env python

nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]

student = list()
point = list()

for i in range(n):
    student.append([int(i) for i in input().split()])

for j in range(m):
    point.append([int(i) for i in input().split()])


mat = [[abs(student[i][0]-point[j][0]) + abs(student[i][1]-point[j][1]) for j in range(m)] for i in range(m)]

for i in range(n):
    print(mat[i].index(min(mat[i]))+1)

### FIXED CODE ###

#!/usr/bin/env python

nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]

a = list()
b = list()
c = list()
d = list()

for i in range(n):
    ab = [int(tmp) for tmp in input().split()]
    a.append(ab[0])
    b.append(ab[1])

for j in range(m):
    cd = [int(tmp) for tmp in input().split()]
    c.append(cd[0])
    d.append(cd[1])

for i in range(n):
    min_dist = abs(a[i]-c[0]) + abs(b[i]-d[0])
    checkpoint = 1
    for j in range(m):
        cur_dist = abs(a[i]-c[j]) + abs(b[i]-d[j])
        if min_dist > cur_dist:
            min_dist = cur_dist
            checkpoint = j + 1
    print(checkpoint)
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	S = IS()
	ans = True:
	for i,s in enumerate(S):
		if (i % 2 == 1 and s=='R') or (i % 2 == 0 and s=='L'):
			ans=False
	if(ans):
		print('Yes')
	else:
		print('No')

main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	S = IS()
	ans = True
	for i,s in enumerate(S):
		if (i % 2 == 1 and s=='R') or (i % 2 == 0 and s=='L'):
			ans=False
	if(ans):
		print('Yes')
	else:
		print('No')

main()
@profile
def main():
    N = int(input())
    a = list(map(int, input().split()))
    #N = 1000
    #a = [i for i in range(N)]

    #summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)]

    summation = []
    sumtemp = sum(a)
    tmp1 = 0
    for i in range(len(a)-1):
        tmp1 += a[i]
        tmp2 = sumtemp - tmp1
        tmp = abs(tmp1 - tmp2)
        summation.append(tmp)
        
    print(min(summation))

main()



### FIXED CODE ###

def main():
    N = int(input())
    a = list(map(int, input().split()))
    #N = 1000
    #a = [i for i in range(N)]

    #summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)]

    summation = []
    sumtemp = sum(a)
    tmp1 = 0
    for i in range(len(a)-1):
        tmp1 += a[i]
        tmp2 = sumtemp - tmp1
        tmp = abs(tmp1 - tmp2)
        summation.append(tmp)
        
    print(min(summation))

main()
N = int(input())
A = list(map(int,input().split()))
S = []
P = A[:N]
Q = A[2*N:]
for i in range(N):
    Q[i] *= -1
R = A[N:2*N]
p = [0]*(N+1)
q = [0]*(N+1)
import heapq
heapq.heapify(P)
heapq.heapify(Q)
sp = sum(P)
sq = sum(Q)
p[0] = sp
q[0] = sq

for i in range(1,N+1):
    heapq.heappush(P,R[i-1])
    x = heapq.heappop(P)
    heapq.heappush(Q,-R[-i])
    y = heapq.heappop(Q)
    sp = sp + R[i-1] - x
    sq = sq - R[-i] - y
    p[i] = sp
    q[i] = sq
ans = -(10**100)
for k in range(N+1):
    ans = max(ans,p[k] + q[N-k])
    
print(ans)


### FIXED CODE ###

W,H = map(int,input().split())
ans = 10**30
for i in range(1,W):
    a = H*i
    w = W - i
    b = max((w//2)*H,w*(H//2))
    c = w*H - b
    x = max(a,b,c) - min(a,b,c)
    ans = min(ans,x)
for i in range(1,H):
    a = W*i
    h = H - i
    b = max((W//2)*h,W*(h//2))
    c = h*W - b
    x = max(a,b,c) - min(a,b,c)
    ans = min(ans,x)
print(ans)
import fractions
N = int(input())
l = list(map(int,input().split()))

if len(l) == 2:
    memo = max(l)
else:
    memo = 1
    for i in range(N):
        g = fractions.gcd(*(l[:i]+l[i+1:]))
        if g > memo:
            memo = g

print(memo)

### FIXED CODE ###

import fractions

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

L = [0]
R = [0]

gl = 0
gr = 0
for i in range(N):
    gl = fractions.gcd(gl,l[i])
    L.append(gl)
    gr = fractions.gcd(gr,l[N-1-i])
    R.append(gr)

M = []
for i in range(N+1):
    M.append(fractions.gcd(L[i-1],R[N-i]))

print(max(M))
s = input()
q_num = int(input())
head = []
tail = []
flip = 0
for i in range(q_num):
    q = tuple(input().split())
    if q[0] == '1':
        flip ^= 1
    else:
        f = int(q[1]) - 1
        c = q[2]
        if f ^ flip == 0:
            head.append(c)
        else:
            tail.append(c)
if flip:
    head, tail = tail, head
    s = s[::-1]
head = ''.join(head)
tail = ''.join(tail)
print(head[::-1] + s + tail)

### FIXED CODE ###

s = input()
if s == 'AAA' or s == 'BBB':
    ans = 'No'
else:
    ans = 'Yes'
print(ans)
def main(N, a):
    a.sort()
    if a[0] == 1:
        if a[1] == 1:
            return 0
        return 1
    i = 0
    while True:
        num = a[0]
        if 2 > len(a):
            return len(a)+i
        while True:
            if num == a[1]:
                a = [i for i in a if i != num]
                if 2 > len(a):
                    return len(a)+i
                num = a[0]
            else:
                break
        if num*2 > a[len(a)-1]:
            a = [i for i in a if i % num != 0]
            return len(a)+i+1
        a = [i for i in a if i % num != 0]
        i = i+1


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


### FIXED CODE ###

import numpy as np


def main(x):
    for i in range(len(x)):
        if x[i] == 0:
            return i+1
    return 1


x = list(map(int, input().split()))
print(main(x))
import sys
n = int(input())
l = []
for _ in range(n):
    m = int(input())
    l.append([list(map(int, input().split())) for _ in range(m)])
# for i in range(1):
for i in range(2 ** n - 1):
    sj = [True] * n
    bin_i = format(i, 'b').rjust(n, "0")
    for j in range(n):
        sj[j] = (bin_i[j] == "0")
        for k in range(n):
            check = True
            for x in range(len(l[k])):
                # print(j, k, x)
                if sj[k] and sj[l[k][x][0]] and l[k][x][1] == 0:
                    check = False
                    break
                elif sj[k] and not(sj[l[k][x][0]]) and l[k][x][1] == 1:
                    check = False
                    break
                elif (not (sj[k])) and (not(sj[l[k][x][0]])) and l[k][x][1] == 1:
                    check = False
                    break
                elif (not (sj[k])) and (sj[l[k][x][0]]) and l[k][x][1] == 0:
                    check = False
                    break
    if check:
        print(n - i)
        exit()
print(0)

### FIXED CODE ###

n = int(input())
l = []
ans = 0
check = True
for _ in range(n):
    m = int(input())
    l.append([list(map(int, input().split())) for _ in range(m)])
for i in range(2 ** n):
    bin_i = format(i, 'b').rjust(n, "0")
    check = True
    for k in range(n):
        for x in range(len(l[k])):
            if bin_i[k] == "1":
                if (bin_i[l[k][x][0] - 1] == "1") and (l[k][x][1] == 0):
                    check = False
                elif (bin_i[l[k][x][0]-1] == "0") and (l[k][x][1] == 1):
                    check = False
    if check:
        ans = max(ans, bin_i.count("1"))
print(ans)
test1 = input()
test2 = input()

ans = test2 + test1

print(ans)

### FIXED CODE ###

test1, test2 = input().split()

ans = test2 + test1

print(ans)
a1 = int(input())
b2 = input().split(" ")

def check(a , b):
  score = 1
  if '0' in b:
    return 0
  else:
    for i in range(a):
      score *= int(b[i])
      if score > 10 ** 18:
        return print(-1)
    return print(score)

check(a1 , b2)

### FIXED CODE ###

list = input().split(" ")

a = int(list[0])
b = int(list[1])

print(a * b)
#--import&define---------------------
import math

def yes():
    print("Yes")
def no():
    print("No")
#--my_library--------------------------------
#mapを利用したリストの入力
# x,y = map(int,input().split())

#forを利用したリストの入力
#l = []
#for i in range():
#    l.append(int(input()))

#intの最大値と最小値
#maxX = 2147483647
#minX =-2147483648
#--以下解答---------------------------------

n = int(input())
l = []
# min = 2147483647
for i in range(5):
    l.append(int(input()))
    # min = l[i] if l[i]<min else min
minV = min(l)
print(int((n+minV-1)/min) +4)
# if n%min == 0:
#     print(n//min +4)
# else:
#     tmp = int(n//min) +1
#     print(tmp+4)


### FIXED CODE ###

N,*A = map(int,open(0).read().split())
print((N+min(A)-1)//min(A) + 4)
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  query = []
  candi = []
  for i in range(n):
    x,y,h = (int(i) for i in input().split())
    query.append((x,y,h))
  if n == 1:
    print(*[x,y,h])
    exit()
  for cx in range(0,101):
    for cy in range(0,101):
      judge = True
      x,y,h = query[0]
      karih = h +abs(cx-x)+abs(cy-y)
      karih2 = 0
      for i in range(n-1):
        nx,ny,nh = query[i+1]
        if nh == max(karih-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:
        candi.append((cx,cy,karih))
        
      judge = True 
      for i in range(n-1):
        nx,ny,nh = query[i+1]
        if nh == max(karih2-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:
        candi.append((cx,cy,karih2))
  print(*candi[0])
        
          
      
      
solve()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  query = []
  candi = []
  for i in range(n):
    x,y,h = (int(i) for i in input().split())
    query.append((x,y,h))
  if n == 1:
    print(*[x,y,h])
    exit()
  for cx in range(0,101):
    for cy in range(0,101):
      judge = True
      for j in range(n):
        x,y,h = query[j]
        if not h == 0:
          karih = h +abs(cx-x)+abs(cy-y)
          karih2 = 0
      for i in range(n):
        nx,ny,nh = query[i]
        if nh == max(karih-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:
        candi.append((cx,cy,karih))
        
      judge = True 
      for i in range(n-1):
        nx,ny,nh = query[i+1]
        if nh == max(karih2-abs(nx-cx)-abs(ny-cy),0):
          pass
        else:
          judge = False
      if judge:
        candi.append((cx,cy,karih2))
  print(*candi[0])
        
          
      
      
solve()
l = map(int, raw_input().split())
k = raw_input()
listed = list(k)
if (len(k) == (l[0] + l[1] + 1)) and (listed[l[0]] == "-") and ((int(listed[l[0]+1]) in range(10)) and ((int(listed[l[0]-1])) in range(10))):
    print "Yes"
else:
    print "No"


### FIXED CODE ###

l = map(int, raw_input().split())
k = raw_input()
listed = list(k)
if (len(k) == (l[0] + l[1] + 1)) and (listed[l[0]] == "-"):
    if (str("".join(listed[0:l[0]])).isdigit() == True) and (str("".join(listed[l[0]+1:len(listed)])).isdigit() == True):
        print "Yes"
        exit()
    print "No"
else:
    print "No"
zinput = int(input())
a = []
b = []
i = 1
while(i <= input):
  if i%3 == 0 and i%5 == 0:
    a[i] = "FizzBuzz"
  elif i%3 == 0:
    a[i] = "Fizz"
  elif i%5 == 0:
    a[i] = "Buzz"
  else:
    a[i] = i
    b.append(i)
  i += 1
sum = 0
for j in a:
    sum = sum + b[j]
print(sum)



### FIXED CODE ###

input = input()
a = []
i = 1
while(i <= int(input)):
    if i%3 == 0 or i%5 == 0:
        pass
    else:
        a.append(i)
    i += 1
res = 0
for j in a:
  res = res + j
print(res)
H, W, D = tuple(map(int, input().split()))
board = dict()
for h in range(H):
    row = tuple(map(int, input().split()))
    for w in range(W):
        board[row[w]] = (h, w)
delta = dict([(i, 0) for i in range(1, D+1)])
for d in range(D+1, H*W):
    delta[d] = delta[d-D] + abs(board[d][0] - board[d-D][0]) + abs(board[d][1] - board[d-D][1])

Q = int(input())

LRs = [tuple(map(int, input().split())) for _ in range(Q)]
result = [delta[LR[1]] - delta[LR[0]] for LR in LRs]

for r in result:
    print(r)


### FIXED CODE ###

def telepo_test(start, goal, delta, board):
    route = [start + delta * i for i in range(abs(goal - start) // abs(delta) + 1)]
    route = [board[r] for r in route]

    mp = 0
    for s, t in zip(route[:-1], route[1:]):
        print(s,t)
        mp += abs(t[0] - s[0]) + abs(t[1] - s[1])
    return mp


H, W, D = tuple(map(int, input().split()))
board = dict()
for h in range(H):
    row = tuple(map(int, input().split()))
    for w in range(W):
        board[row[w]] = (h, w)
delta = dict([(i, 0) for i in range(1, D+1)])
for d in range(D+1, H*W+1):
    delta[d] = delta[d-D] + abs(board[d][0] - board[d-D][0]) + abs(board[d][1] - board[d-D][1])

Q = int(input())

LRs = [tuple(map(int, input().split())) for _ in range(Q)]
result = [delta[LR[1]] - delta[LR[0]] for LR in LRs]

for r in result:
    print(r)
ef main():

    data = list(map(int, input().split()))
#     print(data)

    a = data[:3]
#     print(a)
    b = data[3:]
#     print(b)
    ans = [0 for x in range(3)]

    t = b[2] - a[2]
    if t < 0:
        ans[2] = t + 60
        b[1] -= 1
    else:
        ans[2] = t


    t = b[1] - a[1]
    if t < 0:
        ans[1] = t + 60
        b[0] -= 1

    else:
        ans[1] = t

    ans[0] = b[0] - a[0]
#     print(ans)
    for a in ans[:-1]:
        print(a, end=' ')
    print(ans[-1])

if __name__ == '__main__':
    for a in range(3):
        main()

### FIXED CODE ###

def main():

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

    a = data[:3]
    b = data[3:]
    ans = [0 for x in range(3)]

    t = b[2] - a[2]
    if t < 0:
        ans[2] = t + 60
        b[1] -= 1
    else:
        ans[2] = t


    t = b[1] - a[1]
    if t < 0:
        ans[1] = t + 60
        b[0] -= 1

    else:
        ans[1] = t

    ans[0] = b[0] - a[0]
    for a in ans[:-1]:
        print(a, end=' ')
    print(ans[-1])

if __name__ == '__main__':
    for a in range(3):
        main()
n = int(input())
list = list(map(int,input().split()))
di = {}
for i in range(n):
	k = list[i]
	if k not in di:
		di[k]=1
	else:
		di[k]+=1
list_del=[]
for key in di.keys():
	if di[key]==1:
		list_del.append(key)
for i in range(len(list_del)):
	di.pop(list_del[i])
	
	
su=0
for valu in di.values():
	su += valu*(valu-1)/2
	
for i in range(n):
	k = list[i]
	if k in si:
		l = di[k]
		su_ch = su
		su_ch -= l*(l-1)/2
		su_ch += (l-1)*(l-2)/2
		print(int(su_ch))
	else:
		print(su)


### FIXED CODE ###

n = int(input())
list = list(map(int,input().split()))
di = {}
for i in range(n):
	k = list[i]
	if k not in di:
		di[k]=1
	else:
		di[k]+=1
"""
list_del=[]
for key in di.keys():
	if di[key]==1:
		list_del.append(key)
for i in range(len(list_del)):
	di.pop(list_del[i])
"""
	
su=0
for valu in di.values():
	su += valu*(valu-1)/2
	
for i in range(n):
	k = list[i]
	l = di[k]
	su_ch = su
	su_ch -= l*(l-1)/2
	su_ch += (l-1)*(l-2)/2
	print(int(su_ch))
N = int(input())
As = list(map(int, input().split()))

total = 0
before = 0
for i in range(len(As) - 1):
    if i == 0:
        total = total + As[i] * sum(As[i+1:])
        before = As[i] * sum(As[i+1:])
    else:
        total = total + (((before / As[i-1]) - As[i]) * As[i])
        before = (((before / As[i-1]) - As[i]) * As[i])

total = total % (10**9 + 7)

print(int(total))

### FIXED CODE ###

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

total = 0
before = 0
for i in range(len(As) - 1):
    if i == 0:
        total = total + As[i] * sum(As[i+1:])
        before = sum(As[i+1:])
    else:
        total = total + ((before - As[i]) * As[i])
        before = before - As[i]

total = total % (10**9 + 7)

print(int(total))