Harryxun/stf_run huggingface dataset:
N,M =map(int,input().split())
a = [int(input()) for i in range(M)]
DP = [1]*N
mod = 10**9 + 7
for i in a:
    DP[i-1] = 0
for i in range(N):
    if(DP[i] != 0):
        if(i<1):
            DP[i+1] = DP[i]%mod
        else:
            DP[i] = (DP[i-2]%mod + DP[i-1]%mod)
print(DP[-1])

### FIXED CODE ###

N,M =map(int,input().split())
a = [int(input()) for i in range(M)]
DP = [1]*N
mod = 10**9 + 7
for i in a:
    DP[i-1] = 0
if(N != 1):
    for i in range(N):
        if(DP[i] != 0):
            if(i<1):
                DP[i] = DP[i-1]%mod
            else:
                DP[i] = (DP[i-2] + DP[i-1])%mod
else:
    DP = [1]
print(DP[-1])
"""Rooted Trees."""

class Node:
    def __init__(self, num, parent, rightSibling, *children):
        self.id = num
        self.parent = parent
        self.rightSibling = rightSibling
        self.children = list(children)
        self.depth = 0
    def showInfo(self):
        print('node {0}: '.format(self.id), end = '')
        print('parent = {0}, '.format(self.parent), end = '')
        print('depth = {0}, '.format(self.depth), end = '')
        if self.children and self.parent != -1:
            print('internal node, ', end = '')
        elif self.parent != -1:
            print('leaf, ', end = '')
        else:
            print('root, ', end = '')
        print('{0}'.format(self.children))

def setNode(num, k, *children):
    if T[num]:
        T[num].children = list(children)
    else:
        node = Node(num, -1, None, *children)
        T[num] = node
    if children:
        for i, x in enumerate(children[:-1]):
            if T[x]:
                T[x].parent = num
                T[x].rightSibling = children[i + 1]
            else:
                node = Node(x, num, children[i + 1])
                T[x] = node
        lastChild = children[-1]
        if T[lastChild]:
            T[lastChild].parent = num
        else:
            node = Node(lastChild, num, None)
            T[lastChild] = node

def setDepth(u, p):
    T[u].depth = p
    if T[u].children:
        setDepth(T[u].children[0], p + 1)
    if T[u].rightSibling:
        setDepth(T[u].rightSibling, p)

def findRoot(r):
    if T[r].parent == -1:
        return r
    findRoot(T[r].parent)


import sys

n = int(sys.stdin.readline())

T = [None for i in range(n)]

for x in sys.stdin.readlines():
    setNode(*list(map(int, x.split())))

r = findRoot(0)

setDepth(r, 0)

for x in T:
    x.showInfo()

### FIXED CODE ###

class Node:
    def __init__(self, num, parent, children):
        self.id = num
        self.parent = -1
        self.depth = 0
        self.type = None
        self.children = children
        
    def show_info(self):
        print('node {0}: parent = {1}, depth = {2}, {3}, {4}'.format(self.id,
                                                                     self.parent,
                                                                     self.depth,
                                                                     self.type,
                                                                     self.children))


def set_node(i_s):
    i_l = list(map(int, i_s.split()))
    num = i_l[0]
    children = i_l[2:]
    node = Node(num, -1, children)
    T[num] = node
    for n in children:
        T[-1] -= n

def set_pdt(n_i, parent, depth):
    node = T[n_i]
    node.parent = parent
    node.depth = depth
    if node.children:
        node.type = 'internal node'
        for n in node.children:
            set_pdt(n, n_i, depth + 1)
    else:
        node.type = 'leaf'


import sys

n = int(sys.stdin.readline())

T = [None] * n

T.append(int(n * (n - 1) / 2))

for x in sys.stdin.readlines():
    set_node(x)

set_pdt(T[-1], -1, 0)

T[T[-1]].type ='root'

for n in T[:-1]:
    n.show_info()
