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

n = int(input())

l = []

for _ in range(n):
    s = str(input())
    if not s in l:
        l.append(s)

print(len(l))

### FIXED CODE ###

from sys import stdin
input = stdin.readline

n = int(input())

l = [str(input()) for _ in range(n)]

print(len(set(l)))
### BUGGY CODE ###

def slove():
    import sys, heapq
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    bc = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    heapq.heapify(a)
    for b, c in bc:
        for i in range(b):
            p = heapq.heappop(a)
            if p < c:
                heapq.heappush(a, c)
            else:
                heapq.heappush(a, p)
                break
    print(sum(a))


if __name__ == '__main__':
    slove()


### FIXED CODE ###

def slove():
    import sys, heapq
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    bc = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    heapq.heapify(a)
    bc = sorted(bc, key=lambda x: x[1], reverse=True)
    for b, c in bc:
        bo = True
        for i in range(b):
            p = heapq.heappop(a)
            if p < c:
                heapq.heappush(a, c)
            else:
                heapq.heappush(a, p)
                bo = False
                break
        if not bo:
            break
    print(sum(a))


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

N,M,Q = map(int,input().split())
T = [[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
  L,R = map(int, input().split())
  for r in range(R-1,N):
    T[L-1][r] += 1
ans = []
for i in range(Q):
  p,q = map(int, input().split())
  n = 0
  for l in range(p-1,q):
    n += T[l][q-1]
  ans.append(n)
print('\n'.join(map(str,ans)))


### FIXED CODE ###

N,M,Q = map(int,input().split())
T = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(M):
  L,R = map(int, input().split())
  T[L][R] += 1
for l in range(1,N+1):
  for r in range(1,N+1):
    T[l][r] += T[l-1][r]+T[l][r-1]-T[l-1][r-1]
ans = []
for i in range(Q):
  p,q = map(int, input().split())
  ans.append(T[p-1][p-1]+T[q][q]-T[p-1][q]-T[q][p-1])
print('\n'.join(map(str,ans)))
### BUGGY CODE ###

n = int(input())
S = str(input())
r = []
g = []
b = []
for i in range(n):
    if S[i] == 'R':
        r.append(i)
    elif S[i] == 'G':
        g.append(i)
    else:
        b.append(i)
#print(r, g, b)
ans = 0
for R in r:
    for G in g:
        i = min(R, G)
        j = max(R, G)
        for B in b:
            if j < B:
                if j-i != B-j:
                    ans += 1
            elif B < i:
                if j-i != i-B:
                    ans += 1
            else:
                if j-B != B-i:
                    ans += 1

print(ans)



### FIXED CODE ###

n=int(input())
S=str(input())
r=S.count('R')
g=S.count('G')
b=S.count('B')
cnt=r*g*b
for i in range(n):
    for a in range(1,n):
        j=i+a
        k=j+a
        if k>=n:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            cnt-=1

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

N,A,B = map(int,input().split())
cnt = 0
num = 0

for i in range(N):
    if i < A:
        cnt += 1
        num += 1
    elif i < A + B:
        num += 1
    elif i < A + B + A:
        cnt += 1
        num += 1
print(cnt)


### FIXED CODE ###

N, A, B = map(int, input().split())
ans = N // (A + B) * A
rem = N % (A + B)
ans += min(rem, A)
print(ans)
### BUGGY CODE ###

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

from collections import defaultdict

cnt = defaultdict(int)
for i in range(n):
    cnt[a[i]] += 1
# print(cnt)

for key, val in list(cnt.items()):
    if val < 2:
        cnt.pop(key)
# print(cnt)

for i in range(n):
    cnt[a[i]] -= 1
    # print(cnt)
    ans = 0
    for val in cnt.values():
        if val >= 2:
            ans += val*(val-1)//2
    print(ans)
    cnt[a[i]] += 1

### FIXED CODE ###

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

from collections import defaultdict

cnt = defaultdict(int)
for i in range(n):
    cnt[a[i]] += 1
# print(cnt)

for key, val in list(cnt.items()):
    if val < 2:
        cnt.pop(key)
# print(cnt)

total = 0
for val in cnt.values():
    if val >= 2:
        total += val*(val-1)//2

for i in range(n):
    diff = 0
    if a[i] in cnt:
        y = (cnt[a[i]]-1)*cnt[a[i]]//2
        x = (cnt[a[i]]-1)*(cnt[a[i]]-2)//2
        diff = y - x
    print(total - diff)
        
        

# for i in range(n):
#     flag = False
#     if a[i] in cnt:
#         cnt[a[i]] -= 1
#         flag = True
#     # print(cnt)
#     ans = 0
#     for val in cnt.values():
#         if val >= 2:
#             ans += val*(val-1)//2
#     print(ans)
#     if flag:
#         cnt[a[i]] += 1
### BUGGY CODE ###

import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

prev_cmd = 0
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          prev_cmd += 1
        if( str[0] == '2'):
	  if( prev_cmd %2 == 1):
	    s = s[::-1]
	  prev_cmd = 0
          if( str[2] == '1'):
	    s = str[4] + s
          if( str[2] == '2'):
	    s = s + str[4]

if( prev_cmd %2 == 1):
  s = s[::-1]

print s
sys.stdout.flush()


### FIXED CODE ###

import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

flag = 0
prev=""
end=""
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          flag += 1
        if( str[0] == '2'):
          if( str[2] == '1'):
	    if( flag % 2 == 0):
	      prev = str[4] + prev
	    else:
	      end = end + str[4]
          if( str[2] == '2'):
	    if( flag % 2 == 0):
	      end = end + str[4]
	    else:
	      prev = str[4] + prev

ss = prev + s + end
if( flag % 2 == 1):
  ss = ss[::-1]

print ss
sys.stdout.flush()
### BUGGY CODE ###

# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
diff = []
for i in range(1, N):
    diff.append(abs(sum(A[:i]) - sum(A[i:])))
print(min(diff))

### FIXED CODE ###

# coding: utf-8
from math import ceil
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
half = ceil(sum(A) / 2)
tmp = 0
diff = sum(A)
for i in range(N):
    tmp += A[i]
    total -= A[i]
    if total == tmp:
        print(0)
        exit()
    diff = min(diff, abs(total - tmp))
print(diff)
### BUGGY CODE ###

'''
4 2
1 3
2 4
'''

N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
for i in range(M):
    L,R=map(int,input().split())
    L_list.append(L)
    R_list.append(R)

for i in range(1,N+1):

    for j in range(M):
        if(i in range(L_list[j],R_list[j]+1)):
            if j==M-1:
                count+=1
        else:
            break
print(count)

### FIXED CODE ###

N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
min_mn=float('inf')
max_mn=0
for i in range(M):
    L,R=map(int,input().split())
    min_mn = min(min_mn,R)
    max_mn = max(max_mn,L)

for i in range(1,N+1):
    if(i>=max_mn and i<=min_mn):
        count += 1
print(count)
### BUGGY CODE ###

N = int(input())
V = [int(n) for n in input().split()]
C = [int(n) for n in input().split()]

take = [0 for _ in range(N)]
ans = 0

def up(i):
    if i == N:
        return False
    take[i] += 1
    if take[i] == 2:
        take[i] = 0
        return up(i + 1)
    return True

while True:
    sum = 0
    for i in range(N):
        if take[i] == 1:
            sum += V[i] - C[i]
    if sum > ans:
        ans = sum
    if not up(0):
        break

print(ans)


### FIXED CODE ###

N = int(input())
V = [int(n) for n in input().split()]
C = [int(n) for n in input().split()]

ans = 0
for i in range(N):
    ans = max([ans, ans + V[i] - C[i]])

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

import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

WV = []

N, W = [int(v) for v in input().strip().split(' ')]

for _ in range(N):
    WV.append([int(v) for v in input().strip().split(' ')])


dp = np.zeros((N + 1, W + 1), dtype = 'uint64')
for i in range(N):
    for w in range(W + 1):
        if w - WV[i][0] >= 0:
            dp[i + 1][w] = max(dp[i + 1][w], WV[i][1] + dp[i][w - WV[i][0]])
        dp[i + 1][w] = max(dp[i + 1][w], dp[i][w])
print(dp[N][W])



### FIXED CODE ###

import numpy as np
import sys

N, W = [int(v) for v in input().strip().split(' ')]
dp = np.zeros(W + 1, dtype = 'uint64')

for _ in range(N):
    w, v = [int(v) for v in sys.stdin.readline().split(' ')]
    np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])

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

