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

from collections import defaultdict
n,k = map(int,input().split())
mod = 924844033
rng = 2010
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
if (n-k)*2 <= n:
  x = (n-k)*2
  ans = 0
  for i in range(x+1):
    if i%2 == 0:
      ans += cmb(x,i)*fctr[n-i]
    else:
      ans -= cmb(x,i)*fctr[n-i]
    ans %= mod
  print(ans)
  exit()
dc = defaultdict(int)
for j in range(1,k+1):
  a = j
  b = k+j
  cnt = 0
  while a<=n and b<=n:
    if a>b:
      b += 2*k
    else:
      a += 2*k
    cnt += 1
  dc[cnt] += 2
cp = set()
cpp = 1
for i,x in dc.items():
  for j in range(x):
    cpp += i
    cp.add(cpp)
cp.add(1)
nn = (n-k)*2
dp = [[0 for j in range(n+1)] for i in range(nn+1)]
dp[0][0] = 1
for i in range(nn+1):
  dp[i][0] = 1
  if i not in cp:
    for j in range(1,min(i,n)+1):
      dp[i][j] = dp[i-1][j]+dp[i-2][j-1]
  else:
    for j in range(1,min(i,n)+1):
      dp[i][j] = dp[i-1][j]+dp[i-1][j-1]
    dp[i][j] %= mod
ans = 0
for i in range(n+1):
  if i%2 == 0:
    ans += fctr[n-i]*dp[nn][i]
  else:
    ans -= fctr[n-i]*dp[nn][i]
  ans %= mod
print(ans)

### FIXED CODE ###

from collections import defaultdict
n,k = map(int,input().split())
mod = 924844033
rng = 2010
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
if (n-k)*2 <= n:
  x = (n-k)*2
  ans = 0
  for i in range(x+1):
    if i%2 == 0:
      ans += cmb(x,i)*fctr[n-i]
    else:
      ans -= cmb(x,i)*fctr[n-i]
    ans %= mod
  print(ans)
  exit()
dc = defaultdict(int)
for j in range(1,k+1):
  a = j
  b = k+j
  cnt = 0
  while a<=n and b<=n:
    if a>b:
      b += 2*k
    else:
      a += 2*k
    cnt += 1
  dc[cnt] += 2
nn = (n-k)*2
cp = set()
cpp = 1
for i,x in dc.items():
  for j in range(x):
    cpp += i
    cp.add(cpp)
cp.add(1)
dp = [[0 for j in range(n+1)] for i in range(nn+1)]
dp[0][0] = 1
for i in range(1,nn+1):
  dp[i] = dp[i-1][:]
  if i not in cp:
    for j in range(1,min(i,n)+1):
      dp[i][j] += dp[i-2][j-1]
      dp[i][j] %= mod
  else:
    for j in range(1,min(i,n)+1):
      dp[i][j] += dp[i-1][j-1]
      dp[i][j] %= mod
ans = 0
for i in range(n+1):
  if i%2 == 0:
    ans += fctr[n-i]*dp[nn][i]
  else:
    ans -= fctr[n-i]*dp[nn][i]
  ans %= mod
print(ans)
### BUGGY CODE ###

import math
a,b,n = map(int, input().split())

ans = 0
lenge = min(b-1, n)
for x in range(lenge+1):
    y = int((a*x)/b) - a * int(x/b)
    ans = max(y, ans)

print(ans)

### FIXED CODE ###

