Harryxun/stf_run huggingface dataset:
def K(n):
    return 0.5 * (n + 1)

def d():
    n, k = list(map(int, input().split()))
    p = list(map(int, input().split()))

    pionta = None
    ire = [None for i in range(k)]
    for i in range(0, n):
        if k < i + 1:
            pionta = i // k
        if pionta is None:
            ire[i] = p[i]
        else:
            if ire[pionta] < p[i]:
                ire[pionta] = p[i]
    m = 0
    for i in ire:
        m += K(i)
    return m
print(d())

### FIXED CODE ###

def K(n):
    return 0.5 * (n + 1)

def d():
    n, k = list(map(int, input().split()))
    p = list(map(int, input().split()))

    pionta = None
    ire = [None for i in range(k)]
    d = {}
    d[0] = 0

    ss = 0
    for i in range(0, n):
        if k < i + 1:
            pionta = i % k
        if pionta is None:
            ire[i] = p[i]
        else:
            ss += p[i] - ire[pionta]
            d[ss] = i
            ire[pionta] = p[i]


    max_s = max(d.keys())
    i = d[max_s]
    m = 0
    for i2 in range(i-k+1, i+1):
        m += K(p[i2])
    return m
print(d())
N,M = list(map(int,input().split()))
x = 1
y = 1

for m in M:
    a,b = list(map(int,input().split()))
    if a==1:
      x|=1<<b
    if b==N:
      y|=1<<a

print("IM"*(x&y==1)+"POSSIBLE")

### FIXED CODE ###

N,M = list(map(int,input().split()))
x = 1
y = 1

for m in range(M):
    a,b = list(map(int,input().split()))
    if a==1:
      x|=1<<b
    if b==N:
      y|=1<<a

print("IM"*(x&y==1)+"POSSIBLE")
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
n = list(a, b, c, d, e)

n.sort(key=lambda x: x % 10)

for i in range(1, 5):
    n[i] = 10 * (n[i]//10+1)

sm = sum([n[i] for i in range(1, 5)])+n[0]
print(sm)


### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
n = [a, b, c, d, e]

zr = list(filter(lambda x: x % 10 == 0, n))
nz = list(filter(lambda x: x % 10 != 0, n))

nz.sort(key=lambda x: x % 10)

for i in range(1, len(nz)):
    nz[i] = 10 * (nz[i]//10+1)

print(sum(nz)+sum(zr))
from collections import deque
N, M = map(int, input().split())
edges = [[] for i in range(N)]
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    AB.append((a-1, b-1))
def BFS(s):
    prev = [-1]*N
    que = deque([s])
    while que:
        v = que.pop()
        for nv in edges[v]:
            if nv == s:
                prev[nv] = v
                return (s, prev)
            if prev[nv]<0:
                que.append(nv)
                prev[nv] = v
    return (-1, prev)
for v in range(N):
    v0, prev = BFS(v)
    if v0>=0:
        break
if v0<0:
    print(-1)
    exit()
circle = set()
circle.add(v0)
pv = prev[v0]
while pv != v0:
    circle.add(pv)
    pv = prev[pv]
for a, b in AB:
    if a in circle and b in circle and prev[b] != a:
        pv = prev[b]
        while pv != a:
            circle.remove(pv)
            pv = prev[pv]
print(len(circle))
for i in circle:
    print(i+1)

### FIXED CODE ###

import sys
from collections import deque
N, M = map(int, input().split())
edges = [[] for i in range(N)]
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    AB.append((a-1, b-1))
def BFS(s):
    prev = [-1]*N
    que = deque([s])
    while que:
        v = que.pop()
        for nv in edges[v]:
            if nv == s:
                prev[nv] = v
                return (s, prev)
            if prev[nv]<0:
                que.append(nv)
                prev[nv] = v
    return (-1, prev)
for v in range(N):
    v0, prev = BFS(v)
    if v0>=0:
        break
if v0<0:
    print(-1)
    sys.exit()
circle = set()
circle.add(v0)
pv = prev[v0]
while pv != v0:
    circle.add(pv)
    pv = prev[pv]
for a, b in AB:
    if a in circle and b in circle and prev[b] != a:
        pv = prev[b]
        while pv != a:
            circle.remove(pv)
            pv = prev[pv]
        prev[b] = a
print(len(circle))
for i in circle:
    print(i+1)
print(int(input(x)**3))

### FIXED CODE ###

x = int(input())

print(x*x*x)
N = int(input())
sel = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * N for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if not j == k:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j]+sel[i][k])