N, K, Q = map(int, input().split())
A = []
for _ in range(Q):
  A.append(int(input()))

# print(A)

pts = [K]*N
for ai in A:
    for i, _ in enumerate(pts):
        if (i+1)!=ai:
            pts[i] -= 1

for p in pts:
    if p>0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

N, K, Q = map(int, input().split())
A = []
for _ in range(Q):
    A.append(int(input()))
    
pts = [K - Q]*N
for ai in A:
    pts[ai-1] += 1

for p in pts:
    if p>0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    A, B = mis()
    from fractions import gcd
    n = gcd(A,B)
    def get_common_divs(n1, n2):
        common_divs = set()
        i = 1
        while i*2 <= min(n1,n2):
            if n1%i == n2%i == 0:
                common_divs.add(i)
            i += 1
        return common_divs
    
    common_divs = get_common_divs(A,B)

    ans = {1}
    for d in common_divs:
        if all(gcd(a,d)==1 for a in ans):
            ans.add(d)

    ans = len(ans)
    print(ans)


main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def divs_gen(n):
    for i in range(1, int(m**.5)+1):
        if n%i == 0:
            yield i
            if i != n//i:
                yield n//i


def main():
    A, B = mis()
    from fractions import gcd
    G = gcd(A, B)
    fs = set()
    for i in range(2, int(G**0.5)+2):
        if G%i == 0 and all(i%f != 0 for f in fs):
            fs.add(i)
            while G%i == 0:
                G //= i
    if G > 1:
        fs.add(G)
    print(len(fs)+1)