a,b,n=map(int,input().split())
x=min(b-1,n)
print((a*x)//b-a*(x//b))
### BUGGY CODE ###

N = int(input())
S = input()

for l in range(N//2, 0, -1):
    for i in range(N):
        if 2*l+i > N:
            break
        part = S[i:l+i]
        for j in range(l+i, N-l+1):
            cmp = S[j:j+l]
            if cmp == part:
                print(l)
                import sys
                sys.exit()
else:
    print(0)

### FIXED CODE ###

N = int(input())
WholeS = input()

ans = 0
for l in range(N):
    # Z-algorithm
    A = [-1]*(N-l)
    c = 0
    S = WholeS[l:]
    for i, s in enumerate(S):
        if i == 0:
            continue
        if c+A[c] > i+A[i-c]:
            A[i] = A[i-c]
        else:
            j = max(0, A[c]-i+c)
            while i+j < N-l and S[j] == S[i+j]:
                j += 1
            A[i] = j
            c = i
        ans = max(ans, A[i] if(i>A[i]) else i)

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

import itertools

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

ans = [0] * N
comb = list(itertools.combinations(range(1,N+1),2))


for i in range(len(comb)):
    if comb[i][0] <= X and comb[i][1] >= Y:
        k = comb[i][1] - Y + X - comb[i][0]  + 1
        ans[k] += 1
    elif comb[i][0] <= X:
        k = X - comb[i][0] + min(comb[i][1] - X, Y - comb[i][1]+1)
        ans[k] += 1
    elif comb[i][1] >= Y:
        k = comb[i][1] - Y + min(Y - comb[i][0], comb[i][0] - X + 1)
        ans[k] += 1
    else:
        k = min(comb[i][1] - comb[i][0], comb[i][0] - X + Y - comb[i][1] + 1)
        ans[k] += 1
for i in range(1,N):
    print(ans[i])

### FIXED CODE ###

import itertools

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

ans = [0] * N
comb = list(itertools.combinations(range(1,N+1),2))


for i in range(len(comb)):
    if comb[i][0] <= X and comb[i][1] >= Y:
        k = comb[i][1] - Y + X - comb[i][0]  + 1
        ans[k] += 1
    elif comb[i][0] <= X:
        k = X - comb[i][0] + min(comb[i][1] - X, Y - comb[i][1]+1)
        ans[k] += 1
    elif comb[i][1] >= Y:
        k = comb[i][1] - Y + min(Y - comb[i][0], comb[i][0] - X + 1)
        ans[k] += 1
    else:
        k = min(comb[i][1] - comb[i][0], comb[i][0] - X + Y - comb[i][1] + 1)
        ans[k] += 1
for i in range(1,N):
    print(ans[i])
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt_list = []
cnt_dict = {}
for i in a:
    if i in cnt_dict:
        cnt_dict[i] += 1
    else:
        cnt_dict[i] = 1
cnt_dict_sorted = sorted(cnt_dict.items(), key=lambda x: x[1])
for i in set(a):
    cnt_list.append(a.count(i))
ans = 0
if len(cnt_dict_sorted) <= k:
    ans = 0
else:
    tmp = len(cnt_dict_sorted) - k
    for j in range(tmp):
        ans += cnt_dict_sorted[j][1]
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt_dict = {}
for i in a:
    if i in cnt_dict:
        cnt_dict[i] += 1
    else:
        cnt_dict[i] = 1
cnt_dict_sorted = sorted(cnt_dict.items(), key=lambda x: x[1])
ans = 0
if len(cnt_dict_sorted) <= k:
    ans = 0
else:
    tmp = len(cnt_dict_sorted) - k
    for j in range(tmp):
        ans += cnt_dict_sorted[j][1]
print(ans)
### BUGGY CODE ###

n, m = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y=[int(i) for i in input().split()]
    l.append(x)
    r.append(y)
ans = 0
'''
for i in range(n):
    cnt = 0
    for j in range(m):

        for k in range(l[j], r[j]+1):
            if i + 1 == k:
                cnt += 1
        if cnt == m:
            ans += 1
print(ans)
'''
for i in range(n):
    cnt = 0
    #print('cnt rrr')
    #print('i=' + str(i))
    for j in range(m):
        #print(l[j], end=' ')
        #print(r[j])
        if i + 1 >= l[j] and r[j] >= i + 1:
            cnt += 1
            #print('cnt='+ str(cnt))
        else:
            #print('break')
            break
    if cnt == m:
        ans += 1
print(ans)


### FIXED CODE ###

n, m = list(map(int, input().split()))
maxl = 0
minr = 1000000
for i in range(m):
    l, r = list(map(int, input().split()))
    maxl = max(maxl, l)
    minr = min(minr, r)
if minr < maxl:
    print(0)
else:
    print(minr - maxl + 1)
### BUGGY CODE ###

#editorial参照
#そもそもの漸化式
#2次元累積和
#dp累積和のdpを含む漸化式 & dp消せる
n,m = map(int, input().split( ))

s = list(map(int, input().split( )))
t = list(map(int, input().split( )))

mod = 10**9 + 7

dp_sum = [[0]*(m+1) for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] + 1
            dp_sum[i][j] %= mod
        else:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] - dp_sum[i-1][j-1]
            dp_sum[i][j] %= mod
#print(dp_sum)
print(dp_sum[n-1][m-1]+1)#空集合で+1



### FIXED CODE ###

#editorial参照
#そもそもの漸化式
#2次元累積和
#dp累積和のdpを含む漸化式 & dp消せる
n,m = map(int, input().split( ))

s = list(map(int, input().split( )))
t = list(map(int, input().split( )))

mod = 10**9 + 7

dp_sum = [[0]*(m+1) for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] + 1
            dp_sum[i][j] %= mod
        else:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] - dp_sum[i-1][j-1]
            dp_sum[i][j] %= mod
