Harryxun/stf_run huggingface dataset:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from bisect import bisect_left
from sys import stdin
from heapq import heappush, heappop
import numpy as np


readl = stdin.readline
def main():
  ## input
  N,Q = map(int, readl().rstrip().split())
  STX = [list(map(int, readl().rstrip().split())) for _ in range(N)]
  Dn = np.asarray([int(readl().rstrip()) for _ in range(Q)] + [10**10])
  ans = []

  for s,t,x in sorted(STX,key=lambda x:x[2]):
    l = bisect_left(Dn,s-x)
    t -= x
    r = l
    while Dn[r] < t:
      heappush(ans, (Dn[r],x))
      r += 1
    del Dn[l:r]

  for d in Dn[:-1]:
    heappush(ans, (d,-1))

  return ans,Q


if __name__ == "__main__":
  ans,n = main()
  for _ in range(n):
    print(heappop(ans)[1])    


### FIXED CODE ###

import sys
from bisect import bisect_left



N,Q = map(int, input().split())
lines = sys.stdin.readlines()
kkk = []
for line in lines[:N]:
  s, t, x = map(int, line.split())
  kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[N:]))

ans = [-1] * Q
skip = [-1] * Q
for x, s, t in kkk:
  ss = bisect_left(ddd, s - x)
  tt = bisect_left(ddd, t - x)
  while ss < tt:
    sk = skip[ss]
    if sk == -1:
      ans[ss] = x
      skip[ss] = tt
      ss += 1
    else:
      ss = sk

print('\n'.join(map(str, ans)))
from collections import deque
S =input()
counter = 0
S = list(S)
q = deque([])
for i in range(len(S)):
    q.append(S[i])
for i in range(len(S)):
    if q:
        s1 = q.popleft()
        s2 = q.popleft()
        if(s1 != s2):
            counter+=2
        else:
            q.append(s1)
            q.appendleft(s2)
    else:
        break
print(counter)

### FIXED CODE ###

S =input()
S = list(S)
c_one = S.count('1')
c_zero = S.count('0')
print(min(c_one,c_zero)*2)
import math
sys.setrecursionlimit(10**9)

def main():
    A,B,C,K = map(int,input().split())

    if K<= A:
        print(K)
    elif K<=B:
        print(A)
    else:
        print(2*A+B-K)

if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
import math
sys.setrecursionlimit(10**9)

def main():
    A,B,C,K = map(int,input().split())

    if K<= A:
        print(K)
    elif K<=B:
        print(A)
    else:
        print(2*A+B-K)

if __name__ == "__main__":
  main()
import numpy as np
from scipy.ndimage.interpolation import shift as scipy_shift

class shift:
    def __init__(self,a):
        self.arr = a
        self.height = a.shape[0]
        self.width = a.shape[1]
    def shifted(self,down,right):
        temp1 = self.arr[list(np.linspace(-down, -down + self.height - 1, self.height, dtype=int) % self.height), :]
        temp2 = temp1[:, list(np.linspace(-right, -right + self.width - 1, self.width, dtype=int) % self.width)]
        return temp2
    def shifted_zero(self,down,right):
        index_vertical = np.arange(self.height)
        index_horizontal = np.arange(self.width)
        temp1 = self.arr[list(scipy_shift(index_vertical, down, output = int, mode = 'constant')),:]
        temp2 = temp1[:,list(scipy_shift(index_horizontal, right, output = int, mode = 'constant'))]
        return temp2
    def is_sym(self,down,right):
        temp = self.shifted(down,right)
        delta = temp - temp.T
        return(not (delta*delta).sum())



N = int(input())
array = [list(input()) for i in range(N)]
array_int = np.array([[ord(i) for i in j] for j in array])

count = np.array([[shift(array_int).is_sym(i,j) for i in range(N)] for j in range(N)])
print(count.sum())

### FIXED CODE ###

import numpy as np
from scipy.ndimage.interpolation import shift as scipy_shift