main()
### BUGGY CODE ###

import itertools
N = int(input())
stick = sorted(list(map(int, input().split())), reverse=True)
combi = itertools.combinations(stick, 3)
ans = 0
lst = []
flag = False
for a,b,c in combi:
  if flag and a in lst:
    continue
  else:
    flag = False
  if a < b+c and b < c+a and c < a+b:
    ans += 1
  else:
    flag = True
    lst.append(a)
print(ans)

### FIXED CODE ###

import time
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
#print(l)
#start = time.time()
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        #print(l[i], l[j],ab , c_index, j+1, res)
        res += c_index - j - 1
print(res)
### BUGGY CODE ###

import itertools
n = int(input())
a = list(map(int, input().split()))
idList = [i for i in range(1,n+1)]

com = list(itertools.combinations(idList, 2))

num = len(com)
ans = 0
for i in range(num):
    aa = com[i]
    # print(aa)
    idA = aa[0]
    idB = aa[1]
    dif = abs(idA - idB)
    height = a[idA - 1] + a[idB - 1]

    if (height == dif):
        ans += 1

print(ans)


### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))

minus = [0] * N
plus = [0] * N

for i in range(N):
    minus[i] = (i + 1) - A[i]
    plus[i] = (i + 1) + A[i]

count = Counter(minus)
most = count.most_common()
num = len(most)

countPP = Counter(plus)
#mostPP = countPP.most_common()
#check = mostPP[:][0]
ans = 0

for i in range(num):
    elm = most[i]
    fir = elm[0]
    sec = elm[1]
    # if (fir in check):

    aa = countPP[fir]
    #    print(aa)
    ans += aa * sec

    # try countPP[tar]:

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

n = int(input())
s = input()
 
max_count = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            count = max_count
            while True:
                if i+count <= j and s[i:i+count] == s[j:j+count]:
                    #print(count, i, s[i:i+count])
                    count += 1
                else:
                    max_count = max(max_count, count-1)
                    break
print(max_count)

### FIXED CODE ###