#print(dp_sum)
print(dp_sum[n-1][m-1]+1)#空集合で+1
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
min = float('inf')
for i in range(1,N):
    sunuke = a[:i]
    kuma = a[i:]
    if abs(sum(sunuke) - sum(kuma)) < min:
        min = abs(sum(sunuke) - sum(kuma))
print(min)

### FIXED CODE ###

import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))

a = abs(2*np.cumsum(a) - a.sum())[:-1]

print(min(a))
### BUGGY CODE ###

def move(S, v):
    next = [0 for _ in range(len(S))]
    for i in range(len(S)):
        if S[i] == 'R':
            next[i + 1] += v[i]
        else:
            next[i - 1] += v[i]
    return next
S = input()
V = [1 for _ in range(len(S))]
count = 1

history = {tuple(V):1}
while(True):
    count += 1
    next = move(S, V)
    if tuple(next) in history:
        freq = count - history[tuple(next)]
        res = 1
        if freq > 0:
            for i in range(100):
                res = (res * 10) % freq
            for i in range(res + (count % freq)):
                V = move(S,V)
        print(' '.join([str(i) for i in V]))
        break
    V = next
    history[tuple(V)] = count


### FIXED CODE ###

S = input()
N = len(S)
V = [0 for _ in range(len(S))]
Vi = V[:]
def move(S, v):
    next = [0 for _ in range(len(S))]
    for i in range(len(S)):
        if S[i] == 'R':
            next[i + 1] += v[i]
        else:
            next[i - 1] += v[i]
    return next

nearestL = V[:]
nearestR = V[:]
lastL = N - 1
lastR = 0

for i in range(N - 1, -1, -1):
    if S[i] == 'L':
        lastL = i
    else:
        nearestL[i] = lastL
for i in range(N):
    if S[i] == 'R':
        lastR = i
    else:
        nearestR[i] = lastR

count = 0

maxTurn = 0
for i in range(N):
    if S[i] == 'R':
        dist = abs(i - nearestL[i])
        vec = V if dist % 2 == 0 else Vi
        vec[nearestL[i]] += 1
        maxTurn = max(maxTurn, dist)
    else:
        dist = abs(i - nearestR[i])
        vec = V if dist % 2 == 0 else Vi
        vec[nearestR[i]] += 1
        maxTurn = max(maxTurn, dist)
# print(maxTurn)
# print(' '.join(S))
# print(' '.join([str(i) for i in V]))
# print(' '.join([str(i) for i in Vi]))

Vi = move(S, Vi)
for i in range(N):
    V[i] += Vi[i]

# if (maxTurn % 2 == 1):
#     V = move(S, V)
print(' '.join([str(i) for i in V]))
### BUGGY CODE ###

def resolve():
    s = input()
    s = [c for c in s]
    t = input()
    t = [c for c in t]
    import itertools
    S = list(itertools.permutations(s, len(s)))
    T = list(itertools.permutations(t, len(t)))
    for s in S:
        for t in T:
            if "".join(s) < "".join(t):
                print("Yes")
                return
    print("No")
            

if '__main__' == __name__:
    resolve()

### FIXED CODE ###

def resolve():
    S = sorted(input())
    T = sorted(input(), reverse=True)
    print("Yes" if S < T else "No")
            

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

N=int(input())
S=input()
max=0
A = [0] *len(S)
for f in range(len(S)-1):
    i = f+1
    
    A[0]=len(S)
    while(i<len(S)):
        j=0
        while(i+j<len(S) and S[f+j]==S[i+j] and j<i):
            j+=1
        A[i]=j
        if(j>max):
            max=j
        if(j==0):
            i+=1
            continue
        k=1
        while(k+i<len(S) and k+A[k]<j):
            A[i+k]=A[f+k]
            k+=1
        i+=k
