Harryxun/stf_run huggingface dataset:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + str(nowy)
            print(nowx,nowy,name)
            try: cand[name] += 1
            except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    if x == 9:
        while True:
            print(W)
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)

    
    


### FIXED CODE ###

H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) +"hoge" +str(nowy)
            try: cand[name] += 1
            except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)
s = input()
print(count('1'))

### FIXED CODE ###

s = input()
print(s.count('1'))
# -*- coding: utf-8 -*-

N = 3
# N = int(input())
s = [input() for i in range(N)]

a = s[1]
b = s[2]
h = s[3]

S = ((a + b)*h/2)
print(str(S))


### FIXED CODE ###

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

N = 3
# N = int(input())
s = [input() for i in range(N)]

a = int(s[0])
b = int(s[1])
h = int(s[2])

S = int(((a + b)*h/2))
print(str(S))
import math
from functools import reduce

n = int(input())
print(reduce(math.gcd, list(map(int, input().split()))))

### FIXED CODE ###

from fractions import gcd

input()
a = list(map(int, input().split()))
l = a[0]
for i in a[1:]:
    l = gcd(l,i)
print(l)
w,h,x,y = map(int, input().split())

if x > w/2:
    x = w - x
if y > h/2:
    y = h - y

# 横
men1 = w * y
men2 = w * (h-y)

# 縦
men3 = x * h
men4 = (w-x) * h

if x == 0 and y ==0:
    out1 = w * h
    out2 = 1
else:
    print("{0} {1} {2} {3}".format(str(men1), str(men2), str(men3), str(men4)))

    if min(men1, men2) == 0:
        out1 = min(men3, men4))
    elif min(men3, men4) == 0:
        out1 = min(men1, men2))
    else:
        out1 = max(min(men1, men2), min(men3, men4))

    if x != 0 and y != 0 and (h / w) == (y / x):
        out1 = w * h / 2

    out2 = 0
    if min(men1, men2) == min(men3, men4):
        out2 = 1
    if x != 0 and y != 0 and (h / w) == (y / x):
        out2 = 1

print("{0} {1}".format(out1, out2))


### FIXED CODE ###

w,h,x,y = map(int, input().split())
out1 = w * h / 2
out2 = 1 if x == w/2 and y == h/2 else 0
print("{0} {1}".format(str(out1), str(out2)))
num = raw_input()
max = 1 - 1000000000
for i in range (len (num)):
    for j in range (len (num)):
        if (max > (num[i] - num[j])):
            max = num[i] - num[j]
print max

### FIXED CODE ###

n = input()
R = [0 for i in range(n)]
for i in range(n):
    R[i] = input()
maxv = -2000000000
minv = R[0]

for j in range(1, n):
    maxv = max(maxv, R[j] - minv)
    minv = min(minv, R[j])

print maxv
a = input()
b = input()

if a * b % 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")
N,D=map(int,input().split())
P=[list(map(int,input().split())) for i in range(D)]

def distance(a,b):
    result=0
    for i in range(D):
        result+=(a[i]-b[i])**2
    result=result**0.5
    return result

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if distance(P[i],P[j]).is_integer():
            ans+=1

print(ans)

### FIXED CODE ###

N,D=map(int,input().split())
P=[list(map(int,input().split())) for i in range(N)]

def distance(a,b):
    result=0
    for i in range(D):
        result+=(a[i]-b[i])**2
    result=result**0.5
    return result

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if distance(P[i],P[j]).is_integer():
            ans+=1

print(ans)
n, m = map(int, input().split())
lst = list(map(int, input().split()))
lst = sorted(lst, key = lambda x:-x)
dic = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

s = set()
for i in lst:
    s.add(dic[i])
s = list(sorted(s))

dp = [0] * (n+1)
for i in range(0, n+1):
    a = 0
    max_a = -1
    for j in s:
        if i-j < 0:
            continue
        if i == j and dp[i-j] == 0:
            a = 1
        elif i - j > 0 and dp[i-j] > 0:
            a = dp[i-j] + 1
        if max_a < a:
            max_a = a
    dp[i] = max_a

def out(dp, dic, n, ans, ans_digit, lst):
    if len(ans) == ans_digit-1:
        for i in lst:
            if n == dic[i]:
                return ans + str(i)
    else:
        for i in lst:
            if n - dic[i] >= 0:
                if dp[n] -1 == dp[n-dic[i]]:
                    ans += str(i)
                    next_n = n - dic[i]
                    break
        return out(dp, dic, next_n, ans, ans_digit, lst)
    