tmp = input()
my_str = input()
 
start = 0
end = 1
max_len = 0
 
while (end < len(my_str)):
    if my_str[start:end] in my_str[end:]:
        if end - start > max_len:
            max_len = end - start
        end += 1
    else:
        start += 1
print(max_len)
### BUGGY CODE ###

n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]
for s in range(1, n+1):
	b = a.count(s)
	if b > q-k:
		print("Yes")
	else:
		print("No")

### FIXED CODE ###

n, k, q = map(int, input().split())
a = [k-q] * n
for s in range(q):
	t = int(input())
	a[t-1] += 1
for u in range(n):
	if a[u] > 0:
		print("Yes")
	else:
		print("No")
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10 ** 9
dp = [INF] * N
dp[0] = 0
for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j > N - 1:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[-1])

### FIXED CODE ###

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

INF = 10 ** 9
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

def chmin(a, b):
    if a > b:
        return b
    else:
        return a
        
for i in range(2, N):
    for j in range(1, K + 1):
        dp[i] = chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

print(dp[-1])
### BUGGY CODE ###

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

for i in range(k):
  b=[0]*n
  if k-i>n-2:
    for i in range(n):
      a[i]=n
    for i in a:
      print(i,end=' ')
    sys.exit()
  for j in range(n):
    for m in range(j-a[j],j+a[j]+1):
      if 0<=m<=n-1:
        b[m]=b[m]+1
  a=b
for i in a:
  print(i,end=' ')


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
  b=[0]*(n+1)
  for i in range(n):
    l=max(0,i-a[i])
    r=min(n,i+a[i]+1)
    b[l]+=1
    b[r]-=1
  for i in range(n-1):
    b[i+1]+=b[i]
  a=b[:n]
print(*a)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 10:03:26 2017

@author: kotania
"""
N = int(input())
AList = []

count = 0
        
for n in range(0,N):
    An = input()
    
    if An not in AList:
        AList.append(An)
        count += 1
    else:
        AList.remove(An)
        count -= 1

print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 10:03:26 2017

@author: kotania
"""
from collections import Counter

N = int(input())
 
AList = []
 
count = 0
        
for n in range(0,N):
    AList.append(input())
    
countDict = Counter(AList)
countDictValues = countDict.values()

count = 0

for c in countDictValues:
    if c % 2 == 1 :
        count += 1

print(count)
### BUGGY CODE ###

k = int(input())
start = 7 % k
ans = start
con = 1

while True:
  if ans == 0:
    print(con)
    break
  else:
    con += 1
    ans = ans * 10 + 7
    ans = ans % k
    if ans == start:
      print("-1")
      break


### FIXED CODE ###

k = int(input())
start = 7 % k
ans = start
con = 1

if k % 2 == 0 or k % 5 == 0:
  print("-1")
  exit()
while True:
  if ans == 0:
    print(con)
    break
  else:
    con += 1
    ans = ans * 10 + 7
    ans = ans % k
    if ans == start:
      print("-1")
      break
### BUGGY CODE ###

N, K = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(K)]

dp = [0] * (N + 1)
dp_sums = [0] * (N + 1)
dp[1] = dp_sums[1] = 1

for i in range(2,N+1):
    for l, r in S: 
        if i >= r + 1:
            dp[i] += dp_sums[i - l] - dp_sums[i - r - 1] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i > l and i < r + 1:
            dp[i] += dp_sums[i - l] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i <= l:
            dp_sums[i] = dp_sums[i-1] + dp[i]
        while dp[i] >= 998244353:
            dp[i] -= 998244353
while dp[N] >= 998244353:
    dp[N] -= 998244353 
print(dp[N])

### FIXED CODE ###

N, K = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(K)]

dp = [0] * (N + 1)
dp_sums = [0] * (N + 1)
dp[1] = dp_sums[1] = 1

for i in range(2,N+1):
    for l, r in S: 
        if i >= r + 1:
            dp[i] += dp_sums[i - l] - dp_sums[i - r - 1] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i > l and i < r + 1:
            dp[i] += dp_sums[i - l] 
            dp_sums[i] = dp_sums[i-1] + dp[i]
        elif i <= l:
            dp_sums[i] = dp_sums[i-1] + dp[i]
    dp[i] %= 998244353
    dp_sums[i] %= 998244353