print(max(dp[N]))

### FIXED CODE ###

N = int(input())
sel = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if not j == k:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j]+sel[i][k])

print(max(dp[N]))
A = int(input())
B = int(input())
C = int(input())
K = int(input())

if K<=A:
  print(K)
elif k<=A+B:
  print(A)
else:
  print(A-(C-(k-(A+B)))

### FIXED CODE ###

A,B,C,K = map(int,input().split())
 
if K <= A:
    print(str(K))
elif K <= A + B:
    print(str(A))
else:
    print(str(A - (C - (A + B + C - K))))
"""
T E S T
"""

from collections import Counter, deque

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

cnt_a = Counter(A)
cnt_b = Counter(B)

cnt_ab = cnt_a + cnt_b

for i in cnt_ab.values():
    if i > N:
        print("No")
        exit()


print("Yes")
dq_a = deque(A)
dq_b = deque(B)

ans = []

dq_b.rotate(n // 2)

while dq_a:
    if dq_a[0] != dq_b[0]:
        dq_a.popleft()
        p = dq_b.popleft()
        ans.append(p)
        # ans.append(b.popleft())
    else:
        dq_b.rotate()
print(*ans)


### FIXED CODE ###

"""
T E S T
"""

from collections import Counter, deque

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

cnt_a = Counter(A)
cnt_b = Counter(B)

cnt_ab = cnt_a + cnt_b

for i in cnt_ab.values():
    if i > N:
        print("No")
        exit()


print("Yes")
dq_a = deque(A)
dq_b = deque(B)

ans = []

dq_b.rotate(N // 2)

while dq_a:
    if dq_a[0] != dq_b[0]:
        dq_a.popleft()
        p = dq_b.popleft()
        ans.append(p)
        # ans.append(b.popleft())
    else:
        dq_b.rotate()
print(*ans)
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,m=map(int,input().split())
if (n<=1) and (m<=1):
  ans=0
else:
  if n==0:
    ans=comb(m,2)
  elif m==0:
    ans=comb(n,2)
  else:
    ans=comb(n,2)+comb(m,2)
  
print(ans)
  

### FIXED CODE ###

import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,m=map(int,input().split())
if (n<=1) and (m<=1):
  ans=0
else:
  if n<=1:
    ans=comb(m,2)
  elif m<=1:
    ans=comb(n,2)
  else:
    ans=comb(n,2)+comb(m,2)
  
print(ans)
K = int(input())
print(2)
print(N+K-2,2)

### FIXED CODE ###

K = int(input())
N = 50

a = [i for i in range(N)]
a = [x + K // N for x in a]
for i in range(K % N):
    a = [x - 1 for x in a]
    a[i] += N + 1

print(N)
print(*a)
a = list(input().split())

if a[1]=='+':
  print(int(a[0])+int(a[2]))
else if a[1]=='-':
  print(int(a[0])-int(a[2]))



### FIXED CODE ###

a = input().split()

if a[1]=='+':
  print(int(a[0])+int(a[2]))
elif a[1]=='-':
  print(int(a[0])-int(a[2]))
from collections import deque
def inpl(): return list(map(int, input().split()))

N, M = inpl()
G = {i:[] for i in range(N)}
X = [0]*(N)
searched = [0]*(N)
pairents = [-1]*N

for _ in range(N-1+M):
    a, b = inpl()
    G[a-1].append(b-1)
    X[b-1] += 1

q = X.index(0)

Q = deque([q])
while Q:
    p = Q.popleft()
    for q in G[p]:
        if searched[q] <= searched[p]:
            searched[q] = searched[p] + 1
            Q.append(q)

for a in range(N):
    for b in G[a]:
        if searched[b] == searched[a] + 1:
            pairents[b] = a
for p in pairents:
    print(p+1)
    


### FIXED CODE ###

from string import ascii_lowercase
def inpl(): return list(map(int, input().split()))
N, A, B = inpl()
if A + B <= N:
    C = 0
else:
    abs(A - B)

print(min(A, B), max(A + B - N, 0))
a, b, n = map(int, input().split())
x = min(b-1, n)
ans = max(int((a*x)/b) - a*int(x/b))
print(ans)


### FIXED CODE ###

a, b, n = map(int, input().split())
x = min(b-1, n)
ans = int((a*x)/b) - a*int(x/b)
print(ans)
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S,W = map(int, readline())


if S > W:
  print('safe')
else:
  print('unsafe')

### FIXED CODE ###

import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
S,W = map(int, readline().split())
 
 
if S > W:
  print('safe')
else:
  print('unsafe')
N, M = map(int, input().split())
H = list(map(int, input().split()))

t = [0]*N
for i in range(M):
   a, b = map(int, input().split())
   t[a-1] = max(t[a-1], H[b-1])
   t[b-1] = max(t[b-1], H[a-1])

res = 0
for i range(N):
    if H[i] > t[i]:
        res += 1

print(res) 

### FIXED CODE ###

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

t = [0]*N
for i in range(M):
   a, b = map(int, input().split())
   t[a-1] = max(t[a-1], H[b-1])
   t[b-1] = max(t[b-1], H[a-1])

res = 0
for i in range(N):
    if H[i] > t[i]:
        res += 1

print(res)
from operator import itemgetter
n,h = map(int,input().split())
ab = []
ans = 0
a = 0
for i in range(n):
  ab.append(list(map(int,input.split())))
ab.sort()
swing = ab.pop(-1)
ab = sorted(a,key = itemgetter(1))
ab.reverse
for i in range(len(ab)):
  h -= ab[i][1]
  ans += 1
  if h <= 0:
    print(ans)
    a += 1
    break
if a == 0:
  if h%swing[1] == 0:
    h -= swing[1]
    ans += h // swing[1]
    print(ans+1)
  else:
    h -= swing[1]
    ans += h // swing[1]
    print(ans+2)


### FIXED CODE ###

N,H = map(int,input().split());
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
        if ab[i][1] >= swing:
          H -= ab[i][1]
          ans += 1 
        else:
            continue
        if H <= 0:
            break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)
import numpy as np

N = int(input())

LR = []
for i in range(N):
  X, L = map(int, input().split())
  LR.append([X-L, 1, i])
  LR.append([X+L, 0, i])

LR.sort()

tree = np.zeros([N, N], dtype=bool)

is_now = np.zeros(N, dtype=bool)
for y, lr, idx in LR:
  if lr == 1:
    is_now[idx] = True
    tree[idx] += is_now
  else:
    is_now[idx] = False
    tree[idx] += is_now


tree += tree.T

a = np.sum(tree, axis=0)
while (a != 1).any():
  idx = a.argmax()
  tree = np.delete(np.delete(tree, idx, 0), 1)
  a = np.sum(tree, axis=0)

print(len(tree))

### FIXED CODE ###

N = int(input())

RL = []
for i in range(N):
  x, l = map(int, input().split())
  RL.append([x+l, x-l])

RL.sort()
right = -10**9

ans = 0
for r, l in RL:
  if l >= right:
    right = r
    ans += 1
    
print(ans)
N,T = map(int,input().split());
t = [int(x) for x in input().split()];

end = 0;
ans = 0;
for i in range(N) :
    if end > t[i] :
        ans += t[i] + T - end;
        else :
        ans += T;
    end += t[i] + T;
    #print(ans,end);

print(ans); 

### FIXED CODE ###

N,T = map(int,input().split());
t = [int(x) for x in input().split()];

end = 0;
ans = 0;
for i in range(N) :
    if end > t[i] :
        ans += t[i] + T - end;
    else :
        ans += T;
    end = t[i] + T;
    #print(ans,end);

print(ans);
import math

p = input()
r = int(p)
area = math.pi * r ** 2
length = 2 * math.pi * r
print(f"{area:.6f} {length:.6f}")


### FIXED CODE ###

import math

r = float(input())
area = math.pi * r ** 2
length = 2 * math.pi * r
print(f"{area:.6f} {length:.6f}")
N = int(input())
T = list(int(input().split()))
S = sum(T)
M = int(input())

for _ in range(M):
    p,x = map(int,input().split())
    ans = S - T[p-1] + x
    print(ans)

### FIXED CODE ###

#ABC050.B
N =int(input())
T = list(map(int,input().split()))
S = sum(T)
M = int(input())

for _ in range(M):
    a = S
    p,x = map(int,input().split())
    a -= T[p-1]
    a += x
    print(a)
n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in d:
	for j in (d -i):
		ans += i * j
		
print(ans // 2)

### FIXED CODE ###

n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(n -1):
	for j in range(i + 1, n):
		ans += d[i] * d[j]
		
print(ans)
S = input()
l = len(S)

S1 = S[0:(l-1)//2]
S2 = S[(l+3)//2]

def Kaibun(Str):
	return Str == Str[::-1]:

if Kaibun(S) and Kaibun(S1) and Kaibun(S2):
		print("Yes")
	else:
		print("No")

### FIXED CODE ###

def f(x):
  return x==x[::-1]
S=input()
n=(len(S)-1)//2
S1,S2=S[:n],S[n+1:]
if f(S) and f(S1) and f(S2):
  print('Yes')
else:
  print('No')
N = int(input())
H = list(map(int, input().split()))  
H = list(reversed(H))  
if N==1:
    ans='Yes'
else:         
    for i in range(1, N):
        if H[i] - H[i-1] >= 2: #
            ans='No'
            break   
        elif H[i] - H[i-1] == 1: # 1 smaller
            H[i] -= 1
print(ans)  

### FIXED CODE ###

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

H = list(reversed(H)) 
ans='Yes'
if N==1:
    ans='Yes'
else:         
    for i in range(1, N):
        if H[i] - H[i-1] >= 2: #
            ans='No'
            break   
        elif H[i] - H[i-1] == 1: # 1 smaller
            H[i] -= 1
print(ans)
a,b,c,d=map(int,input().split())
al = b-a+1
# cで割り切れる個数
x = int(b/c) -int((a-1)/c)
# dで割り切れる個数
y = int(b/d) -int((a-1)/d)
# cdの最小公倍数
lcm_xy = int(c*d/math.gcd(c,d))
# cdの最小公倍数で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

### FIXED CODE ###

def gcd(a,b):
  while b:
    a,b = b,a % b    
  return a

a,b,c,d = map(int,input().split())

a_c = (a-1)//c
a_d = (a-1)//d
a_cd = (a-1)//(c*d//gcd(c,d))

b_c = b//c
b_d = b//d
b_cd = b//(c*d//gcd(c,d))

bb = b - (b_c + b_d - b_cd) 
aa = (a-1) - (a_c + a_d - a_cd)

print(bb - aa)
a,b,c=map(input().split())
d,e,f=map(input().split())
if a==d:
  A=1
else:
  A=0
if b==e:
  B=1
else:
  B=0
if c==f:
  C=1
else:
  C=0
print(A+B+C)

### FIXED CODE ###

a=input()
b=input()
if a[0]==b[0]:
  A=1
else:
  A=0
if a[1]==b[1]:
  B=1
else:
  B=0
if a[2]==b[2]:
  C=1
else:
  C=0
print(A+B+C)
A, B, K = map(int, input().split())
a = max(0, A - K)
if K - A > 0:
    b = max(0, B - K + A)
print(a, b)


### FIXED CODE ###

A, B, K = map(int, input().split())
a = max(0, A - K)
b = B
if K - A > 0:
    b = max(0, B - K + A)
print(a, b)
n, m = map(int, input().split())

a = list(map(int, input().split()))
a.sort(reverse=True)
total = sum(a)

canPick = True
for i in range(m):
    if a[m] < total // (4 * m):
        canPick = False

if canPick is True:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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

a = list(map(int, input().split()))
a.sort(reverse=True)
total = sum(a)

canPick = True
for i in range(m):
    if a[i] < total / (4 * m):
        canPick = False

if canPick is True:
    print("Yes")
else:
    print("No")
N = input()
turi = N % 1000
if turi != 0:
  turi = 1000 - turi
print(turi)

### FIXED CODE ###

N = int(input())
turi = N % 1000
if turi != 0:
  turi = 1000 - turi
print(turi)
from collections import deque
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
BC=sorted([list(map(int,input().split())) for i in range(m)],key=lambda x:x[1])

cnt,flag=0,True
A=deque(A)
for b,c in BC[::-1]:
    if not flag:break
    for i in range(b):
        if A[0]<c:
            cnt +=c
            A.popleft()
        else:
            flag=False
print(cnt+sum(A))

### FIXED CODE ###

from collections import deque
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
BC=sorted([list(map(int,input().split())) for i in range(m)],key=lambda x:x[1])

A=deque(A)
for b,c in BC[::-1]:
    if len(A)==0:break
    for i in range(b):
        if A[0]<c:
            A.append(c)
            A.popleft()
        else:break
print(sum(A))
S = input().split()
T = input().split()

ans = 0

for i in range(3) :
	if S[i] == T[i] :
		ans += 1

print(ans)

### FIXED CODE ###

S = input()
T = input()

ans = 0

if S[0] == T[0] :
	ans += 1

if S[1] == T[1] :
	ans += 1

if S[2] == T[2] :
	ans += 1

print(ans)
A, B = map(int, input())
S = input()
if S[0:A].isdigit()==True and S[A]== "-" and S[A+1:A+B+1]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

A, B = map(int, input().split())
S = input()
if S[0:A].isdigit() and S[A]== "-" and S[A+1:A+B+1].isdigit():
  print("Yes")
else:
  print("No")
import math
a, b, c, d = map(int, input().split())
m=0
e = c * d/math.gcd(c,d)
num_c = int(b/c)-int((a-1)/c)
num_d = int(b/d)-int((a-1)/d)
num_e = int(b/e)-int((a-1)/e)
m = num_c + num_d - num_e
print(b-a+1-m)

### FIXED CODE ###

from fractions import gcd
a, b, c, d = map(int, input().split())

e = (c*d)//gcd(c,d)

def calc(x):
    return x - (x//c)-(x//d)+(x//e)

print(calc(b)-calc(a-1))
n = int(input())
o = {""}
for i in range(n):
    a = len(o)
    op, ob = map(str, input().split())
    if op == "find"
        o.add(ob)
        if len(o) > a:
            print("no")
            o.discard(ob)
        else:
            print("yes")
    else:
        o.add(ob)


### FIXED CODE ###

n = int(input())
o = {""}
for i in range(n):
    a = len(o)
    op, ob = map(str, input().split())
    if op == "find":
        o.add(ob)
        if len(o) > a:
            print("no")
            o.discard(ob)
        else:
            print("yes")
    else:
        o.add(ob)
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
import heapq as hp
s = x+y
u = []
hp.heapify(u)
for i in range(a):
    hp.heappush(u,[-p[i],'r'])
for i in range(c):
    hp.heappush(u,[-r[i],'m'])
v = []
hp.heapify(v)
for i in range(b):
    hp.heappush(v,[-q[i],'g'])
for i in range(c):
    hp.heappush(v,[-r[i],'m'])
z = []
ans = 0
hp.heapify(z)
for i in range(a):
    hp.heappush(z,[-p[i],'r'])
for i in range(b):
    hp.heappush(z,[-q[i],'g'])
for i in range(c):
    hp.heappush(z,[-r[i],'m'])
while s and x and y:
    t = hp.heappop(z)
    ans += -t[0]
    if t[1] == 'r':
        x -= 1
        s -=1
    elif t[1] == 'g':
        y -= 1
        s -= 1
    else:
        s -= 1
if s > 0 and x > 0:
    while s:
        t = hp.heappop(u)
        if t[1] == 'r':
            continue
        else:
            ans += -t[0]
            s -= 1
elif s > 0 and y > 0:
    while s:
        t = hp.heappop(v)
        if t[1] == 'g':
            continue
        else:
            ans += -t[0]
            s -= 1
print(ans)

### FIXED CODE ###

x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
import heapq as hp
s = x+y
u = []
hp.heapify(u)
for i in range(a):
    hp.heappush(u,[-p[i],'r'])
for i in range(c):
    hp.heappush(u,[-r[i],'m'])
v = []
hp.heapify(v)
for i in range(b):
    hp.heappush(v,[-q[i],'g'])
for i in range(c):
    hp.heappush(v,[-r[i],'m'])
z = []
ans = 0
hp.heapify(z)
for i in range(a):
    hp.heappush(z,[-p[i],'r'])
for i in range(b):
    hp.heappush(z,[-q[i],'g'])
for i in range(c):
    hp.heappush(z,[-r[i],'m'])
while s and x and y:
    t = hp.heappop(z)
    ans += -t[0]
    if t[1] == 'r':
        x -= 1
        s -=1
    elif t[1] == 'g':
        y -= 1
        s -= 1
    else:
        s -= 1
if s > 0 and x > 0:
    while s:
        t = hp.heappop(z)
        if t[1] == 'g':
            continue
        else:
            ans += -t[0]
            s -= 1
elif s > 0 and y > 0:
    while s:
        t = hp.heappop(z)
        if t[1] == 'r':
            continue
        else:
            ans += -t[0]
            s -= 1
print(ans)
import numpy as np

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

dp = np.zeros(W+1, dtype=int64)

for i in range(N):
  w,v = map(int,input().split())
  np.maximum(dp[:-w]+v,dp[w:], out=dp[w:])

print(dp[-1])


### FIXED CODE ###

import numpy as np

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

dp = np.zeros(W+1, dtype=np.int64)

for _ in range(N):
  w,v = map(int,input().split())
  np.maximum(dp[:-w]+v,dp[w:], out=dp[w:])

print(dp[-1])
n=int(input())
li=list(map(int, input().split()))
ans=1
for i in range(1,n):
    lis=li[:i]
    if min(lis)>=li[i]:
        ans=ans+1
print(ans)


### FIXED CODE ###

n,m=map(int, input().split())
if n==m:
    print('Yes')
else:
    print('No')
from fracions import gcd
from collections import deque

a, b = map(int, input().split())
x = gcd(a, b)
y = int(x ** 0.5)
cd = deque([])
if x ** 0.5 % 1 == 0:
    cd.append(y)
    y -= 1
prime = []
for i in range(y, 0, -1):
    if x % i == 0:
        cd.appendleft(i)
        cd.append(x // i)

def prime_check(x, prime):
    for y in prime:
        if x % y == 0:
            return False
    return True

for x in cd:
    if prime_check(x, prime) and x != 1:
        prime.append(x)
print(len(prime) + 1)

### FIXED CODE ###

from fractions import gcd
from collections import deque

a, b = map(int, input().split())
x = gcd(a, b)
y = int(x ** 0.5)
cd = deque([])
if x ** 0.5 % 1 == 0:
    cd.append(y)
    y -= 1
prime = []
for i in range(y, 0, -1):
    if x % i == 0:
        cd.appendleft(i)
        cd.append(x // i)

def prime_check(x, prime):
    for y in prime:
        if x % y == 0:
            return False
    return True

for x in cd:
    if prime_check(x, prime) and x != 1:
        prime.append(x)
print(len(prime) + 1)
s = [int(x) for in list(input())]
cand = []
for c1, c2, c3 in zip(s, s[1:], s[2:]):
  res = abs(c1 * 100 + c2 * 10 + c3 - 753)
  cand.append(res)
print(min(cand))
  


### FIXED CODE ###

s = [int(x) for x in list(input())]
cand = []
for c1, c2, c3 in zip(s, s[1:], s[2:]):
  res = abs(c1 * 100 + c2 * 10 + c3 - 753)
  cand.append(res)
print(min(cand))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
N,M,X = map(int,input().split()) #整数の入力
a = list(map(int,input().split()))
#検問所の入力
b=[]
c=[]
for i in range(X+1,N): #X+1からNの範囲の整数について 
  if i in a: #ある整数が検問所の整数として存在する
    b.append(1)
for i in range(1,X): #1からX-1の範囲の整数について
  if i in a: #ある整数が検問所の整数として存在する
    c.append(1)
print(min(sum(b),sum(c)))

### FIXED CODE ###

# -*- coding: utf-8 -*-
A,B,X= map(int,input().split())
if A + B >= X and X >= A:
  print("YES")
else:
  print("NO")
li = list(map(int,input().split()))
li[0] = a
li[4] = e
li[5] = k

if e - a <= 15:
    print("Yay!")
else:
    print(":(")

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e - a <= k:
    print("Yay!")
else:
    print(":(")
import sys,math,collections,itertools
input = sys.stdin.readline

H,W,D=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(H)]
Q = int(input())
LR=[list(map(int,input().split())) for i in range(Q)]


dict_map = {}
for ih in range(H):
    for iw in range(W):
        dict_map[A[ih][iw]]=(ih,iw)

memo = [[-1]*(W*H+1) for _ in range(W*H+1)]

for i in range(Q):
    L = LR[i][0]
    R = LR[i][1]
    useMP = 0
    if memo[L][R] == -1:
        point = range(L,R+1,D)
        for p in range(1,len(point)):
            x0,y0 = dict_map[point[p-1]]
            x1,y1 = dict_map[point[p]]
            useMP += abs(x0-x1)+abs(y0-y1)
            memo[(point[p-1])][point[p]]=abs(x0-x1)+abs(y0-y1)
        memo[L][R]=useMP 
          
    else:
        useMP = memo[L][R]
    print(useMP)


### FIXED CODE ###

import sys,math,collections,itertools
input = sys.stdin.readline

H,W,D=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(H)]
Q = int(input())
LR=[list(map(int,input().split())) for i in range(Q)]


dict_map = {}
for ih in range(H):
    for iw in range(W):
        dict_map[A[ih][iw]]=(ih,iw)

memo = [-1]*(H*W+1)
for i in range(1,D+1):
    useMP = 0
    direct = range(i,H*W+1,D)
    memo[i]=0
    for p in range(len(direct)-1):
        x0,y0 = dict_map[direct[p]]
        x1,y1 = dict_map[direct[p+1]]
        dist = abs(x0-x1)+abs(y0-y1)
        useMP += dist
        memo[direct[p+1]]=useMP

for q in range(Q):
    L,R=LR[q]
    print(memo[R]-memo[L])