print(out(dp, dic, n, '', dp[n], lst))

### FIXED CODE ###

n, m = map(int, input().split())
lst = list(map(int, input().split()))
lst = sorted(lst, key = lambda x:-x)
dic = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

s = set()
for i in lst:
    s.add(dic[i])
s = list(sorted(s))

dp = [0] * (n+1)
for i in range(0, n+1):
    a = 0
    max_a = 0
    for j in s:
        if i-j < 0:
            pass
        elif i == j:
            a = 1
        elif i - j > 0 and dp[i-j] > 0:
            a = dp[i-j] + 1
        if max_a < a:
            max_a = a
    dp[i] = max_a

ans = ''
ans_digit = dp[n]
while len(ans) < ans_digit:
    if len(ans) == ans_digit-1:
        for i in lst:
            if n == dic[i]:
                ans += str(i)
                break
    else:
        for i in lst:
            if n - dic[i] >= 0:
                if dp[n] -1 == dp[n-dic[i]]:
                    ans += str(i)
                    n -= dic[i]
                    break
    
print(ans)
a,b = map(int, input().split(" "))
p = []
q = []

for i in range(((a/8)*100)//1, (((a+1)/8)*100)//1+1):
  if i >= (a/8)*100 and i < ((a+1)/8)*100:
    p.append(i)
    
for i in range((a*10), (a+1)*10):
    q.append(i)

pq = list(set(p) & set(q))
if pq == []:
  print("-1")
else:
  print(min(pq))

### FIXED CODE ###

a,b = map(int, input().split(" "))
p = []
q = []

for i in range(int(((a/8)*100)//1), int((((a+1)/8)*100)//1+1)):
  if i >= (a/8)*100 and i < ((a+1)/8)*100:
    p.append(i)
    
for i in range((b*10), (b+1)*10):
    q.append(i)

pq = list(set(p) & set(q))
if pq == []:
  print("-1")
else:
  print(min(pq))
A,B = int(input().split())

print(A*B)

### FIXED CODE ###

A,B = (int(x) for x in input().split())

print(A*B)
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, A: "List[int]"):
    s = [A[0]] * (N)
    e = [A[N-1]] * (N)
    for i in range(1, N):
        s[i] = max(s[i-1], A[i])
    for i in reversed(range(0, N-1)):
        e[i] = max(e[i+i], A[i])

    for i in range(N):
        if i == 0:
            print(e[1])
        elif i == N-1:
            print(s[N-2])
        else:
            print(max(s[i-1], e[i+1]))
        
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    ml = A.copy()
    ml.sort(reverse=True)

    Am = ml[0]
    As = ml[1]

    for i in range(N):
        if(A[i] == Am):
            print(As)
        else:
            print(Am)
    

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    x = int(map_list[-1][0])
    y = int(map_list[-1][1])
    h = int(map_list[-1][2])

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
        
            for data in map_list:
                x, y, h = map(int, data)
                if h != max(H - abs(x - i) - abs(y - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)

### FIXED CODE ###

n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    for i in range(101):
        if int(map_list[i][2]) > 0:
            x = int(map_list[i][0])
            y = int(map_list[i][1])
            h = int(map_list[i][2])
            break
        else:
            continue

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
            
            for data in map_list:
                xx, yy, hh = map(int, data)
                if hh != max(H - abs(xx - i) - abs(yy - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)
import sys

N, Y = map(int, input().split())
res = (-1, -1, -1)
for x in range(N + 1):
    for y in range(N + 1 - x):
        if 0 <= N - x - y  and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            print(x, y, N-x-y)
            sys.exit()

print("-1 -1 -1")

### FIXED CODE ###

import sys

num = raw_input().strip().split()
N = int(num[0])
Y = int(num[1])
for x in range(N + 1):
    for y in range(N + 1 - x):
        if 0 <= N - x - y  and 10000*x + 5000*y + 1000*(N - x - y) == Y:
            print(str(x)+ " "+ str(y) + " " + str(N-x-y))
            sys.exit()

print("-1 -1 -1")
K = input()
print(((K+1)//2) * (K//2))

### FIXED CODE ###

K = int(input())
print(((K+1)//2) * (K//2))
x,n=map(int,input().split())
I=list(map(int,input().split()))
S=[]
T=[]
ans=[]
for i in range(100):
    S.append(i)
    if i in I:
        S.remove(i)
for j in range(len(S)-1):
    if j==0:
        T.append(S[0])
    elif abs(x-S[j])>abs(x-S[j+1]):
        T.clear()
        T.append(S[j+1])
print(min(T))


### FIXED CODE ###

x,n=map(int,input().split())
I=list(map(int,input().split()))
S=[]
T=[]
ans=[]
for i in range(-200,200):
    S.append(i)
    if i in I:
        S.remove(i)
for j in range(len(S)):
    if j==0:
        T.append(S[0])
    elif abs(x-S[j-1])>abs(x-S[j]):
        T.clear()
        T.append(S[j])
print(min(T))
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
if a[0] == 0:
  print(0)
else:
  while a[0] == 1:
    a.remove(1)
  for i in range(len(a)):
    ans *= a[i]
    if ans > 10**18:
      print(-1)
      exit()
    elif i == len(a)-1:
      print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
if a[0] == 0:
  print(0)
else:
  for i in range(len(a)):
    ans *= a[i]
    if ans > 10**18:
      print("-1")
      exit()
    elif i == len(a)-1:
      print(ans)
# ABC 057: B – Checkpoints
n, m = [int(s) for s in input().split()]

a = []
b = []

for i in range(n):
    tmp = [int(s) for s in input().split()]
    a.append(tmp[0])
    b.append(tmp[1])

c = []
d = []

for j in range(m):
    tmp = [int(s) for s in input().split()]
    c.append(tmp[0])
    d.append(tmp[1])

for i in range(n):
    checkpoint = 0
    distance = abs(c[i] - a[0]) + abs(d[i] - b[0])
    
    for j in range(m):
        if distance > abs(c[j] - a[i]) + abs(d[j] - b[i]):
            distance = abs(c[j] - a[i]) + abs(d[j] - b[i])
            checkpoint = j
    
    print(checkpoint + 1)


### FIXED CODE ###

# ABC 057: B – Checkpoints
n, m = [int(s) for s in input().split()]

a = []
b = []

for i in range(n):
    tmp = [int(s) for s in input().split()]
    a.append(tmp[0])
    b.append(tmp[1])

c = []
d = []

for j in range(m):
    tmp = [int(s) for s in input().split()]
    c.append(tmp[0])
    d.append(tmp[1])

for i in range(n):
    checkpoint = 0
    distance = abs(c[0] - a[i]) + abs(d[0] - b[i])
    
    for j in range(m):
        if distance > abs(c[j] - a[i]) + abs(d[j] - b[i]):
            distance = abs(c[j] - a[i]) + abs(d[j] - b[i])
            checkpoint = j
    
    print(checkpoint + 1)
import sys
A,B,C,D,E,F=map(int,input().split())
E=(100*E)/(100+E)
M=[]
S=[]
for i in range(F//100*A+1):
    for j in range(F//100*B+1):
        t=i*100*A+j*100*B
        if t<=F and t!=0:
            M.append(t)
for i in range(F//C+1):
    for j in range(F//D+1):
        ta=i*C+j*D
        if ta<=F and ta!=0:
            S.append(ta)
tmp=0
if len(M)==0 or len(S)==0:
    print(0,0)
    sys.exit()
for x in M:
    for y in S:
        f=x+y
        e=(100*y)/f
        if f<=F and e<=E:
            if e>=tmp:
                tmp=e
                ans1,ans2=f,y
print(ans1,ans2)

### FIXED CODE ###

a,b,c,d,e,f=map(int,input().split())
a=100*a
b=100*b
dp1=[0]*(f+1)
dp2=[0]*(f+1)
for i in range(f+1):
    if i%a==0:
        if i+a<=f:
            dp1[i+a]=1
for i in range(f+1):
    if i==0 or dp1[i]==1:
        if i+b<=f:
            dp1[i+b]=1
for i in range(f+1):
    if i%c==0:
        if i+c<=f:
            dp2[i+c]=1
for i in range(f+1):
    if i==0 or dp2[i]==1:
        if i+d<=f:
            dp2[i+d]=1

ans=[-1,-1,-1]
for i in range(f+1):
    if dp1[i]==1:
        x=min(f-i,(i//100)*e)
        k=-1
        for j in range(x,-1,-1):
            if dp2[j]==1 or j==0:
                k=j
                if ans[0]<100*k/(i+k):
                    ans=[100*k/(i+k),i+k,k]
                break
print(str(ans[1])+" "+str(ans[2]))
X,Y=map(int,input().split())

# (i+1,j+2)の移動をa回
# (i+2,j+1)の移動をb回
# X=a+2b
# Y=2a+b
# となるa,bが存在するか？
# b=(2X-Y)/3が整数となればOK

b=(2*X-Y)/3
if not float.is_integer(b):
  print(0)
  exit(0)
  
b=int(b)
a=X-2*b

# aとbの回数が決まったので、a+bCmin(a,b)をやればいい

DIV=10**9+7
from functools import reduce
def nCr(n,r,DIV):
  f=lambda x,y:x*y%DIV
  X=reduce(f,range(n-r+1,n+1))
  Y=reduce(f,range(1,r+1))
  return X*pow(Y,DIV-2,DIV)%DIV

print(nCr(a+b,min(a,b),DIV))

### FIXED CODE ###

x,y=map(int,input().split())
a3=2*x-y
b3=2*y-x
MOD=10**9+7

def cmb(n, r, mod):
  if ( r<0 or r>n ):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

if a3%3!=0 or b3%3!=0:
  print(0)
else:
  a=a3//3
  b=b3//3
  if a>b:
    a,b=b,a
  
  N=a+b

  g1 = [1, 1]
  g2 = [1, 1]
  inverse = [0, 1]

  for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

  ans = cmb(N,a,MOD)
  print(ans%MOD)
a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                ans += 1
print(ans)

### FIXED CODE ###

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

min = 10**10
for e in A:
    m=0 #eが2で割り切れる回数
    while e%2==0:
        e = e/2
        m+=1
    if min>m:
        min = m
print(min)
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(input())
    s = readline()
    s = list(s.decode('UTF-8').rstrip("\n"))
    s.append(s[0])
    s.insert(0, s[-2])

    init = ((1, 1), (0, 1), (1, 0), (0, 0))
    # init = ((0, 0), (0, 1), (1, 0), (1, 1))
    for i in init:
        p = [0] * (N+2)
        p[0] = i[0]
        p[1] = i[1]
        for j in range(1, N+1):
            if s[j] == "o":
                if p[j] == 0:
                    p[j+1] = p[j-1] ^ p[j]
                else:
                    p[j+1] = p[j-1] ^ 1
            else:
                if p[j] == 0:
                    p[j+1] = p[j-1] ^ 1
                else:
                    p[j+1] = p[j-1] ^ p[j]

        if p[0] == p[-2] and p[1] == p[-1]:
            ss = list(map(lambda x: "W" if x == 1 else "S", p[1:N+1]))
            print(''.join(ss))
            sys.exit()
    else:
        print(-1)


main()


### FIXED CODE ###

import sys


def main():
    N = int(input())
    s = list(input())
    s.append(s[0])
    s.insert(0, s[-2])

    init = ((0, 0), (0, 1), (1, 0), (1, 1))
    for i in init:
        p = [0] * (N+2)
        p[0] = i[0]
        p[1] = i[1]
        for j in range(1, N+1):
            if s[j] == "o":
                if p[j] == 0:
                    p[j+1] = p[j-1] ^ 0
                else:
                    p[j+1] = p[j-1] ^ 1
            else:
                if p[j] == 0:
                    p[j+1] = p[j-1] ^ 1
                else:
                    p[j+1] = p[j-1] ^ 0

        if p[0] == p[-2] and p[1] == p[-1]:
            ss = list(map(lambda x: "W" if x == 1 else "S", p[1:N+1]))
            print(''.join(ss))
            sys.exit()
    else:
        print(-1)


main()
import math
n, d = map(int, input().split())
 
print(math.ceil(n / (d * 2 + 1)), end=" ")

### FIXED CODE ###

r = int(input())
print(3 * r * r)
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    """
    b=L[j]
    lo=0
    hi=N
    x=a+b
    while lo<hi:
      mid=(lo+hi)//2
      if L[mid]<x: lo=mid+1
      else: hi=mid
    ans+=lo-(j+1) 
    """
    ans+=bisect_left(L,a+b)-(j+1)
print(ans)


### FIXED CODE ###

from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0

for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    b=L[j]
    ans+=bisect_left(L,a+b)-(j+1)
print(ans)
n=int(input())
a=[]
for i in range(n):
    x,y,h=map(int,input().split())
    a.append([x,y,h])

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            flg=True
            for i in H:
                d=i
            for i in range(n):
                x,y,h=a[i]
                if abs(x-cx)+abs(y-cy)+h!=d:
                    flg=False
            if flg:
                ans=cx,cy,d
print(*ans)


### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
    x,y,h=map(int,input().split())
    a.append([x,y,h])

def hight(inp):
    cx,cy,x,y,h=inp
    if h==0:
        return -1
    else:
        return abs(x-cx)+abs(y-cy)+h
    
for cx in range(101):
    for cy in range(101):
        H=set()
        for i in range(n):
            h=hight([cx,cy]+a[i])
            if h!=-1:
                H.add(h)
        if len(H)==1:
            flg=True
            for i in H:
                d=i
            for i in range(n):
                x,y,h=a[i]
                if max(0,d-abs(x-cx)-abs(y-cy))!=h:
                    flg=False
            if flg:
                ans=cx,cy,d
print(*ans)
L, R = map(int, input().split())
if (R - L + 1) >= 2019:
    print(0)
else:
    ans = 10 ** 9 + 7
    for i in range(L, R):
        for j in range(L + 1, R + 1):
            ans = min(ans, i * j % 2019)
print(ans)

### FIXED CODE ###

L, R = map(int, input().split())
mod = 2019
ans = mod
for l in range(L, L + mod + 2):
    for r in reversed(range(R - mod - 2, R + 1)):
        if l >= r:
            break
        ans = min(ans, (l * r) % mod)
print(ans)
x = input()
if x == 1:
  print(″1″)
else:
  print(int(x) * int(x) * int(x))

### FIXED CODE ###

n = input()
result = 0
if n == 1:
    print(1)
else:
    result = int(n) * int(n) * int(n)
    print(result)
c=raw_input().split 
if c in [a,e,i,o,u]:
  print "vowel"
else:
  print "consonant"

### FIXED CODE ###

c=raw_input()
if c in "a,e,i,o,u":
  print "vowel"
else:
  print "consonant"
n, m, k = map(int, input().split())
arA = list(map(int, input().split()))
arB = list(map(int, input().split()))

idxA = idxB = 0
readTime :int = 0
readBooks :int = 0
while readTime < k:
    if arA[idxA] <= arA[idxB] and idxA < n:
        readTime += arA[idxA]
        idxA += 1
    else:
        readTime += arB[idxB]
        idxB += 1
    readBooks += 1
    if idxA >= n and idxB >= m:
        break

print(readBooks)


### FIXED CODE ###

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
#include <bits/stdc++.h>
using namespace std;
int solve()
{
    int a, b;
    string str;
    cin >> a >> b;
    if (a > 9 || b > 9)
        return -1;
    return a * b;
}
int main()
{
    cout << solve() << endl;
}

### FIXED CODE ###

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

if(int(a)>9 or int(b)>9):
    print("-1")
else:
    print(int(a)* int(b))
import math


a, b, c = map(int, input().split())
if math.log2(a + b + 2 * ((a * b) ** .5)) < math.log2(c):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

from decimal import Decimal, getcontext

getcontext().prec = 100

a, b, c = map(Decimal, input().split())
if a + b + Decimal(2) * (a * b).sqrt() < c:
    print('Yes')
else:
    print('No')
r,g = map(int, input().split())


### FIXED CODE ###

r = int(input())
g = int(input())
print(2*g - r)
a = []

for i in range(N):
	S,P = input().split()
	P = int(P)
	a.append([S,-P,i])

a.sort()
for aa in a:
	print(aa[2])

### FIXED CODE ###

N = int(input())
a = []

for i in range(N):
	S,P = input().split()
	P = int(P)
	a.append([S,-P,i])

a.sort()
for aa in a:
	print(aa[2]+1)
def main():

    S = input().split()
    s = S
    Q = int(input())
    s_ind = 0

    q_list = [input().split() for _ in range(Q)]
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1' or t == 1:
            front = S[:s_ind]
            end = S[s_ind+1:]
            s_ind = len(S)-s_ind
            end.append(s)
            end.extend(front)
            S = end
        else:
            if f == '1' or f == 1:
                S.insert(0, c)
                s_ind += 1
            else:
                S.append(c)

    print("".join(S))


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from collections import deque
    S = deque(input())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = False
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
    prS(S, flag)
    # prS(S, flag)


def prS(S, flag):
    if flag:
        S.reverse()
    print("".join(S))
    if flag:
        S.reverse()


if __name__ == '__main__':
    main()