print(dp[N])
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().strip()

n=int(input())
xs=input()
xj=xs.count("1")

x=int(xs,2)

i1=1<<n
for i in range(n-1,-1,-1):
    i1=i1>>1
    xi=x^i1
    if xs[n-1-i]=="0":
        pxi=xj+1
    else:
        pxi=xj-1
    if xi==0:
        print(0)
    else:
        xi=xi%pxi
        if xi==0:
            print(1)
        else:
            icnt=1
            while xi>0:
                icnt+=1
                xi=xi%bin(xi).count("1")
            print(icnt)


### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()

n=int(input())
xs=input()
xj=xs.count("1")

x=int(xs,2)
xip=x%(xj+1)
if xj!=1:
    xim=x%(xj-1)

for i in range(n-1,-1,-1):
    if xs[n-1-i]=="0":
        pxi=xj+1
        i2=pow(2,i,pxi)
        xi=(xip+i2)%pxi
    elif xj==1:
        print(0)
        continue
    else:
        pxi=xj-1
        i2=pow(2,i,pxi)
        xi=(xim-i2)%pxi
    xi=xi%pxi
    if xi==0:
        print(1)
        continue
    icnt=1
    while xi>0:
#        print("i",i,"xi",xi,"icnt",icnt)
        icnt+=1
        xi=xi%(bin(xi).count("1"))
    print(icnt)
### BUGGY CODE ###

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

cnt = 0

for x in range(k+1):
    for y in range(k+1):
        if x + y <= s:
            z = s-x-y
            if (z>=0) and (z <= k and x+y+z == s):
                cnt +=1
            
            
print(cnt)
    

### FIXED CODE ###

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

cnt = 0

for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if (z>=0) and (z <= k):
            cnt +=1
            
            
print(cnt)
### BUGGY CODE ###

h,w=map(int,input().split())
h+=2
w+=2
s=[]
l=[[0 for i in range(w)]for j in range(h)]
s.append(["#" for i in range(w)])
for i in range(h-2):
    a=input()
    s.append("#"+a+"#")
s.append(["#" for i in range(w)])

yl=[[]for j in range(h)]
tl=[[]for j in range(w)]
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            yl[i].append(j)
            tl[j].append(i)
ans=0
import bisect
for i in range(1,h-1):
    for j in range(1,w-1):
        if s[i][j]!="#":
            n=bisect.bisect(yl[i],j)
            m=bisect.bisect(tl[j],i)
            p=0
            if yl[i][n-1]!=yl[i][-1]:
                p+=yl[i][n]-yl[i][n-1]-1
            elif j<yl[i][0]:
                p+=yl[i][0]
            else:
                p+=len(yl[i])-yl[i][-1]-1
                
            if tl[j][m-1]!=tl[j][-1]:
                p+=tl[j][m]-tl[j][m-1]-2
            elif i<tl[j][0]:
                p+=tl[j][0]-1
            else:
                p+=len(tl[j])-tl[j][-1]-2
            
            ans=max(ans,p)
                
        
print(ans)

### FIXED CODE ###

h,w=map(int,input().split())
s=[]
l=[[0 for i in range(w)]for j in range(h)]
 
for i in range(h):
    a=input()
    s.append(a)

yoko=[[0 for j in range(w)] for j in range(h)]
tate=[[0 for j in range(w)] for j in range(h)]

for i in range(h):
    p=0
    for j in range(w):
        if s[i][j]=="#" or j==w-1:
            if s[i][j]==".":
                for k in range(p):
                    yoko[i][j-k-1]+=p+1
                yoko[i][j]+=p+1
            else:
                for k in range(p):
                    yoko[i][j-k-1]+=p
            p=0
        elif s[i][j]==".":
            p+=1
