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

a,b,k = map(int,input().split(" "))
r = list(map(int,input().split(" ")))
l = list(map(int,input().split(" ")))
ar = [0]
br = [0]
for i in range(a):
    if ar[-1] + r[i] <= k:
        ar.append(ar[-1] + r[i])
    else:
        break 
for i in range(b):
    if br[-1] + l[i] <= k:
        br.append(br[-1] + l[i])
    else:
        break 
ans = 0
for i in range(len(ar)):
    for j in range(len(br)):
        if ar[i] + br[j] <= k:
            t = i + j
        ans = max(ans,t)
print(ans)

### FIXED CODE ###

a,b,k = map(int,input().split(" "))
r = list(map(int,input().split(" ")))
l = list(map(int,input().split(" ")))
ar = [0]
br = [0]
for i in range(a):
    ar.append(ar[-1] + r[i])
for i in range(b):
    br.append(br[-1] + l[i])
ans = 0
j = b
for i in range(len(ar)):
    if ar[i] > k:
        break
    while True:
        if ar[i] + br[j] <= k:
            t = i + j
            break
        j -= 1
    ans = max(ans,t)
print(ans)
### BUGGY CODE ###

n = int(input())
s_list = []
n_list = []
ana = 0
for i in range(n):
    s = sorted(input())
    #print(s)
    if len(s_list) > 0:
        for num, s_i in enumerate(s_list):
            is_exist = False
            if s_i == s:
                n_list[num] += 1
                ana += n_list[num]
                is_exist = True
                break
        if not is_exist:
            s_list.append(s)
            n_list.append(0)
    else:
        s_list.append(s)
        n_list.append(0)



print(int(ana))

### FIXED CODE ###

n = int(input())
s_dict = {}
ana = 0
for i in range(n):
    s = "".join(sorted(input()))
    #print(s)
    if s in s_dict:
        ana += s_dict[s]
        s_dict[s] += 1
    else:
        s_dict[s] = 1
        
print(ana)
### BUGGY CODE ###

def d_wizard_in_maze():
    from collections import deque
    H, W = [int(i) for i in input().split()]
    Start_row, Start_col = [int(i) - 1 for i in input().split()]
    Goal_row, Goal_col = [int(i) - 1 for i in input().split()]
    Grid = [input() for _ in range(H)]

    neighbor = ((-1, 0), (1, 0), (0, -1), (0, 1))  # 上下左右
    warp = tuple((i, j) for i in range(-2, 3) for j in range(-2, 3))  # ワープで移動できる範囲

    def is_inside(row, col):
        return 0 <= row < H and 0 <= col < W

    # dist[r][c]: スタートから (r, c) に到達するために必要なワープ回数の最小値
    dist = [[float('inf')] * W for _ in range(H)]
    queue = deque([(Start_row, Start_col, 0)])
    while queue:
        row, col, time = queue.pop()
        dist[row][col] = time
        for dr, dc in neighbor:
            nr, nc = row + dr, col + dc
            if is_inside(nr, nc) and Grid[nr][nc] == '.' and time < dist[nr][nc]:
                queue.append((nr, nc, time))
        for dr, dc in warp:
            nr, nc = row + dr, col + dc
            if is_inside(nr, nc) and Grid[nr][nc] == '.' and time < dist[nr][nc]:
                queue.append((nr, nc, time + 1))
    return -1 if dist[Goal_row][Goal_col] == float('inf') else dist[Goal_row][Goal_col]

print(d_wizard_in_maze())

### FIXED CODE ###

def d_wizard_in_maze():
    from collections import deque
    H, W = [int(i) for i in input().split()]
    Start_row, Start_col = [int(i) - 1 for i in input().split()]
    Goal_row, Goal_col = [int(i) - 1 for i in input().split()]
    Grid = [input() for _ in range(H)]

    warp_count = [[-1] * W for i in range(H)]
    neighbor_4 = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    neighbor_25 = [(i, j) for i in range(-2, 3) for j in range(-2, 3)]
    queue = deque([(Start_row, Start_col, 0)])  # コスト 0 の移動は左詰めする

    while(queue):
        row, col, count = queue.popleft()
        if warp_count[row][col] != -1:
            continue
        warp_count[row][col] = count

        for dr, dc in neighbor_4:
            nr, nc = row + dr, col + dc
            if 0 <= nr < H and 0 <= nc < W and Grid[nr][nc] == '.':
                if warp_count[nr][nc] == -1:
                    queue.appendleft((nr, nc, count))

        for dr, dc in neighbor_25:
            nr, nc = row + dr, col + dc
            if 0 <= nr < H and 0 <= nc < W and Grid[nr][nc] == '.':
                queue.append((nr, nc, count + 1))

    return warp_count[Goal_row][Goal_col]