print(max)

### FIXED CODE ###

N=int(input())
S=input()

max = 0
index = 0
for i in range(1,len(S)-1):
    s1=S[index:i]
    s2=S[i:]
    if s1 in s2:
        max=len(s1)
    else:
        index+=1
        
print(max)
### BUGGY CODE ###

import bisect, functools
N = int(input())
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

@functools.lru_cache(maxsize=None)
def b(n):
    return sum(a(x) for x in B[:bisect.bisect_left(B, n)])

def c():
    return sum(b(x) for x in C)

print(c())

### FIXED CODE ###

import bisect, functools, sys
sys.setrecursionlimit(10**6)
N = int(input())
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

b_cache = [0] * (N + 1)
b_cached = [False] * (N + 1)
def b_i(i):
    global b_cache, b_cached
    if i >= 1:
        if not b_cached[i - 1]: b_i(i - 1)
        t = b_cache[i - 1] + a(B[i - 1])
        b_cache[i] = t
        b_cached[i] = True
        return t
    return 0

@functools.lru_cache(maxsize=None)
def b(n):
    return b_i(min(N, bisect.bisect_left(B, n)))

def c():
    return sum(b(x) for x in C)

print(c())
### BUGGY CODE ###

K,S = (int(_) for _ in input().split())

out = 0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x + y + z == S :
                out += 1

print(out)


### FIXED CODE ###

def binary_search_list(beSearched,wanted) :
    l = 0
    r = len(beSearched)

    #print("condition = {}".format(r-l))

    while r - l >= 1 :
        s = (l + r) // 2
        #print("l={} r={} s={}".format(l,r,s))
        if beSearched[s] == wanted :
            return True
        if beSearched[s] > wanted :
            r = s
        else :
            l = s + 1

    return False

K,S = (int(_) for _ in input().split())
num = [_ for _ in range(K+1)]
out = 0
for i in range(K+1):
    for j in range(i+1):
        if 0 <= S - i - j <= j :
            if i == j and j == S - i - j:
                out += 1
            elif i == j or j == S - i - j or S -i - j == i:
                out += 3
            else :
                out += 6
        #print(num[:j+1])
        #b = binary_search_list(num[:j+1],S - i - j)
        #print("b={} i={} j={} k = {}".format(b,i,j, S- i -j))
        #if b :
            #if i == j and j == S - i - j:
                #out += 1
            #elif i == j or j == S - i - j or S -i - j == i:
                #out += 3
            #else :
                #out += 6

print(out)
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split()))
ans = 1
for i in range(1, N):
    if P[i] == min(P[:i+1]):
        ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
Q = [P[0]]
for i in P[1:]:
    if i < Q[-1]:
        Q.append(i)
print(len(Q))
### BUGGY CODE ###

a = input().split()
b = input().split()

ans = 0
be = 0

for i in range(int(a[0])-int(a[1])+1):
    sum = 0
    if be < int(b[i+int(a[1])-1]):
        for j in range(int(a[1])):
            sum += (1 + int(b[i+j]))/2
        if ans < sum:
            ans = sum
    be = int(b[i])

print(ans)

### FIXED CODE ###

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

sum = 0
ans = 0

for i in range(a[0]):
    sum += (1 + b[i])/2
    if i > a[1]-1:
        sum -= (1 + b[i-a[1]])/2
    if ans < sum:
        ans = sum

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

N=int(input())

dp=[-1 for _ in range(N+1)]
def Lu(n):
    if n==0:
        rec=2
    elif n==1:
        rec=1
    elif dp[n]!=-1:
        return dp[n]
    else:
        return Lu(n-1)+Lu(n-2)
    dp[n]=rec
    return rec
print(Lu(N))


### FIXED CODE ###

N=int(input())

dp=[-1 for _ in range(N+1)]
def Lu(n):
    if n==0:
        rec=2
    elif n==1:
        rec=1
    elif dp[n]!=-1:
        return dp[n]
    else:
        rec=Lu(n-1)+Lu(n-2)
    dp[n]=rec
    return rec
print(Lu(N))
### BUGGY CODE ###