n = int(raw_input())
l = []
max = -10^9
x=0
for i in (n-1):
    l.append(int(raw_input())

for s in (n-1):
 for t in (s-1):
  x= l[n-s-1] - l[n-t-1]
  if max<x:
   max=x
printf('%d')%(max)

### FIXED CODE ###

n = int(raw_input())
max = -10**9
x1 = input() 
min = x1

for i in range(n-1):
 x = int(raw_input())

 if max < x-min:
  max = x- min
 if x< min:
  min = x
  
print max
N = int(input())
As = list(map(int, input().split()))

hs = []
ls = []

i = 0
if As[1] > As[0]:
  ls.append((As[0],0))
  f = 1
elif As[1] < As[0]:
  hs.append((As[0],0))
  f = 0
else:
  for j in range(2,N):
    if As[j] > As[0]:
      ls.append((As[0],0))
      f = 1
      i = j
      break
    elif As[j] < As[0]:
      hs.append((As[0],0))
      f = 0
      i = j
      break
  
while i < N-1:
  if f == 1 and As[i] > As[i+1]:
    hs.append((As[i],i))
    f = 0
  elif f == 0 and As[i] < As[i+1]:
    ls.append((As[i],i))
    f = 1
  i += 1
    
if As[N-2] < As[N-1]:
  hs.append((As[N-1],N-1))
elif As[N-2] > As[N-1]:
  ls.append((As[N-1],N-1))

if len(ls) == 1 and len(hs) == 1 and ls[0][1] > hs[0][1]:
  print(1000)
  exit()
if ls[0][1] > hs[0][1]:
  del hs[0]
if hs[-1][1] < ls[-1][1]:
  del ls[-1]
  
memo = [[[0]*2 for _ in range(len(ls)+1)]  for _ in range(2)]
memo[0][0][0] = 1000
memo[0][0][1] = 0
memo[1][0][0] = 1000
memo[1][0][1] = 0

for i in range(1,len(ls)+1):
  a = memo[1][i-1][0] // ls[i-1][0]
  if a > memo[0][i-1][1]:
    memo[0][i][0] = memo[1][i-1][0]-a*ls[i-1][0]
    memo[0][i][1] = a
  else:
    memo[0][i][0] = memo[1][i-1][0]
    memo[0][i][1] = 0
  b = memo[0][i][1]*hs[i-1][0] + memo[0][i][0]
  if b > memo[1][i-1][0]:
    memo[1][i][0] = b
    memo[1][i][1] = 0
  else:
    memo[1][i][0] = memo[0][i][0]
    memo[1][i][1] = memo[0][i][1]
    
print(memo[1][-1][0])

### FIXED CODE ###

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

rlt = 1000
for i in range(N-1):
  if As[i+1] > As[i]:
    rlt = (As[i+1]-As[i])*(rlt//As[i]) + rlt
    
print(rlt)
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

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

n, m = map(int, input().split())
s = str(input())
t = str(input())
l = lcc(n, m)
L = [0] * l
for i in range(n):
    L[i*(l//n)] = s[i]
for j in range(m):
    if L[j*(l//m)] == 0:
        L[j*(l//m)] = t[j]
    elif L[j*(l//m)] == t[j]:
        pass
    else:
        print(-1)
        break
else:
    print(l)


### FIXED CODE ###

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

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

n, m = map(int, input().split())
s = str(input())
t = str(input())
g = gcd(n, m)
l = lcm(n, m)
for i in range(g):
    if s[i*n//g] != t[i*m//g]:
        print(-1)
        break
else:
    print(l)
inf = 10**18
N = int(input())
S = []
C = []
for i in range(N):
    s,c = input().split()
    S.append(s)
    C.append(int(c))

def left(s1):
    res = inf
    if s1==s1[::-1]:
        return 0
    for i in range(N):
        s2 = S[i][::-1]
        c = C[i]
        if s1.startswith(s2):
            res = min(res,left(s1[len(s2):])+c)
        if s2.startswith(s1):
            res = min(res,right(s2[len(s1):])+c)
    return res

def right(s2):
    res = inf
    if s2==s2[::-1]:
        return 0
    for i in range(N):
        s1 = S[i]
        c = C[i]
        if s1.startswith(s2):
            res = min(res,left(s1[len(s2):])+c)
        if s2.startswith(s1):
            res = min(res,right(s2[len(s1):])+c)
    return res

ans = inf
for i in range(N):
    ans = min(ans,left(S[i])+C[i])

if ans == inf:
    ans = -1

print(ans)

### FIXED CODE ###

from heapq import heappush, heappop
inf = float('inf')
def dijkstra(graph:list, node:int, start:int) -> list:
    dist = [inf]*node

    dist[start] = 0
    heap = [(0,start)]
    while heap:
        cost,thisNode = heappop(heap)
        for NextCost,NextNode in graph[thisNode]:
            dist_cand = dist[thisNode]+NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode],NextNode))
    return dist

N = int(input())
S1 = []
S2 = []
C = []
for i in range(N):
    s,c = input().split()
    S1.append(s)
    S2.append(s[::-1])
    C.append(int(c))

d_v = {('',''):0,('l',''):1,('r',''):2}
idx = 3
for i in range(N):
    s = S1[i]
    for j in range(len(s)):
        for k in range(j,len(s)):
            ss_l = s[j:k+1]
            ss_r = ss_l[::-1]
            if ss_l != ss_r:
                if ('l',ss_l) not in d_v:
                    d_v[('l',ss_l)] = idx
                    idx += 1
                if ('r',ss_r) not in d_v:
                    d_v[('r',ss_r)] = idx
                    idx += 1

edge = [[] for _ in range(len(d_v))]

for i in range(N):
    s_l = S1[i]
    s_r = S2[i]
    c = C[i]
    for lr,ss in d_v:
        if ss == '':
            if lr == '':
                t = s_l
                if t==t[::-1]:
                    t = ''
                edge[0].append((c,d_v[('l',t)]))
            else:
                continue
        if lr == 'l':
            if ss.startswith(s_r):
                t = ss[len(s_r):]
                if t==t[::-1]:
                    t = ''
                edge[d_v[(lr,ss)]].append((c,d_v[('l',t)]))
            if s_r.startswith(ss):
                t = s_r[len(ss):]
                if t==t[::-1]:
                    t = ''
                edge[d_v[(lr,ss)]].append((c,d_v[('r',t)]))
        elif lr == 'r':
            if ss.startswith(s_l):
                t = ss[len(s_l):]
                if t==t[::-1]:
                    t = ''
                edge[d_v[(lr,ss)]].append((c,d_v[('r',t)]))
            if s_l.startswith(ss):
                t = s_l[len(ss):]
                if t==t[::-1]:
                    t = ''
                edge[d_v[(lr,ss)]].append((c,d_v[('l',t)]))
            

dist = dijkstra(edge,len(d_v),0)
ans = min(dist[1],dist[2])
if ans == inf:
    ans = -1

print(ans)
H, W = map(int, input().split(' '))
matrix = []
for _ in range(W):
    tmp = [0 if j == '.' else 1 for j in input()]
    matrix.append(tmp)

flag = 'Yes'
for i, row in enumerate(matrix):
    for j, s in enumerate(row):
        if s == 1:
            if j > 0 and row[j-1] == 0:
                if j < W - 1 and row[j+1] == 0:
                    if i > 0 and matrix[i-1][j] == 0:
                        if i < H - 1 and matrix[i+1][j] == 0:
                            flag = 'No'
                            break

print(flag)


### FIXED CODE ###

H, W = map(int, input().split(' '))
matrix = []
for _ in range(H):
    tmp = [0 if j == '.' else 1 for j in input()]
    matrix.append(tmp)

flag = 'Yes'
for i, row in enumerate(matrix):
    for j, s in enumerate(row):
        if s == 1:
            if (j > 0 and row[j-1] == 0) and (j < W - 1 and row[j+1] == 0):
                if (i > 0 and matrix[i-1][j] == 0) and (i < H - 1 and matrix[i+1][j] == 0):
                    flag = 'No'
                    break

print(flag)
import sys

sys.setrecursionlimit(10000)

def search(a, b, left, right):
    mid = int(left + (left - right) / 2)
    if(b[mid] == a):
        return b[mid]
    if(b[mid] >= a and a >= b[mid+1]):
        if(b[mid]- a >= a - b[mid+1]):
            return  b[mid+1]
        else:
            return b[mid]
    if(b[mid] >= a):
        return search(a, b, 0, mid)
    else:
        return search(a, b, mid, right)

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

b = sorted(a, reverse=True)
for i in b:
    m = i/2
    j = search(m, b, 0, len(b))
    print("%d %d" %(i, j))
    break

### FIXED CODE ###

import sys

sys.setrecursionlimit(10000)

def search(a, b, left, right):
    mid = int(left + (right - left) / 2)
    if(b[mid] == a):
        return b[mid]
    if(len(b) <= mid + 1):
        return b[mid]
    if(b[mid] >= a and a >= b[mid+1]):
        if(b[mid]- a >= a - b[mid+1]):
            return b[mid+1]
        else:
            return b[mid]
    if(b[mid] <= a):
        return search(a, b, left, mid)
    else:
        return search(a, b, mid, right)

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

b = sorted(a, reverse=True)
for i in b:
    m = i/2
    j = search(m, b, 0, len(b))
    print("%d %d" %(i, j))
    break
a, b = map(int, raw_input().split())
if a % 2 == 0 or b % 2 == 0:
    print('No')
else:
    print('Yes')


### FIXED CODE ###

a, b = map(int, input().split())
if a % 2 == 0 or b % 2 == 0:
    print('No')
else:
    print('Yes')
N=int(input())
XY=[]
for i in range(N):
  A=int(input())
  XY_i=[]
  for _ in range(A):
    x,y = map(int, input().split())
    x-=1
    XY_i.append([x,y])
  XY.append(XY_i)

ans=0
for bit_state in range(2**N):
  flag=True
  for i in range(N):
    if (bit_state>>i)&1:
      for x, y in XY[i]:
        if (bit_state >>x)&1 != y:
          flag=False
  if flag:
    ans=max(ans, bin(bit_state>>x).count("1"))
    
print(ans) 


### FIXED CODE ###

N=int(input())
XY=[[] for _ in range(N)]
for i in range(N):
  A=int(input())
  for _ in range(A):
    x,y = map(int, input().split())
    x-=1
    XY[i].append([x,y])

ans=0
for bit_state in range(2**N):
  flag=True
  for i in range(N):
    if (bit_state>>i)&1:
      for x, y in XY[i]:
        if (bit_state >>x)&1 != y:
          flag=False
  if flag:
    ans=max(ans, bin(bit_state).count("1"))
    
print(ans)
from collections import defaultdict
from math import factorial
N = int(input())
d = defaultdict(int)
for i in range(N):
    s = ''.join(sorted(input()))
    d[s] += 1
t = 0
for c in d.values():
    if 1 < c:
        t += factorial(c) / 2
print(int(t))

### FIXED CODE ###

from collections import defaultdict
from math import factorial
N = int(input())
d = defaultdict(int)
for i in range(N):
    s = ''.join(sorted(input()))
    d[s] += 1
t = 0
for c in d.values():
    if 1 < c:
        t += c * (c-1) // 2
print(t)
x = input().split()
a = int( x[0])
b = int( x[1])
 
if a > b:
    print( "a > b")
elif a < b:
    print( "a < b")
else:
    print( "a == b"

### FIXED CODE ###

x = input().split()
a = int( x[0])
b = int( x[1])
  
if a > b:
    print( "a > b")
elif a < b:
    print( "a < b")
else:
    print( "a == b")
N, K = map(int, input().split())

def combination(a, b):
    minb = min(a-b, b)
    r = 1
    for i in range(1, minb+1):
        r = r * (a-minb+i)/i
    return int(r)

for i in range(1, K+1):
    if i-1 == 0:
        must = 1
    else:
        must = combination(K-1, i-1)
    left_ball = N-K-i+1
    if left_ball < 0:
        print(0)
        continue
    can = combination(left_ball+i, i)
    print((must*can)%1000000007)

### FIXED CODE ###

N, K = map(int, input().split())
mod = 10**9+7

import math

def combination(a, b):
    minb = min(a-b, b)
    r = 1
    for j in range(1, minb+1):
        r = r * (a-minb+j)//j
    return int(r)

for i in range(1, K+1):
    if N==K and i!=1:
        print(0)
        continue
    must = combination(K-1, i-1)
    if must is None:
        print("K:"+str(K)+", i:"+str(i))
    left_ball = N-K-i+1
    if left_ball < 0:
        print(0)
        continue
    can = combination(left_ball+i, i)
    print((must*can)%mod)
ST = input().split()
s += ST[0]
s += ST[1]

### FIXED CODE ###

ST = input().split()
s = ""
s += ST[1]
s += ST[0]
print(s)
def calc(n, w):
    min_sub = 100000
    N = N
    num = w
    for i in range(1,N):
        S1 = num[:i]
        S2 = num[i:]
        sub = abs(sum(S1)-sum(S2))
        if min_sub > sub:
            min_sub = sub
    print(min_sub)
     
N = int(input())
W = [int(i) for i in input().split()]
calc(N, W)

### FIXED CODE ###

N = int(input())
W = [int(i) for i in input().split()]
a = []
for i in range(N - 1):
    a.append(abs(sum(W[:i+1]) - sum(W[i+1:])))

print(min(a))
import sys,fractions
sys.setrecursionlimit(10**5)
def input():
    return sys.stdin.readline()[:-1]

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

u = 10**9+7

from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

G = l[0]
for i in range(1,N):
    G = fractions.gcd(G,l[i])
    if G==1:
        break
gcd = G
L = [l[i]//gcd for i in range(N)]
lcm = lcm_list(L)

# print(lcm,gcd,'aaa')
ANS = 0
for i in range(N):
    elm = L[i]
    ANS += (lcm/elm)
    ANS %= u
print(ANS)

### FIXED CODE ###

import sys
from fractions import gcd
sys.setrecursionlimit(10**5)
def input():
    return sys.stdin.readline()[:-1]

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

u = 10**9+7

lcm = 1
s = 0
for i in range(N):
    k = l[i]
    g = gcd(k,lcm)
    t = k//g
    lcm = lcm*t
    s = s*t + lcm//k
print(s%u)
I=lambda:[int(i)for i in input().split()]
n,m=I()
P=I()
D={i:i for i in range(n+1)}
def U(x):
  if D[x]!=x:D[x]=U(D[x])
  return D[x]
for _ in [0]*m:
  x, y= I():D[U(x)]=U(y)
print(sum(U(i)==U(p)for i,p in enumerate(P,1)))

### FIXED CODE ###

I=lambda:[int(i) for i in input().split()]
n, m = I()
P = I()
D = {i:i for i in range(n+1)}

def U(x):
  if D[x] != x:
    D[x] = U(D[x])
  return D[x]

for _ in range(m):
  x, y = I()
  D[U(x)] = U(y)

print(sum(U(i)==U(p) for i, p in enumerate(P,1)))
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#define INF (1e9 + 7)
#define distance(x1, y1, x2, y2) sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;
int main(){
    
    ll A;
    double B;
    cin >> A >> B;
    ll ans = A * B;
    cout << ans << endl;

    return 0;
}

### FIXED CODE ###

from decimal import Decimal
in_ = list(input().split())
A = int(in_[0])
B = Decimal(in_[1])
ans = Decimal(A * B)
print(int(ans))
N=str(input())
if "7" in N:
  print("Yes")
else:
  print("No)


### FIXED CODE ###

N=str(input())
if "7" in N:
  print("Yes")
else:
  print("No")
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n


### FIXED CODE ###

X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n
N = input()
V = list(map(int,input(),split()))
C = list(map(int,input(),split()))
for i in range(N+1):
  val= []
  a = V[i] - C[i]
  val.append(a)
val_int = [b for b in val if b > 0]
print(sum(val_int))

### FIXED CODE ###

n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if v[i] > c[i]:
    ans += (v[i]-c[i])
  else:
    continue
print(ans)
a,b,c=map(int,input().split())
if a-b = b-c:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

a,b,c=map(int,input().split())
if a-b == b-c:
  print("YES")
else:
  print("NO")
N,M=map(int,input().split())
c = [map(int,input().split()) for i in range(M)]
result = [0]*N

for a,b in c:
    result[a-1] += 1
    result[b-1] += 1

for i in result:
    print(i)

### FIXED CODE ###

A,B,C = map(int,input().split())
if A<=C<=B:
    print('Yes')
else:
    print('No')
a, b = map(int, input().split())
c = a % 2
d = b % 2
if c + d = 2:
  print(Odd)
  else:
    print(Even)
 

### FIXED CODE ###

a, b = map(int, input().split())
c = a % 2
d = b % 2
if c + d == 2:
  print('Odd')
else:
  print('Even')
H, W, D = list(map(int, input().split()))

A = [[0 for i in range(W)] for j in range(H)]
dic = {}
for i in range(H):
    for j,v in enumerate(list(map(int, input().split()))):
        A[i][j] = v
        dic[v] = (i,j)

Q = int(input())

Qs = []
mi = 10000000
ma = 1
for i in range(Q):
    l,r = list(map(int, input().split()))
    Qs.append((l,r))
    mi = min(mi, l)
    ma = max(ma, r)

S = [0 for i in range(100000)]
acm = 0
pi, pj = dic[mi]
for i in range(mi, ma+D, D):
    x,y = dic[i]
    acm += abs(x-pi) + abs(y-pj)
    S[i] = acm
    pi,pj = x,y

for i in Qs:
    l,r = i
    print(S[r] - S[l])


### FIXED CODE ###

H, W, D = list(map(int, input().split()))
 
dic = {}
for i in range(H):
    for j,v in enumerate(list(map(int, input().split()))):
        dic[v] = (i,j)
 
Q = int(input())
 
Qs = []
mi = 100000
ma = 1
for i in range(Q):
    l,r = list(map(int, input().split()))
    Qs.append((l,r))
    mi = min(mi, l)
    ma = max(ma, r)
 
S = [0 for i in range(100000)]
acm = 0
pi, pj = dic[mi]
for start in range(1, D+1):
    for i in range(start, ma+1, D):
        x,y = dic[i]
        acm += abs(x-pi) + abs(y-pj)
        S[i] = acm
        pi,pj = x,y

for i in Qs:
    l,r = i
    print(S[r] - S[l])
a,b = map(int, input())
if a==1:
  print('Alice')
if b==1:
  print('Bob')
if a==b:
  print("Draw")
if a>b:
  print("Alice")
else:
  print("Bob")

### FIXED CODE ###

A,B = map(int, input().split())
if A==1:
  A=14
if B==1:
  B=14

if A>B:
  print('Alice')
elif B>A:
  print('Bob')
else:
  print('Draw')
# C - Typical Stairs

MOD = 1000000007
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
dp = [None] * (N + 1)

def f(i):
    if dp[i] != None:
        return dp[i]
    else:
        if i in A:
            dp[i] = 0
        elif i < 2:
            dp[i] = 1
        else:
            dp[i] = f(i - 1) + f(i - 2)
        return dp[i] % MOD

print(f(N))


### FIXED CODE ###

# C - Typical Stairs

MOD = (10 ** 9) + 7
N, M = map(int, input().split())
A = [False] * (N + 1)
for _ in range(M):
    A[int(input())] = True
dp = [0] * (N + 1)
dp[0] = 1
if A[1] == False:
    dp[1] = 1

for i in range(2, N + 1):
    if A[i] == True:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

print(dp[N])
A,B,T = map(int,intput().split())

print(T//A*B)

### FIXED CODE ###

A,B,T = map(int,input().split())

print(T//A*B)
a,b,c = map(int,input().split("/"))
print("2018/"+b+"/"+c)

### FIXED CODE ###

s = input()
s = s.replace("2017","2018")
print(s)
a,b,c=input().split
print("YES") if a[-1]==b[0] and b[-1]==c[0] else print("NO")

### FIXED CODE ###

a,b,c=input().split()
print("YES") if a[-1]==b[0] and b[-1]==c[0] else print("NO")