class shift:
    def __init__(self,a):
        self.arr = a
        self.height = a.shape[0]
        self.width = a.shape[1]
    def shifted(self,down,right):
        temp1 = self.arr[list(np.linspace(-down, -down + self.height - 1, self.height).astype(np.int32) % self.height), :]
        temp2 = temp1[:, list(np.linspace(-right, -right + self.width - 1, self.width).astype(np.int32) % self.width)]
        return temp2
    def shifted_zero(self,down,right):
        index_vertical = np.arange(self.height)
        index_horizontal = np.arange(self.width)
        temp1 = self.arr[list(scipy_shift(index_vertical, down, output = int, mode = 'constant')),:]
        temp2 = temp1[:,list(scipy_shift(index_horizontal, right, output = int, mode = 'constant'))]
        return temp2
    def is_sym(self,down,right):
        temp = self.shifted(down,right)
        delta = temp - temp.T
        return(not (delta*delta).sum())



N = int(input())
array = [list(input()) for i in range(N)]
array_int = np.array([[ord(i) for i in j] for j in array])

if N >= 2:
    count = np.array([shift(array_int).is_sym(0,i)*(N-i) for i in range(N)]).sum() + np.array([shift(array_int).is_sym(i,0)*(N-i) for i in range(1,N)]).sum()
else:
    count =  int(shift(array_int).is_sym(0,0))
print(count)
n = int(input())
A = list(map(int, input().split()))[
ans = 1
for a in A:
  if a%2==0:
    if a%3!=0 and a%5!=0:
      ans = 0
print('APPROVED' if ans else 'DENIED')

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
  if a%2==0:
    if a%3!=0 and a%5!=0:
      ans = 0
print('APPROVED' if ans else 'DENIED')
import copy
N = int(input())
ai = list(map(int, input().split()))

def lcm_list(l):
    if len(l) <= 1:
        return l[0]
    
    a = l.pop(len(l)-1)
    b = l.pop(len(l)-1)
    ans = lcm(a, b)
    l.append(ans)
    return lcm_list(l)

def lcm(a, b):
    return a * b // gcd(a, b)

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)

bi = copy.deepcopy(ai)
lcm_a = lcm_list(ai) - 1
ans = 0
for a in bi:
    ans += lcm_a % a

print(ans)

### FIXED CODE ###

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

ans = 0
for a in ai:
    ans += a - 1

print(ans)
l=[]
for i in range(1,n+1):
  l.append(abs(l-1+i))
mi=l.index(min(l))
print(n*(l-1)+sum(range(1,n+1))-l-mi)

### FIXED CODE ###

import math
a,b,c,d=map(int,input().split())
x=b//c-(a-1)//c
y=b//d-(a-1)//d
g=math.gcd(c,d)
l=c*d//g
z=b//l-(a-1)//l
print(b-a+1-x-y+z)
n=int(input())
a=[]
for i in range(n):
  x=int(input())
  a.append(x)
d={}
f=0
maxi=0
for i in range(n):
  if((a[i]-1) in d):
    d[a[i]]=d[a[i]-1]+1
    if(f==0):
      maxi=d[a[i]]
    else:
      if(d[a[i]]>maxi):
        maxi=d[a[i]]
  else:
    d[a[i]]=0
print(n-maxi-1)



### FIXED CODE ###

a,b,c,k=map(int,input().split())
if(k%2==0):
  print(a-b)
else:
  print(b-a)
N = input()
K = int(input())
if N[0] == '1':
  print(N[1])
else:
  print(N[0])
  

### FIXED CODE ###

N = input()
K = int(input())
ans = '1'
for i in range(K):
  if i >= len(N):
    break
  if N[i] != '1':
    ans = N[i]
    break
print(ans)
x = int(input())

def isPrime(n):
  if n%2==0 or n%3==0: return True
  for i in range(2, int(n**0.5)+1):
    if n%i==0: return False
  return True