for i in range(w):
    p=0
    for j in range(h):
        if s[j][i]=="#" or j==h-1:
            if s[j][i]==".":
                for k in range(p):
                    tate[j-k-1][i]+=p+1
                yoko[j][i]+=p+1
            else:
                for k in range(p):
                    tate[j-k-1][i]+=p
            p=0
        elif s[j][i]==".":
            p+=1
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,yoko[i][j]+tate[i][j]-1)

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

import bisect
import sys

sys.setrecursionlimit(200000)

n,q = (int(num) for num in input().split())
neighbor = [[] for _ in range(n)]
visited = [0] * n
val = [0] * n
ab = []
for i in range(n-1):
    a,b = (int(num)-1 for num in input().split())
    ab.append((a,b))

    
for item in ab:
    a = item[0]
    b = item[1]
    neighbor[a].append(b)
    neighbor[b].append(a)
    
        
#print(par)
#print(neighbor)
#print(rank)

for _ in range(q):
    p,x = (int(num) for num in input().split())
    p -= 1
    val[p] += x
    
def calc(idx,neighbor,val,bias):
    val[idx] += bias
    for i in neighbor[idx]:
        if visited[i] == 0:
            visited[i] = 1
            calc(i,neighbor,val,val[idx])

visited[0] = 1
calc(0,neighbor,val,0)    
ans = ""    
for num in val:
    ans += str(num) + " "
print(ans)




### FIXED CODE ###

n,q = (int(num) for num in input().split())
par = [n] * n
visited = [0] * n
val = [0] * n
ab = []
for i in range(n-1):
    a,b = (int(num)-1 for num in input().split())
    par[b] = a
    
for _ in range(q):
    p,x = (int(num) for num in input().split())
    p -= 1
    val[p] += x

for i in range(1,n):
    val[i] += val[par[i]]
    
ans = ""
for num in val:
    ans += str(num) + " "
print(ans)
### BUGGY CODE ###

# E - Crested Ibis vs Monster
H, N = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a,b])
AB.sort()

DP = [float('inf') for i in range(2* 10**4+1)]
DP[0] = 0
for i in range(10**4):
    for ab in AB:
        DP[i+ab[0]] = min(DP[i+ab[0]], DP[i] + ab[1])

print(min(DP[H:]))


### FIXED CODE ###

# E - Crested Ibis vs Monster
H, N = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a,b])
AB.sort()

DP = [float('inf') for i in range(2*10**4 + 1)]
DP[0] = 0
for i in range(H):
    for ab in AB:
        DP[i+ab[0]] = min(DP[i+ab[0]], DP[i] + ab[1])

print(min(DP[H:]))
### BUGGY CODE ###

H,W,D=map(int,input().split())
list1=[]
for i in range(H*W+1):
    list1.append([0,0])

#print(list1)

for j in range(H):
    A=list(map(int,input().split()))
    for k in range(W):
        list1[A[k]][0]=j+1
        list1[A[k]][1]=k+1
#print(list1)

Q=int(input())
for a in range(Q):
    L,R=map(int,input().split())
    cnt=0
    while L<=R:
        if L==R:
            print(cnt)
            break
        else:
            
            cnt+=abs(list1[L+D][0]-list1[L][0])+abs(list1[L+D][1]-list1[L][1])
            L+=D
            

### FIXED CODE ###

H,W,D=map(int,input().split())
L=[0 for i in range(H*W+1)]
A=[]
for i in range(H):
    a=list(map(int,input().split()))
    A.append(a)
    
for i in range(H):
    for j in range(W):
        L[A[i][j]]=[i+1,j+1]
L[0]=[0,0]
#print(L)
l=[0 for i in range(H*W+1)]
for i in range(D):
    for j in range(H*W+1):
        if (i+j*D)>(H*W):
            break
        elif j==0:
            l[i+j*D]=0
        else:
            l[i+j*D]=l[i+(j-1)*D]+abs(L[i+j*D][0]-L[i+(j-1)*D][0])+abs(L[i+j*D][1]-L[i+(j-1)*D][1])
#print(l)
Q=int(input())
for i in range(Q):
    a,b=map(int,input().split())
    print(l[b]-l[a])