print(d_wizard_in_maze())
### BUGGY CODE ###

import heapq
def dijkstra_heap(N,S,edge):
  d = [[float('inf')]*(N*100+1) for _ in range(N)] #始点0から各頂点への最短距離
  used = [[False]*(N*100+1) for _ in range(N)]
  d[0][S] = 0
  used[0][S] = True
  edgelist = []
  #edgelist : [(0,S)からの暫定(未確定)最短時間,頂点,銀貨の枚数]のリスト
  #edge[s] : sから出る枝の[重み,頂点,銀貨の枚数]のリスト
  for w,v,sil in edge[0]:
    if S+sil>=0 and S+sil<=N*100:
      heapq.heappush(edgelist,[w,v,S+sil]) #sの隣の点は枝の重さがそのまま暫定最短距離となる
  while len(edgelist):
    #まだ使われてない頂点の中から最小の距離のものを探す→確定させる
    min_w,min_v,min_sil = heapq.heappop(edgelist)
    #min_w,min_v,min_sil : [0からの(確定)最短距離,頂点,銀貨の枚数]
    if used[min_v][min_sil]:
      continue
    d[min_v][min_sil] = min_w
    used[min_v][min_sil] = True
    for w,v,sil in edge[min_v]:
      if min_sil+sil>=0 and min_sil+sil<=N*100 and not used[v][min_sil+sil]:
        heapq.heappush(edgelist,[min_w+w,v,min_sil+sil])
  return d

def solve():
  N, M, S = map(int, input().split())
  edge = [[] for _ in range(N)]
  amax = 0
  for i in range(M):
    u,v,a,b = map(int, input().split())
    amax = max(amax,a)
    edge[u-1].append([b,v-1,-a])
    edge[v-1].append([b,u-1,-a])
  S = min(S,(N-1)*amax)
  for i in range(N):
    c,d = map(int, input().split())
    edge[i].append([d,i,c])
  D = dijkstra_heap(N,S,edge)
  ans = [0]*N
  for i in range(1,N):
    ans[i] = min(D[i])
  return ans[1:]
print(*solve(),sep='\n')

### FIXED CODE ###

import heapq
def dijkstra_heap(N,S,Smax,edge):
  d = [float('inf')]*(10**4*N) #始点0から各頂点への最短距離
  used = [False]*(10**4*N)
  d[S] = 0
  used[S] = True
  edgelist = []
  #edgelist : [(0,S)からの暫定(未確定)最短時間,頂点,銀貨の枚数]のリスト
  #edge[s] : sから出る枝の[重み,頂点,銀貨の枚数]のリスト
  for w,a in edge[0]:
    v,sil = a//10**4,a%10**4
    if v==0 and S+sil<=Smax:
      heapq.heappush(edgelist,[w,a+S]) #sの隣の点は枝の重さがそのまま暫定最短距離となる
    elif v>0 and S-sil>=0:
      heapq.heappush(edgelist,[w,v*10**4+(S-sil)]) #sの隣の点は枝の重さがそのまま暫定最短距離となる
  while len(edgelist):
    #まだ使われてない頂点の中から最小の距離のものを探す→確定させる
    min_w,min_a = heapq.heappop(edgelist)
    min_v,min_sil = min_a//10**4,min_a%10**4
    #min_w,min_v,min_sil : [0からの(確定)最短距離,頂点,銀貨の枚数]
    if used[min_a]:
      continue
    d[min_a] = min_w
    used[min_a] = True
    for w,a in edge[min_v]:
      v,sil = a//10**4,a%10**4
      if v==min_v and min_sil+sil<=Smax and not used[a+min_sil]:
        heapq.heappush(edgelist,[min_w+w,a+min_sil])
      elif v!=min_v and min_sil-sil>=0 and not used[v*10**4+(min_sil-sil)]:
        heapq.heappush(edgelist,[min_w+w,v*10**4+(min_sil-sil)])
  return d