from math import prod
N,K = map(int, input().split())
A = list(map(int, input().split()))
M = prod(A[:K])
while True:
    A.pop(0)
    if len(A) == K - 1:
        break
    P = prod(A[:K])
    print('Yes' if P > M else 'No')
    M = P

### FIXED CODE ###

N,K = map(int, input().split())
A = list(map(int, input().split()))
for i in range (K,N):
    print('Yes' if A[i] > A[i-K] else 'No')
### BUGGY CODE ###

n = int(input())
alist = list(map(int,input().split()))
for i in range(1,n+1):
  print(alist.index(i)+1,end = " ")


### FIXED CODE ###

n = int(input())
alist = list(map(int,input().split()))
anslist = [0]*n
for i in range(n):
  anslist[alist[i]-1] = i+1
for i in anslist:
  print(i,end = " ")
### BUGGY CODE ###

import collections
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    l = [a[t] for t in range(n) if t != i]
    x = collections.Counter(l).values()
    count = 0
    for j in x:
        if j < 2:
            pass
        else:

            count += combinations_count(j,2)
    print(count)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [0]*n
for i in range(n):
    b[a[i]-1] += 1
c = sum([(i*(i-1))//2 for i in b])
for i in a:
    print(c-(b[i-1]-1))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans=[]
for i in range(1, n+1):
    ans.append(a.index(i)+1)
print(*ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[a[i]-1]=i+1
print(*ans)
### BUGGY CODE ###

n = int(input())
s = [int(input()) for _ in range(n)]
os = [s[i] for i in range(0,n,2)]
j = sorted(s)
ans = 0
for i in os:
    if j.index(i) % 2 == 1:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = [int(input()) for _ in range(n)]
j = sorted(s)
ans = len(set(s[::2]) ^ set(j[::2])) // 2
print(ans)
### BUGGY CODE ###

import bisect


def main():
    N, M = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    for _ in range(M):
        ins = A.pop() // 2
        A.insert(bisect.bisect_left(A, ins), ins)

    print(sum(A))


if __name__ == '__main__':
    main()

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-n for n in A]
heapq.heapify(A)

for _ in range(M):
    high = -heapq.heappop(A)
    heapq.heappush(A, -(high//2))

print(-sum(A))
### BUGGY CODE ###

x = int(input())

count = 0
for i in range(0, x):
    a =  int(input())
    if a % 2 == 0 and a != 2:
        count += 1
    else:
        c =int((a + 1) / 2)
        for j in range ( 2,  c-1 ):
            if a % j == 0:
                count += 1
                break;
        
print(x-count)
        



### FIXED CODE ###

x = int(input())

count = 0
for i in range(0, x):
    a =  int(input())
    for j in range ( 2,  a ):
        c = int(a)
        if a % j == 0:
            count += 1
            break;
        if j * j  > c:
            break;
        
print(x-count)
### BUGGY CODE ###




def main():
        
    N = int(input())

    S = [input() for _ in range(N)]

    """
    あるA,Bを決めたときに、A+1,B+1と比べると、全ての文字が右下にずれるので、(A,B)と(A+1,B+1)の結果は同じになる
    """

    cnt = 0
    for a in range(N):
        S2 = [["" for _ in range(N)]  for _ in range(N)]
        for i in range(N):
            for j in range(N):
                if 0 <= i + a <= N-1:
                    y = i + a
                else:
                    y = (i + a) - N
                S2[y][j] = S[i][j]
        
        flag = True
        for i in range(N):
            if not flag:
                break
            for j in range(N):
                if i == j:
                    continue
                if S2[i][j] != S2[j][i]:
                    flag = False
                    break
        if flag:
            cnt += 1

    print(cnt * N)


if __name__ == "__main__":
    main()

### FIXED CODE ###




def main():
        
    N = int(input())

    S = [input() for _ in range(N)]

    """
    あるA,Bを決めたときに、A+1,B+1と比べると、全ての文字が右下にずれるので、(A,B)と(A+1,B+1)の結果は同じになる
    """
    S2 = [["" for _ in range(N)]  for _ in range(N)]
    cnt = 0
    for a in range(N):
        
        for i in range(N):
            for j in range(N):
                if 0 <= i + a <= N-1:
                    y = i + a
                else:
                    y = (i + a) - N
                S2[y][j] = S[i][j]
        
        flag = True
        for i in range(N):
            if not flag:
                break
            for j in range(N):
                if i == j:
                    continue
                if S2[i][j] != S2[j][i]:
                    flag = False
                    break
        if flag:
            cnt += 1

    print(cnt * N)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

#C
N = int(input())
P = list(map(int, input().split()))
ans = 0

for i in range(N):
    min_to_i = min(P[:i+1])
    if min_to_i >= P[i]:
        ans += 1
        
print(ans)

### FIXED CODE ###

#C
N = int(input())
P = list(map(int, input().split()))
ans = 0
min_num = 10**6

for i in range(N):
    min_num = min(min_num, P[i])
    if min_num >= P[i]:
        ans += 1
        
print(ans)
### BUGGY CODE ###

H, W, D = map(int, input().split())
A_where = [0] * (H*W+1)
A_where[0] = (-1, -1)
for p in range(H):
    A = list(map(int, input().split()))
    for q in range(W):
        A_where[A[q]] = (p, q)

Q = int(input())

DP = [0] * (H*W+1)
for _ in range(Q):
    ans = 0
    start, end = map(int, input().split())
    while start != end:
        next = start + D
        if DP[start] > 0:
            ans += DP[start]
        else:
            ny, nx = A_where[next]
            y, x = A_where[start]
            an = abs(ny-y) + abs(nx-x)
            DP[start] = an
            ans += an
            start = next
    print(ans)

### FIXED CODE ###

H, W, D = map(int, input().split())
A_where = [0] * (H*W+1)
A_where[0] = (-1, -1)
for p in range(H):
    A = list(map(int, input().split()))
    for q in range(W):
        A_where[A[q]] = (p, q)

Q = int(input())

DP = [0] * (H*W+1)

for i in range(D+1, H*W+1):
    y1, x1 = A_where[i]
    y2, x2 = A_where[i-D]

    DP[i] = DP[i-D] + abs(y1-y2) + abs(x1-x2)

for i in range(Q):
    l, r = map(int, input().split())
    print(DP[r] - DP[l])
### BUGGY CODE ###

S = input()
Q = int(input())
qs = list(input() for _ in range(Q))
rev = 0
for q in qs:
    q = q.split()
    if q[0] == '1':
        """
        print('query 1 ', end="")
        print(q)
        S = S[::-1]
        """
        rev = (rev+1) % 2
    else:
        """
        print('query 2 ', end="")
        print(q)
        """
        if (q[1]=='1' and rev==0) or (q[1]=='2' and rev==1):
            S = q[2] + S
        else:
            S = S + q[2]
print(S if rev == 0 else S[::-1])


### FIXED CODE ###

import sys
from collections import deque
def input(): return sys.stdin.readline().rstrip()
S = deque(input())
rev = False
apdlft = S.appendleft
apd = S.append

for _ in range(int(input())):
    q = input().split()
    if q[0] == '1':
        rev = not(rev)
    else:
        if (q[1]=='1' and rev is False) or (q[1]=='2' and rev is True):
            apdlft(q[2])
        else:
            apd(q[2])

if rev:
    print((''.join(S))[::-1])
else:
    print(''.join(S))
### BUGGY CODE ###

while 1:
	try:
		s,t = raw_input(),raw_input()
		Ls,Lt = len(s),len(t)
		if Ls < Lt:
			s,t,Ls,Lt = t,s,Lt,Ls
		ans = 0
		for d in range(Lt+1):
			L = 0
			for i in range(d):
				if s[i] == t[-d+i]:
					L += 1
				elif L > 0:
					ans = max(ans,L)
					L = 0
			ans = max(ans,L)
		for d in range(Ls):
			L = 0
			for i in range(min(Lt,Ls-d)):
				if s[i+d] == t[i]:
					L += 1
				elif L > 0:
					ans = max(ans,L)
					L = 0
			ans = max(ans,L)
		print ans
	except:
		break

### FIXED CODE ###

while 1:
	try:
		s,t = raw_input(),raw_input()
		if len(s) < len(t): s,t = t,s
		MAXL = sum(min(s.count(i),t.count(i)) for i in set(list(s))&set(list(t)))
		ans = 0
		for sp in range(len(t)):
			if len(t) - sp <= ans:
				break
			for L in range(ans+1,min(MAXL+1,len(t)-sp+1)):
				if t[sp:sp+L] in s:
					ans = L
				else:
					break
		print ans
	except:
		break