primes = [i for i in range(2,1000) if isPrime(i)]

def isExponentiation(n):
  i = 0
  flag = False
  while(primes[i]<n):
    if n%primes[i]==0:
      if flag: return False
      else: flag = True
    i+=1
  return flag

print( max([i for i in range(x) if isExponentiation(i)]) )

### FIXED CODE ###

x = int(input())

def isPrime(n):
  if n%2 == 0 or n%3 == 0: return True
  if n<3: return False
  for i in range( 2, int(n**0.5) +1):
    if n%i == 0: return False
  return True

primes = [i for i in range(1, 32) if isPrime(i)]

def isExp(n):
  if n==1: return True
  for i in [p for p in primes if p<int(n**0.5)+1]:
    p = 0
    while i**p<=n:
      if i**p == n: return True
      p+=1
  return False

def solve():
  for i in range(x,0,-1):
    if isExp(i): return i

print(solve())
import sys
n,m = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
 
b=[]
for i in range(0,m):
    
    if A[i][0]==1 and A[i][1]==0:
        print(-1)
        sys.exit()
    else:
        b.append(A[i][1]*pow(10,m-A[i][0]))

if n>1:
    b.remove(0)
    
b=list(set(b))
 
c=[]
for i in range(len(b)):
    c.append(len(str(b[i])))
    
c=list(set(c))


 
if len(b)==len(c) and len(str(sum(b)))==n:
    print(sum(b))
else:
    print(-1)

### FIXED CODE ###

import sys
n,m = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
 
b=[pow(10,n-1)]
count=0
for i in range(0,m):
    
    if A[i][0]==1 and A[i][1]==0 and n>1:
        print(-1)
        sys.exit()
    else:
        b.append(A[i][1]*pow(10,n-A[i][0]))
        if n-A[i][0]==n-1:
            count+=1

#print(b,count)          
if count>0 or n==1:
    b.remove(pow(10,n-1))

if n>1:
    #print([i for i in b if i != 0])
    b=[i for i in b if i != 0]


#print(b)

b=list(set(b))
 
c=[]
for i in range(len(b)):
    c.append(len(str(b[i])))
    
c=list(set(c))

#print(b,c)
 
if len(b)==len(c) and len(str(sum(b)))==n:
    print(sum(b))
else:
    print(-1)
N,K = input.split()
if K==1 :
  print("0")
else : 
  print(N%K)

### FIXED CODE ###

N, K = map(int,input().split())
if K==1: print(0)
else: print(N-K)
import sys
from fractions import gcd

input = sys.stdin.readline

N, X = map(int, input().split())
x = list(map(int, input().split()))

if N == 1:
    print(abs(X - x[0]))
    exit()

x.append(X)
x.sort()
diff = []
ans = []

for i in range(N-1):
    diff.append(x[i+1] - x[i])

for i in range(N-2):
    ans.append(gcd(diff[i], diff[i+1]))

print(min(ans))

### FIXED CODE ###

import sys
from fractions import gcd

input = sys.stdin.readline

N, X = map(int, input().split())
x = list(map(int, input().split()))

if N == 1:
    print(abs(X - x[0]))
    exit()

x.append(X)
x.sort()
diff = []
ans = []

for i in range(N):
    diff.append(x[i+1] - x[i])

for i in range(N-1):
    ans.append(gcd(diff[i], diff[i+1]))

print(min(ans))
s = sorted(input().split())
ans = 0
for i in s:
    if s[i] == '+':
        ans+=1
    else:
        ans -=1
print(ans)

### FIXED CODE ###

s = sorted(input())
ans = 0
for i in s:
    if i == '+':
        ans+=1
    else:
        ans -=1