def solve():
  N, M, S = map(int, input().split())
  edge = [[] for _ in range(N)]
  amax = 0
  for i in range(M):
    u,v,a,b = map(int, input().split())
    amax = max(amax,a)
    edge[u-1].append([b,(v-1)*10**4+a])
    edge[v-1].append([b,(u-1)*10**4+a])
  Smax = (N-1)*amax
  S = min(S,Smax)
  for i in range(N):
    c,d = map(int, input().split())
    edge[i].append([d,i*10**4+c])
  D = dijkstra_heap(N,S,Smax,edge)
  ans = [0]*N
  for i in range(1,N):
    ans[i] = min(D[i*10**4:(i+1)*10**4])
  return ans[1:]
print(*solve(),sep='\n')
### BUGGY CODE ###

import itertools
import functools
import math
from collections import Counter
from itertools import combinations


S=list(input())
Q=int(input())

rflg = 0
for i in range(Q):
    Que = input()
    if Que == '1':
        if rflg == 0:
            rflg = 1
        else:
            rflg = 0
        #S= list(reversed(S))
    else:
        T,F,C=map(str,Que.split())
        if F == '1' and rflg == 0 or (F != '1' and rflg == 1):
            S=list(C)+S
        else:
            S.append(C)

if rflg == 1:
    S = list(reversed(S))
print("".join(S))


### FIXED CODE ###

import itertools
import functools
import math
from collections import Counter
from itertools import combinations

def CHK():
    S=list(input())
    Q=int(input())
    H=""
    B=""
    rflg = 0
    for i in range(Q):
        Que = input()
        if Que == '1':
            if rflg == 0:
                rflg = 1
            else:
                rflg = 0
            #S= list(reversed(S))
        else:
            T,F,C=map(str,Que.split())
            if F == '1' and rflg == 0 or (F != '1' and rflg == 1):
                #S=list(C)+S
                H = C + H
            else:
                #S.append(C)
                B = B + C

    S = list(H) + S + list(B)
    if rflg == 1:
        S = list(reversed(S))
    print("".join(S))

CHK()
### BUGGY CODE ###

s=input()
t=input()
ns,nt,nd=len(s),len(t),len(s)-len(t)
ans="z"*ns
flag=0
for i in range(2**nt):
  K=str(bin(i))[2:].zfill(nt)
  T=""
  for j in range(nt):
    if K[j]=="0":
      T+="?"
    else:
      T+=t[j]
  for k in range(nd+1):
    if s[k:].startswith(T):
      Key=s[:k]+t+s[k+nt:]
      ans=min(ans,Key.replace("?","a"))
      flag=1
print(ans if flag==1 else "UNRESTORABLE")

### FIXED CODE ###

s=input()
t=input()
ns,nt,nd=len(s),len(t),len(s)-len(t)
ans="z"*ns
flag=0
for i in range(nd+1):
  judge=True
  for j in range(nt):
    ss=s[i+j]
    tt=t[j]
    if ss!="?" and ss!=tt:
      judge=False
  if judge:
    Key=s[:i]+t+s[i+nt:]
    ans=min(ans,Key.replace("?","a"))
    flag=1
print(ans if flag==1 else "UNRESTORABLE")
### BUGGY CODE ###

n=int(input())
l=sorted(map(int,input().split()))
ans=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[k]<l[i]+l[j]:
        ans+=1
      else:
        break
print(ans)

### FIXED CODE ###

import bisect
n=int(input())
l=sorted(map(int,input().split()))
print(sum(bisect.bisect_left(l,l[i]+l[j])-j-1for i in range(n)for j in range(i+1,n)))
### BUGGY CODE ###

N = int(raw_input())
T = []
A = []
for _ in xrange(N):
    t, a = map(int, raw_input().split())
    T.append(t)
    A.append(a)

ans = T[0] + A[0]
tmpT = T[0]
tmpA = A[0]
for i in xrange(1, N):
    if T[i] >= T[i-1] and A[i] >= A[i-1] and T[i] + A[i] >= ans:
        ans = T[i] + A[i]
        tmpT = T[i]
        tmpA = A[i]
    else:
        add = T[i] + A[i]
        j = ans / add + 1
        while True:
            tmpAns = add * j
            tt = T[i] * j
            aa = A[i] * j
            if tt >= tmpT and aa >= tmpA:
                ans = tmpAns
                tmpT =tt
                tmpA = aa
                break
            j += 1
print ans

### FIXED CODE ###

N = int(input())
T = []
A = []
for _ in range(N):
    Ti, Ai = map(int, input().split())
    T.append(Ti)
    A.append(Ai)

tmp_t = T[0]
tmp_a = A[0]
ans = tmp_t + tmp_a
for i in range(1, N):
    n_t = tmp_t // T[i] if tmp_t % T[i] == 0 else tmp_t // T[i] + 1
    n_a = tmp_a // A[i] if tmp_a % A[i] == 0 else tmp_a // A[i] + 1
    n = max(n_t, n_a)
    tmp_t = T[i] * n
    tmp_a = A[i] * n
    ans = tmp_t + tmp_a

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

import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


class BIT:
	def __init__(self, n):
		self.n = n
		self.data = [0]*(n+1)
		self.el = [0]*(n+1)
	def sum(self, i):
		s = 0
		while i > 0:
			s += self.data[i]
			i -= i & -i
		return s
	def add(self, i, x):
		# assert i > 0
		self.el[i] += x
		while i <= self.n:
			self.data[i] += x
			i += i & -i
	def get(self, i, j=None):
		if j is None:
			return self.el[i]
		return self.sum(j) - self.sum(i)


def main():
	n,q=MI()
	C=[0]+LI()

	lr=[]

	for i in range(q):
		l,r=MI()
		lr.append([l,r,i])
	lr.sort(key=lambda x:x[1])
	#print(lr)
	R=[-1]*(n+1)

	B=BIT(n)
	now=1
	ans=[-1]*(q)
	for l,r,i in lr:
		while now<=r:
			if R[C[now]]!=-1:
				B.add(R[C[now]],-1)
			R[C[now]]=now
			B.add(R[C[now]],1)
			now+=1
		#print(R)
		#print(B.el)
		ans[i]=B.get(l-1,r)
	print(*ans,sep="\n")



if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


class BIT:
	def __init__(self, n):
		self.n = n
		self.data = [0]*(n+1)
		self.el = [0]*(n+1)
	def sum(self, i):
		s = 0
		while i > 0:
			s += self.data[i]
			i -= i & -i
		return s
	def add(self, i, x):
		# assert i > 0
		self.el[i] += x
		while i <= self.n:
			self.data[i] += x
			i += i & -i
	def get(self, i, j=None):
		if j is None:
			return self.el[i]
		return self.sum(j) - self.sum(i)


def main():
	n,q=MI()
	C=[0]+LI()

	lr=[]

	for i in range(q):
		l,r=MI()
		lr.append([l,r,i])
	lr.sort(key=lambda x:x[1])
	#print(lr)
	R=[-1]*(n+1)

	B=BIT(n)
	now=1
	ans=[-1]*(q)
	for l,r,i in lr:
		while now<=r:
			if R[C[now]]!=-1:
				B.add(R[C[now]],-1)
			R[C[now]]=now
			B.add(R[C[now]],1)
			now+=1
		#print(R)
		#print(B.el)
		ans[i]=B.get(l-1,r)
	print(*ans,sep="\n")



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

# -*- coding: utf-8 -*-


def can_div2(a):
    for i in range(len(a)):
        if a[i] % 2 == 0:
            a[i] /= 2
            return True
    else:
        return False

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

c = 0

while(can_div2(a)):
   c += 1 

print(c)

### FIXED CODE ###

# -*- coding: utf-8 -*-

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

c = 0
for i in range(N):
    while a[i] % 2 == 0:
        a[i] /= 2
        c += 1

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

S = input()
word = 'hi'
if word in S:
    while 1:
        if word == S:
            print('Yes')
            break
        else:
            word += 'hi'
else:
    print('No')

### FIXED CODE ###

import re
S = input()
if re.match(r'^(hi)+$',S):
    print('Yes')
else:
    print('No')
### BUGGY CODE ###