print(ans)
import sys
S=input()
for i in range(n//2):
    s=S[2*i]
    if s=="L":
        print("No")
        sys.exit()
    s=S[2*i+1]
    if s=="R":
        print("No")
        sys.exit()
if n%2==1:
    s=S[-1]
    if s=="L":
        print("No")
        sys.exit()
print("Yes")

### FIXED CODE ###

import sys
S=input()
n=len(S)
if n>1:
    for i in range(n//2):
        s=S[2*i]
        if s=="L":
            print("No")
            sys.exit()
        s=S[2*i+1]
        if s=="R":
            print("No")
            sys.exit()
if n%2==1:
    s=S[-1]
    if s=="L":
        print("No")
        sys.exit()
print("Yes")
N, K = list(map(int, input().split()))
__max = 10**5+1
buff = [0 for i in range(__max)]
a = []
ans = 0
b = 0
for i in range(N):
    _a, _b = list(map(int, input().split()))
    buff[_a] = _b


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

    if K <= buff[i]:
        print(i)
        exit()

    K -= buff[i]


### FIXED CODE ###

amax = 100000
cnt = [0 for i in range(amax+1)]


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

for i in range(N):
    a, b = list(map(int, input().split()))
    cnt[a] += b


for ans in range(1, amax+1):
    if K <= cnt[ans]:
        print(ans)
        break
    K -= cnt[ans]
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))
from math import sqrt
from itertools import combinations
import random
from math import gcd
N = int(input())
def primesd(N):
    P = [2]
    L = (N-1)//2
    searched = [False]*(L+1)
    for i in range(1, L+1):
        if searched[i]:
            continue
        j = i*2+1
        P.append(j)
        searched[i::j] = [True]*(((L-i)//j)+1)
    return P

P = primesd(int(sqrt(30000)))
S = [True]*30001
S[:2] = [False]*2

for p in P:
    i = p
    while i <= 30000:
        S[i] = False
        i *= p

for a, b in combinations(P, 2):
    S[a*b] = False

for a, b, c in combinations(P, 3):
    if a*b*c < 30000:
        S[a*b*c] = False

for a, b, c, d in combinations(P, 4):
    if a*b*c*d < 30000:
        S[a*b*c*d] = False

for a, b, c, d, e in combinations(P, 5):
    if a*b*c*d*e < 30000:
        S[a*b*c*d*e] = False

numbers = [i for i, s in enumerate(S) if s]

count = 0
while True:
    sample = random.sample(numbers, N-1)
    sum_ = sum(sample)
    if sum_ % 11 != 0:
        continue
    elif any([s%11!=0 for s in sample]):
        sum_ += 11
        for s in sample:
            if gcd(s, sum_-s) == 1:
                print("break")
                break
        else:
            sample += [1]
            print(*sample)
            break

### FIXED CODE ###

# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(input())
if N == 3:
    print("2 5 63")
    exit()
elif N == 4:
    print("2 5 20 63")
    exit()
elif N == 5:
    print("7 1580 9438 11373 22962")
    exit()

numbers = []

for k in range(0, 5000):
    numbers.extend([6*k+2, 6*k+3, 6*k+4, 6*k+6])

ans = numbers[:N]
S = sum(ans)


if S%6 == 0:
    pass
elif S%6 == 2:
    del ans[4]
    ans.append((ans[-1]//6 + 1)*6)
elif S%6 == 3:
    del ans[5]
    ans.append((ans[-1]//6 + 1)*6)
else:
    x, y = (ans[-1]//6)*6+4, (ans[-1]//6)*6+10
    ans.append(x if x > ans[-1] else y)
    del ans[5]
print(*ans)
s=str(input())
t=str(input())
ans=0
f=[]
g=len(s)
h=len(t)
for i in range(g-h):
    for j in range(h):
        if s[i+j]!=t[j]:
            ans+=1
    f.append(ans)
    ans=0
f.sort()
print(f[0])


### FIXED CODE ###

S = input()
T = input()
n = len(S)
m = len(T)
x = int(1e9)
for i in range(n-m+1):
  cnt = 0
  for j in range(m):
    cnt += (S[i+j] != T[j])
  x = min(x, cnt)
print(x)
import math

MOD = 10 ** 9 + 7


def cmb(n, r):
    total = 1
    for i in range(r):
        total *= (n - i) % MOD
    return total * pow(math.factorial(r), MOD - 2, MOD) % MOD


def calc(n, r):
    ret = 1
    for i in range(r):
        ret = ret * (n - i) % MOD
    return ret * pow(factorial(r), MOD - 2, MOD) % MOD


if __name__ == '__main__':
    n, a, b = list(map(int, input().split(" ")))

    total = pow(2, n, MOD)
    a_total = calc(n, a)
    b_total = calc(n, b)
    print((total - a_total - b_total - 1) % MOD)

### FIXED CODE ###

from math import factorial
N, A, B = map(int, input().split())
MOD = 10 ** 9 + 7

def calc(n):
    ret = 1
    for i in range(n):
        ret = ret * (N - i) % MOD
    return ret * pow(factorial(n), MOD - 2, MOD) % MOD

print(max(0, (pow(2, N, MOD) - ((calc(A) + calc(B)) % MOD) - 1) % MOD))
k, s = map(int, input().split())
ans = 0
for i in range(k+1):
	for j in range(k+1):
     	for k in range(k+1):
          if i + j + k ==s:
            ans += 1
print(ans)        

### FIXED CODE ###

k, s = map(int, input().split())
 
ans = 0
for i in range(k+1):
  for j in range(k+1):
    if 0 <= s - i - j <= k:
    	ans += 1
        
print(ans)
N = int(input())
S = input()
count = 0
ans = 1
m = 10**9 + 7
 
for i in range(N):
  if s[2*i] == "W":
    ans *= (i - (count*2))
    count += 1
  if s[2*i + 1] == "B":
    ans *= (i - (count*2))
    count += 1
if count != N:
  print(0)
else:
  for o in range(1, N+1):
    ans *= o
    ans %= m
  print(ans %= m)

### FIXED CODE ###

N = int(input())
S = input()
count = 0
ans = 1
m = 10**9 + 7
 
for i in range(N):
  if S[2*i] == "W":
    ans = ans * ((2*i) - (count*2))%m
    count += 1
  if S[2*i + 1] == "B":
    ans = ans * ((2*i + 1) - (count*2))%m
    count += 1
 
if count != N:
  print(0)
else:
  for o in range(1, N+1):
    ans *= o
    ans %= m
  print(ans % m)
S = map(int,input())

if S[0]==S[1] or S[1]==S[2] or S[2]==S[3] or S[3]==S[4] :
	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')
i = 1
while True:
    x = int(input().strip())
    if x == '0':
        break
    print 'Case %d : %d' % (i,x)
    i += 1

### FIXED CODE ###

i = 1
while True:
    x = int(input().strip())
    if x == 0:
        break
    else:
        print ("Case {}: {}".format(i,x))
        i += 1
import numpy as np
import itertools
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
a = np.array(l)
dic = itertools.permutations(n,n)
sum = 0
for i in range(len(dic)):
  for j in range(n-1):
    sum += np.linalg.norm(a[dic[i][j]]-a[dic[i][j+1]])
print(sum//len(dic))

### FIXED CODE ###

n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
sum = 0
for i in range(n):
  for j in range(i+1,n):
    sum += ((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5
print(2*sum/n)
# -*- coding: utf-8 -*-
a, b, t = map(int, input().split())

# 何回生産出来るか
p = (t+0.5)//a

anc = int(p*b)

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
a, b, t = map(int, input().split())

t = (t+0.5)//a


bbb = int(t*b)

print(bbb)
from itertools import permutations
import sys
import heapq
from collections import Counter
from collections import deque
from math import gcd
from math import factorial
from math import sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


#ここから書き始める
n = int(input())
a = []
for i in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
total = 0
for i in permutations(a):
    # print(i)
    for j in range(1, n):
        x_distance = i[j][0] - i[j - 1][0]
        y_distance = i[j][1] - i[j - 1][1]
        d = sqrt(x_distance ** 2 + y_distance ** 2)
        total += d
ans = total / factorial(n)
print(ans)

### FIXED CODE ###

import itertools
import math
n = int(input())
positions = []
for i in range(n):
    x, y = map(int, input().split())
    positions.append([x, y])
# print(positions)
ans = 0
for i in itertools.permutations(positions):
    total_distance = 0
    for j in range(1, len(i)):
        x_gap = i[j][0] - i[j - 1][0]
        y_gap = i[j][1] - i[j - 1][1]
        total_distance += math.sqrt(x_gap ** 2 + y_gap ** 2)
    ans += total_distance
ans /= math.factorial(n)
print(ans)
n, k = map(int, input().split())
hlis = list(map(int, input().split()))
# hlis.sort(reverse=True)

for i in range(0, k):
  cache = max(hlis)
  hlis.remove(cache)
print(sum(hlis))

### FIXED CODE ###

n, k = map(int, input().split())
hlis = list(map(int, input().split()))
hlis.sort(reverse=True)

del hlis[0:k]
print(sum(hlis))
GRID = []
for _ in range(3):
    GRID.append([int(c) for c in input().split()])

def diff(row):
    min_num = min(row)
    return list(map(lambda c: c - min_num, row))

def main():
    ans = None
    prev = None
    while GRID:
        row = GRID.pop()
        curr = diff(row)
        if prev is None:
            prev = curr[:] # deep copy
        if curr != prev:
            ans = "No"
            break
    if ans is None:
        ans = "Yes"
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

N = int(input())
A = int(input())

def main():
    remnant = N % 500
    ans = "Yes" if A >= remnant else "No"
    print(ans)

if __name__ == "__main__":
    main()
n=int(input())
def lucas(n):
	if n==0:
		return 2
	if n==1:
		return 1
	if n>1:
		return lucas(n-1)+lucas(n-2)
print(lucas(n))


### FIXED CODE ###

a=input()
def check(n):
	if n[0]==n[1]:
		if n[1]==n[2]:
			return "Yes"
		else:
			return "No"
	else:
		if n[1]==n[2]:
			if n[2]==n[3]:
				return "Yes"
			else:
				return "No"
		else:
			return "No"
print(check(a))
N, M = map(int, input().split())
A = list(map(int, input().split()))
flag = True

for i in  A:
N = N - i
if N < 0:
flag = False
break

if flag == True:
print(N)
else:
print(-1)

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
flag = True
 
for i in  A:
  N = N - i
  if N < 0:
    flag = False
    break
 
if flag == True:
  print(N)
else:
  print(-1)
3
100000000 JPY
100.00000000 BTC
0.00000001 BTC

### FIXED CODE ###

N = int(input())
ans = 0.0
for _ in range(N):
    x, u = input().split()
    if u == "JPY":
        ans += float(x)
    else:
        ans += float(x) * 380000.0
print(ans)
A,B,K=(int(i) for i in input().split())
L=list(range(A,B+1))
a=B-A+1
if K>=a:
  for i in range(a):
    print(L[i])
else:
  S=list(set(L[:K])&set(L[a-K:a]))[:]
  for i in range(len(S)):
    print(S[i])

### FIXED CODE ###

A,B,K=(int(i) for i in input().split())
a=B-A+1
if K>=a:
  for i in range(A,B+1):
    print(i)
else:
  L1=list(range(A,A+K))
  L2=list(range(B-K+1,B+1))
  S=list(set(L1+L2))
  S.sort()
  for i in S:
    print(i)
H,N = map(int, input().split())
lists = [] 
lists.append(int, input().split())
lists = lists.sort()
if N>=2 and lists[N-1]+lists[N-2]>=H:
  print('Yes')
If N==1 and lists[0]>=H:
  print('Yes')
if N==1 and lists[0]<H:
  print('No')
else:
  print('No')

### FIXED CODE ###

H, A = map(int,input().split())
a = int(H/A)
b = H/A
if a==b:
  print(a)
else:
  c = a+1
  print(c)
c = a*b
if c % 2 == 0:
  print('Even')
else:
  print('Odd')

### FIXED CODE ###

a,b=map(int,input().split())
if a*b % 2 == 0:
  print('Even')
else:
  print('Odd')
L, R = map(int, input().split())
mod = 2019

l = L // mod
r = R // mod

if l != r:
    print(0)
else:
   l_ = L % mod
   r_ = R % mod
   ans = 2019
   for i in range(l_, r_):
       for j in range(i+1, r_+1):
           a = i * j % mod
           ans = min(ans, a)
           if ans == 1:
               break
        if ans == 1:
            break
   print(ans)


### FIXED CODE ###

L, R = map(int, input().split())
mod = 2019

l = L // mod
r = R // mod

if l != r:
    print(0)
else:
   l_ = L % mod
   r_ = R % mod
   ans = 2019
   for i in range(l_, r_):
       for j in range(i+1, r_+1):
           a = i * j % mod
           ans = min(ans, a)
   print(ans)
s = input()
a = int(s[:2])
b = int(s[2:])
if a <= 12 && a > 0:
	if b <=12 && b > 0:
		print('AMBIGUOUS')
	else:
		print('MMYY')
else:
	if b <=12 && b > 0:
		print('YYMM')
	else:
		print('NA')

### FIXED CODE ###

s = input()
a = int(s[:2])
b = int(s[2:])
if a <= 12 and a > 0:
	if b <=12 and b > 0:
		print('AMBIGUOUS')
	else:
		print('MMYY')
else:
	if b <=12 and b > 0:
		print('YYMM')
	else:
		print('NA')
dat = input().split()

for i in dat:
      i = int(i)

dat.sort(reverse=True)

asum=0
bsun=0

for i in range(len(dat)):
	if i%2==0:
		asum = asum + dat[i]
	else:
		bsum bsum + dat[i]
		
print(asum-bsum)

### FIXED CODE ###

n = int(input())
dat = list(input().split())

dat = list(map(int,dat))

dat.sort(reverse=True)

asum = 0
bsum = 0

for i in range(n):
	if i % 2 == 0:
		asum = asum + dat[i]
	else:
		bsum = bsum + dat[i]
		
print(asum-bsum)
H,W,D=list(map(int,input().split()))
arr=[0 for i in range(H*W+1)]
for y in range(H):
    for x,n in enumerate(map(int,input().split())):
        arr[n]=[x,y]

dic={}

Q=int(input())
for i in range(Q):
    ans=0
    now,goal= list(map(int,input().split()))
    nx=arr[now][0]
    ny=arr[now][1]
    tmp=now
    for j in range((goal-now)//D):
        if dic.get(tmp*H*W+goal,0)!=0:
            dic[now*H*W+goal]=ans+dic[tmp*H*W+goal]
            break
        tmp+=D
        x=arr[tmp][0]
        y=arr[tmp][1]
        ans+=abs(x-nx)+abs(y-ny)
        nx=x
        ny=y
        dic[now*H*W+tmp]=ans
    print(dic[now*H*W+goal])

### FIXED CODE ###

H,W,D=list(map(int,input().split()))
map_=[[0,0] for _ in range(H*W+1)]
for y in range(H):
    for x,A in enumerate(map(int,input().split())):
        map_[A]=[x+1,y+1]

cost=[0 for _ in range(H*W+1)]
for i in range(D+1,H*W+1):
    cost[i]+=abs(map_[i][0]-map_[i-D][0])+abs(map_[i][1]-map_[i-D][1])+cost[i-D]
Q=int(input())
for i in range(Q):
    L,R=list(map(int,input().split()))
    print(cost[R]-cost[L])