def resolve():
    def counts(x):
        tot = 0
        for i in range(N):
            if A[i] < 0:
                l, r = -1, N
                while r-l > 1:
                    c = (l+r)//2
                    if A[c]*A[i] < x:
                        r = c
                    else:
                        l = c
                tot += N - r
            else:
                l, r = -1, N
                while r-l > 1:
                    c = (l + r) // 2
                    if A[c] * A[i] < x:
                        l = c
                    else:
                        r = c
                tot += r
            if A[i] * A[i] < x:
                tot -= 1
        tot //= 2
        return tot < K


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

    l = -(10**18)
    r = 10**18
    while r-l > 1:
        x = (l + r) // 2
        if counts(x):
            l = x
        else:
            r = x
    print(l)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###


import numpy as np
def resolve():
    n, k = map(int, input().split())
    a = np.array(input().split(), dtype=np.int64)
    a.sort()

    zero = np.count_nonzero(a == 0)
    positive = a[a > 0]
    negative = a[a < 0]

    def count(x):  # 積が x 以下のペアは何個あるか？
        ans = 0
        if x >= 0:  # 片側が 0 の場合
            ans += n * zero
        ans += np.searchsorted(a, x // positive, side="right").sum()  # 片側が正の場合
        ans += n * len(negative) - np.searchsorted(a, -(-x // negative), side="left").sum()  # 片側が負の場合 切り上げは -(-a//b)
        ans -= np.count_nonzero(a * a <= x)  # 同じもの2つは選べない
        return ans // 2

    ok = 10 ** 18
    ng = -ok - 1
    while ok - ng > 1:  # 二分探索
        cen = (ok + ng) // 2
        if count(cen) >= k:
            ok = cen
        else:
            ng = cen
    print(ok)

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

import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline

N, M = map(int, rl().split())
li = [[] for _ in range(N)]
deg = [0] * N
for _ in range(M):
    a, b = map(int, rl().split())
    a -= 1
    b -= 1
    li[a].append(b)
    deg[b] = 1
deg = collections.deque([i for i in range(N) if deg[i] == 0])
dp = [0] * N
while deg:
    i = deg.popleft()
    for j in li[i]:
        if dp[j] < dp[i] + 1:
            dp[j] = dp[i] + 1
        deg.appendleft(j)
print(max(dp))





        




### FIXED CODE ###

import sys
import math
import itertools
import collections
import numpy as np

rl = sys.stdin.readline

def a():
    N, M = map(int, rl().split())
    li = [[] for _ in range(N)]
    deg = [0] * N
    for _ in range(M):
        a, b = map(int, rl().split())
        a -= 1
        b -= 1
        li[a].append(b)
        deg[b] += 1
    d = collections.deque([i for i in range(N) if deg[i] == 0])
    dp = [0] * N
    while d:
        i = d.popleft()
        for j in li[i]:
            deg[j] -= 1
            if deg[j] == 0:
                dp[j] = max(dp[j] ,dp[i] + 1)
                d.append(j)
    print(max(dp))
a()
### BUGGY CODE ###

#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,Q = II()
a = [0]*(N-1)
b = [0]*(N-1)
p = [0]*Q
x = [0]*Q

for i in range(N-1):
    a1,b1 = II()
    a[i] = a1-1
    b[i] = b1-1

for i in range(Q):
    p1,x1 = II()
    p[i] = p1-1
    x[i] = x1


#深さ優先探索
def dfs(pt,v):
    n=len(pt)
    d=[-1]*n
    check_visited = [False]*n
    check_visited[v] = True
    S = [v]
    d[v] = 0
    while S:
        v1 = S.pop()
        for i in pt[v1]:
            if check_visited[i] == False:
                check_visited[i] = True
                d[i] = d[v1] + 1
                S.append(i)
    return d


pt = [[] for _ in range(N)]
for i in range(N-1):
    pt[a[i]].append(b[i])
    pt[b[i]].append(a[i])
d = dfs(pt,0)

parent = defaultdict(list)
for i in range(N-1):
    if d[a[i]]>d[b[i]]:
        parent[a[i]].append(b[i])
    else:
        parent[b[i]].append(a[i])

val = [0]*N
for i in range(Q):
    val[p[i]] += x[i]

for i in range(N):
    now = i
    ans = 0
    while now != 0:
        ans += val[now]
        now = parent[now][0]
    print(val[0]+ans)

### FIXED CODE ###

#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,Q = II()
a = [0]*(N-1)
b = [0]*(N-1)
p = [0]*Q
x = [0]*Q

for i in range(N-1):
    a1,b1 = II()
    a[i] = a1-1
    b[i] = b1-1

for i in range(Q):
    p1,x1 = II()
    p[i] = p1-1
    x[i] = x1


parent = defaultdict(list)
for i in range(N-1):
    parent[b[i]].append(a[i])

val = [0]*N
for i in range(Q):
    val[p[i]] += x[i]

for i in range(1,N):
    val[i] += val[parent[i][0]]

print(*val)
### BUGGY CODE ###

import sys
INFTY = 1<<30
a = [None] * 2000001
h = 0
ret = []

def maxHeapify(i):
    global a, h
    l = 2 * i
    r = 2 * i + 1
    if l <= h and a[l] > a[i]:
        largest = l
    else:
        largest = i
    if r <= h and a[r] > a[largest]:
        largest = r
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        maxHeapify(largest)

def extract():
    global a, h
    if h < 1:
        return -INFTY
    maxv = a[1]
    a[1] = a[h]
    h -= 1
    maxHeapify(1)
    return maxv
    
def increaseKey(i, k):
    global a
    if k < a[i]:
        return
    a[i] = k
    while i > 1 and a[i//2] < a[i]:
        a[i], a[i//2] = a[i//2], a[i]
        i = i // 2

def insert(k):
    global a, h
    h += 1
    a[h] = -INFTY
    increaseKey(h, k)

i = 0
for com in sys.stdin.readlines():
    if com[0] == "i":
        insert(int(com[7:]))
    elif com[1] == "x":
        ret.append(extract())
    else:
        sys.stdout.writelines("\n".join([str(s) for s in ret]))
        print()

### FIXED CODE ###

import heapq
import sys

h = []

for com in sys.stdin.readlines():
    if com[0] == "i":
        heapq.heappush(h, -int(com[7:]))
    elif com[1] == "x":
        print(-heapq.heappop(h))
### BUGGY CODE ###

h,w,d = map(int, input().split())

a = [[0 for _ in range(w)] for _ in range(h)]
masu = {}
for i in range(h):
    a[i] = list(map(int, input().split()))
    for j in range(w):
        masu[a[i][j]] = (i,j)

point = [0] * (h*w)
for i in range(1,h*w-d+1):
    point[i] = abs(masu[i][0] - masu[i+d][0]) + abs(masu[i][1] - masu[i+d][1])


q = int(input())
ans = [0] * q
for i in range(q):
    l, r = map(int, input().split())
    if l == r:
        ans[i] = 0
    else:
        ans[i] = sum(point[l:r:d])
 
for i in range(q):
    print(ans[i])


### FIXED CODE ###

h,w,d = map(int, input().split())

a = [[0 for _ in range(w)] for _ in range(h)]
masu = {}
for i in range(h):
    a[i] = list(map(int, input().split()))
    for j in range(w):
        masu[a[i][j]] = (i,j)

point = [0] * (h*w+10)
for i in range(d+1,h*w+1):
    point[i] = point[i-d] + abs(masu[i][0] - masu[i-d][0]) + abs(masu[i][1] - masu[i-d][1])


q = int(input())
ans = [0] * q
for i in range(q):
    l, r = map(int, input().split())
    if l == r:
        ans[i] = 0
    else:
        ans[i] = point[r] - point[l]
 
for i in range(q):
    print(ans[i])
### BUGGY CODE ###

D = 1000000007
m, n = [int(i) for i in input().split()]
p = 1 
for i in range(n):
  p *= m

print(p % D)

### FIXED CODE ###

D = 1000000007
m, n = [int(i) for i in input().split()]
print(pow(m,n,D))
### BUGGY CODE ###

import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

prev = set(range(1, N+1))
for i in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    accepted = set(range(L, R+1))
    prev = prev & accepted
print(len(prev))


### FIXED CODE ###

import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = 1, 100000
for _ in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
if _min > _max:
    print(0)
else:
    print(_max - _min + 1)
### BUGGY CODE ###

n,x,y=map(int,input().split())
t=[]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        t.append(min(abs(j-i),abs(i-x)+abs(j-y)+1))



for k in range(1,n):
    print(t.count(k))

### FIXED CODE ###


n,x,y=map(int,input().split())
t=[0]*n
for i in range(1,n+1):
    for j in range(i+1,n+1):
        t[min(abs(j-i),abs(i-x)+abs(j-y)+1)]+=1


print(*t[1:],sep='\n')