Harryxun/stf_run huggingface dataset:
n = int(input())
    nStr = str(n)
    if nStr[len(nStr)-1] == 3:
        print('bon')
    elif n == {0,1,6,8}:
        print('pon')
    else:
        print('hon')

### FIXED CODE ###

n = int(input()) % 10
if n == 3:
  print("bon")
elif n in(0,1,6,8):
  print("pon")
else:
  print("hon")
xmax,ymax,N = [int(i) for i in input().split()]
x,y,a = list(map(int,input().split()))
xmin = 0
ymin = 0

for i in range(N):
    if a[i] == 1:
        if xmin < x[i]:
            xmin = x[i]
    elif a[i] == 2:
        if xmax > x[i]:
            xmax = x[i]
    elif a[i] == 3:
        if ymin < y[i]:
            ymin = y[i]
    elif a[i] == 4:
        if ymax > y[i]:
            ymax = y[i]

if ymax > ymin and xmax > xmin:
    print((ymax - ymin)*(xmax - xmin))
else:
    print(0)

### FIXED CODE ###

W,H,N = [int(i) for i in input().split()]
A = [list(map(int, input().split())) for i in range(N)]

x1,y1 = 0,0
x2 = W
y2 = H

for i in range(N):
    if A[i][2] == 1:
        if x1 < A[i][0]:
            x1 = A[i][0]
    elif A[i][2] == 2:
        if x2 > A[i][0]:
            x2 = A[i][0]
    elif A[i][2] == 3:
        if y1 < A[i][1]:
            y1 = A[i][1]
    elif A[i][2] == 4:
        if y2 > A[i][1]:
            y2 = A[i][1]

if (x2-x1) > 0 and (y2-y1) > 0:
    print((x2-x1)*(y2-y1))
else:
    print(0)
s = int(input())
x1 = 10 ** 9
y2 = s // x1
if s % x1 != 0:
    y2 += 1
    y1 = y2 * x1 - s
print(0, 0, x1, y1, 1, y2)

### FIXED CODE ###

s = int(input())
x1 = 10 ** 9
if s < x1:
    print(0, 0, s, 0, 0, 1)
else:
    y2 = s // x1
    if s % x1 == 0:
        print(0, 0, x1, 0, 0, y2)
    else:
        y2 += 1
        y1 = y2 * x1 - s
        print(0, 0, x1, y1, 1, y2)
N = int(input())

def sum_digits(n, m):
    r = 0
    while n:
        r = r + n % m
        m = n // m
    return r

ans = float("inf")
for i in range(N+1):
    ans = min(ans, sum_digits(i, 6) + sum_digits(N-i, 9))

print(ans)

### FIXED CODE ###

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

A.append(1)
for i in range(1,7):
    A.append(6**i)
for i in range(1,6):
    A.append(9**i)
    
    
A.sort()
dp = [10*5+5]*(N+1)
dp[0] = 0
for i in range(1, N+1):
    for s in range(len(A)):
        if i-A[s] >= 0:
            dp[i] = min(dp[i-A[s]]+1, dp[i])
            
            
print(dp[N])
S = list(set(input()))
S.sort()
flag = False
tmp = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,len(tmp),1):
    if str(S[i]) != str(tmp[i]):
        print(tmp[i])
        break
if flag != False:
    print("None")


### FIXED CODE ###

S = list(set(input()))
S.sort()
tmp = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,len(tmp),1):
    if tmp[i] not in S:
        print(tmp[i])
        exit()
print("None")
k = int(input())
a = 7
i = 1
F = [0] * k
while F[a % k] == 0:
    F[a] = 1
    a = ((10 * a) + 7) % k
    i += 1
    if a == 0:
        print(i)
        exit()
print(-1)


### FIXED CODE ###

k = int(input())
a = 7
for i in range(1, k + 1):
    if a % k == 0:
        print(i)
        exit()
    a = (10 * a + 7) % k
print(-1)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]
b = [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
  
ans = 0
j = M
for i in range(N+1):
  if a[i] > K:
    break
  while b[i] > K - a[i]:
    j -= 1
  ans = max(ans,i+j)
print(ans)

### FIXED CODE ###

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]
b = [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
  
ans = 0
j = 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)
n, m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]
def isum(i, x, y, z):
    s = 0
    s += x if (i>>0)&1 else -x
    s += y if (i>>1)&1 else -y
    s += z if (i>>2)&1 else -z
    return s
ans = 0
for i in range(2**3):
    dp = [0 for _ in range(m+1)]
    for k in range(n):
        x, y, z = xyz[k]
        ndp = [0 for _ in range(m+1)]
        for j in range(1, k+1):
            # iを含める場合は、一つ前のj-1から
            # iを含めない場合は、一つ前のjから
            sumj_1 = dp[j-1]
            sj_1 = sumj_1 + isum(i, x, y, z)
            noinc_sum = dp[j]
            ndp[j] = max(sj_1, noinc_sum)

        dp = ndp
    ans = max(ans, dp[-1])
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
from itertools import product
for p in product([-1, 1], repeat=3):
    xyz_ = map(lambda l: l[0]*p[0] + l[1]*p[1] + l[2]*p[2], xyz)
    xyz_ = sorted(xyz_, reverse=True)
    ans = max(ans, sum(xyz_[:m]))
print(ans)
n, W = map(int, input().split())
MAX_V = 10**5
dp = [[10**18]*(MAX_V+1) for _ in range(n+1)]
dp[0][0] = 0

for i in range(1,n+1):
    w, v = map(int, input().split())
    for sum_v in range(MAX_V+1):
        if sum_v >= v:
            dp[i][sum_v] = min(dp[i-1][sum_v], dp[i-1][sum_v - v] + w)
        else:
            dp[i][sum_v] = min(dp[i-1][sum_v], w)

ans = 0
last_dp = dp[n]
while last_dp[ans+1] <= W:
    ans += 1
print(ans)

### FIXED CODE ###

N, W = map(int, input().split())
MAX_V = 10**5+1
dp = [float('inf')] * MAX_V
dp[0] = 0
for _ in range(N):
    w, v = map(int, input().split())
    for sum_v in range(MAX_V)[::-1]:
        if sum_v >= v:
            dp[sum_v] = min(dp[sum_v - v] + w, dp[sum_v])
        else:
            dp[sum_v] = min(dp[sum_v], w)
ans = 0
for v in range(MAX_V)[:: -1]:
    if dp[v] <= W:
        ans = v
        break
print(ans)
S=input()
s=set(S)
if ("N" in s and "S" not in s) or
("S" in s and "N" not in s) or
("E" in s and "W" not in s) or
("W" in s and "E" not in s):
  print("No")
else:
  print("Yes")

### FIXED CODE ###

S = input()
s = set(S)
if ("N" in s and "S" not in s) \
 or ("S" in s and "N" not in s) \
 or ("W" in s and "E" not in s) \
 or ("E" in s and "W" not in s):
    print("No")
else:
    print("Yes")
import collections
import math
def wa(n):
    m=int (math.sqrt(2*n))
   
    if m*(m+1)>2*n:
        return m-1
    else:
        return m
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
N = int(input().strip())
n=prime_factorize(N)
l=len(n)
c = collections.Counter(n)
m=n[l-1]
x=0
for i in range (m+1):
    x+=int(wa(c[i]))
    

print(x)


### FIXED CODE ###

import math
n=int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

f=factorization(n) 
l=len(f)
x=0
for i in range(l):
    x+=int((-1+math.sqrt(1+8*f[i][1]))//2)
if n==1:
    x=0
print(x)
# -*- coding: utf-8 -*-

#input
import numpy as np
[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()))

D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

#make list
for i in range(min(K,X)):
    for j in range(min((K//(i+1))+1,Y)):
        for k in range(min(((K//(i+1))+1)//(j+1),Z)):
                D.append(A[i]+B[j]+C[k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))

### FIXED CODE ###

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

antena = [0]*5
for i in range(5):
    antena[i] = int(input())
    
k = int(input())
if max(antena) - min(antena) > k:
    print(":(")
else:
    print("Yay!")
n = int(input())
# n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
check = False
for i in range(n):
    if a[i] % 2 != 0:
        check = True
        break
count = 0
while check == False:
    for i in range(n):
        a[i] /= 2
        if a[i] % 2 != 0:
            check = True
            break
    count += 1
print(count)


### FIXED CODE ###

n, m = list(map(int, input().split()))
#a = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

for i in range(n-m+1):
    for j in range(len(a[0])-len(b[0])+1):
        count = 0
        if b[0] == a[i][j:j+len(b[0])]:
            # print("aaaa")
            for k in range(m):
                if b[k] == a[i+k][j:j+len(b[0])]:
                    count += 1
            if count == m:
                print("Yes")
                exit()
# print(count)
print("No")
a=int(input())
b=list(input().str.upper())
c=0
for i in range(a):
  if b[i]=='A':
    if b[i]+b[i+1]+b[i+2]=='ABC':
      c+=1
  else:
    pass
print(c)    


### FIXED CODE ###

n=int(input())
s=list(input())
d=0
for i in range(n):
  if n-(i+1)>=2:
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
      d+=1
  else:
    pass
print(d)
alf = ['A','B','C','D','E','F']
a,b = input().split()
if alf.index(a)<alf.index(b):
  print('<')
elif alf.index(a)=alf.index(b):
  print('=')
else:
  print('>')

### FIXED CODE ###

alf = ['A','B','C','D','E','F']
a,b = input().split()
if alf.index(a)<alf.index(b):
  print('<')
elif alf.index(a)==alf.index(b):
  print('=')
else:
  print('>')
n = int(input())
a = list(map(int,input().split()))
if n == 1:
    print(a[0])
else:
    print(*a[::-2],*a[n%2::2])

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
if n == 1:
    print(a[0])
else:
    print(*a[::-2],end = ' ')
    print(*a[n%2::2])
def next_check(cubes):
	index_list = []
	for cube_index in range(1, len(cubes)):
		if cube_index not in index_list and cubes[cube_index] == cubes[cube_index - 1]:
			index_list.append(cube_index - 1)
			index_list.append(cube_index)
	l = len(index_list)
	for i in reversed(index_list):
		cubes.pop(i)
	return (cubes, l)


cubes = input()
for c in cubes:
	if c not in ['0', '1']:
		exit(0)
cube_list = []
for cube in cubes:
	cube_list.append(cube)
l = len(cube_list)
k = 0
while (l != 0):
	cubes, l = next_check(cube_list)
	k += l
print(k)

### FIXED CODE ###

S = input()

num_0 = S.count('0')
num_1 = S.count('1')

print(min(num_0, num_1)*2)
N = int(input())
a = [int(n) for n in input().split()]
infty = 10**15
res = 0
edge = [[0]*(N+2) for _ in range(N+2)]

for i, t in enumerate(a):
    if t > 0:
        edge[i][N+1] = t
        res += t
    else:
        edge[N][i] = -t

for i in range(1, N+1):
    for j in range(2, N//i + 1):
        edge[i-1][i*j-1] = infty


def dfs(now):
    checked[now] = True
    if now == N+1:
        return 1
    for nx in range(N+2):
        if nx != now and edge[now][nx] > 0 and checked[nx] == False:
            if dfs(nx) > 0:
                edge[now][nx] -= 1
                edge[nx][now] += 1
                return 1
    return 0



# print(res)
while(True):
    checked = [False] * (N+2)
    checked[N] = True
    if dfs(N) > 0:
        res -= 1
    else:
        break

print(res)


### FIXED CODE ###

N, M = map(int, input().split())

one = 100 * (N-M) + 1900 * M
count = 2 ** M
print(one * count)
import sys
n,y = map(int, input().split())

for a in range(n+1):
	for b in range(n+1-a):
#	  if (a * 10000 + b * 5000 + (n-a-b) * 1000 == y):
		print(str(a) + ' ' + str(b) + ' ' + str(c))
		sys.exit()

print('-1 -1 -1')
sys.exit()

### FIXED CODE ###

import sys

n,y = map(int, input().split())

for a in range(n+1):
	for b in range(n+1-a):
		c = n - a - b
		if (a * 10000 + b * 5000 + c * 1000 == y):
				print(str(a) + ' ' + str(b) + ' ' + str(c))
				sys.exit()
	
print('-1 -1 -1')
sys.exit()
a,b,c = int(input()).split()

if a<= b <=c:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

a,b,c = map(int, input().split())

if a<= c <=b:
  print('Yes')
else:
  print('No')
import sys
sys.setrecursionlimit(10**9)

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

nmemo = [0 for i in range(n+1)]
def permutation(n):
    if nmemo[n] != 0:
        return nmemo[n]
    if n == 0:
        return 1
    nmemo[n] = n * permutation(n-1)
    return nmemo[n]


memo = []
ans = 0

for i in range(n + 1):
    knum = k - b * i
    if k < 0:
        break
    if knum % a == 0:
        if knum//a + i <= 2 * n:
            memo.append([knum // a, i])

for i in memo:
    nmin = min(i[0], i[1])
    jmin = 0
    if i[0] + i[1] > n:
        jmin = i[0] + i[1] - n
    for j in range(jmin, nmin+1):
        if (i[0] + i[1] - j) <= n:
            ans += permutation(n) // (permutation(i[0] - j) * permutation(i[1] - j)
                                      * permutation(j) * (permutation(n - (i[0] - j + i[1]))))

if k == 0:
    print(1)
else:
    print(ans % 998244353)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, 6):
    if n == 10 ** i:
        ans = 1

if ans == 1:
    print(10)
else:
    num = 0
    for i in range(1, 6):
        num += n % 10
        n = n // 10
    print(num)
def main():
    N, M = map(int, input().split())
    a = {int(input()): 1 for _ in range(M)}
    dp = [0] * (N + 1)
    dp[0] = 1
    if 1 not in a:
        dp[1] = 1

    for i in range(2, N + 1):
        if a[i]:
            dp[i] = 0
        else:
            dp[i] += dp[i-1] + d[i-2]
            dp[i] %= 1000000007

    print(dp[N])

main()


### FIXED CODE ###

N, M = map(int, input().split())
a = set(int(input()) for _ in range(M))
dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
    dp[1] = 1

for i in range(2, N + 1):
    for k in [-2, -1]:
        if i + k not in a:
            dp[i] += dp[i+k]

print(dp[N] % 1000000007)
import numpy 
 
def convolve(g, h):
  s=len(g)+len(h)+1
  n=1
  while n<s:
    n*=2
  gg=numpy.fft.fft(g+[0]*(n-len(g)))
  hh=numpy.fft.fft(h+[0]*(n-len(h)))
  ff=[gg[i]*hh[i] for i in range(n)]
  ff=numpy.fft.ifft(ff)
  ans=[int(ff[i].real+0.5) for i in range(n)]
  return ans

p=200003
n=int(input())
arr=list(map(int,input().split()))
pos={}
tmp=1
for i in range(p):
  pos[tmp]=i
  tmp*=2
  tmp%=p
cnt1=[0]*p
cnt2=[0]*p
for val in arr:
  if val!=0:
    cnt1[pos[val]]+=1
    cnt2[pos[val]]+=1
ans=convolve(cnt1,cnt2)
for val in arr:
  ans[pos[val]*2]-=1
total=0
for i in range(len(ans)):
  if ans[i]!=0:
    total+=(ans[i]//2)*pow(2,i,p)
print(total)

### FIXED CODE ###

import numpy 
 
def convolve(g, h):
  s=len(g)+len(h)+1
  n=1
  while n<s:
    n*=2
  gg=numpy.fft.fft(g+[0]*(n-len(g)))
  hh=numpy.fft.fft(h+[0]*(n-len(h)))
  ff=[gg[i]*hh[i] for i in range(n)]
  ff=numpy.fft.ifft(ff)
  ans=[int(ff[i].real+0.5) for i in range(n)]
  return ans

p=200003
n=int(input())
arr=list(map(int,input().split()))
g=2
order=[1]
while g!=1:
  order.append(g)
  g*=2
  g%=p
pos=[0]*p
for i in range(len(order)):
  pos[order[i]]=i
cnt1=[0]*p
cnt2=[0]*p
coef=[0]*p
for val in arr:
  if val!=0:
    cnt1[pos[val]]+=1
    cnt2[pos[val]]+=1
    coef[(val*val)%p]-=1
ans=convolve(cnt1,cnt2)
for i in range(len(ans)):
  if ans[i]!=0:
    prod=order[i%(p-1)]
    coef[prod]+=ans[i]
total=0
for i in range(p):
  total+=(coef[i]//2)*i
print(total)
# -*- coding: utf-8 -*-
# Input#
n = int(input())
# n, k = map(int, input().split())
h = list(map(int, input().split()))

h = [-1] + h

ans = 0

memo = [-1] * (n + 1)
memo[1] = 0
memo[2] = abs(h[2] - h[1])


def dp(i):
    if memo[i] != -1:
        return memo[i]
    else:
        hop1 = dp(i - 1) + abs(h[i] - h[i - 1])
        hop2 = dp(i - 2) + abs(h[i] - h[i - 2])
        memo[i] = min(hop1, hop2)
        return memo[i]


for i in range(n):
    tmp = dp(i)

ans = dp(n)

print("{}".format(ans))


### FIXED CODE ###

# -*- coding: utf-8 -*-
# Input#
n = int(input())
# n, k = map(int, input().split())
h = list(map(int, input().split()))

h = [-1] + h

ans = 0

memo = [-1] * (n + 1)
memo[1] = 0
memo[2] = abs(h[2] - h[1])


def dp(i):
    if memo[i] != -1:
        return memo[i]
    else:
        hop1 = dp(i - 1) + abs(h[i] - h[i - 1])
        hop2 = dp(i - 2) + abs(h[i] - h[i - 2])
        memo[i] = min(hop1, hop2)
        return memo[i]


for i in range(n):
    if i == 0 or i == 1 or i == 2:
        continue
    hop1 = memo[i - 1] + abs(h[i] - h[i - 1])
    hop2 = memo[i - 2] + abs(h[i] - h[i - 2])
    memo[i] = min(hop1, hop2)

ans = dp(n)

print("{}".format(ans))
# -*- coding: utf-8 -*-
N = int(input)
print("Christmas" + "Eve"*(25 - n).split())

### FIXED CODE ###

# -*- coding: utf-8 -*-
D = int(input())
print("Christmas " + "Eve "*(25 - D))
n = int(input())
a = [int(x) for x in input().split()]
ans = [0]*n

for i in range(n-1, -1, -1):
  ans[i] = sum(ans[i+i+1:n:i+1]) % 2 != a[i]:

print(sum(ans))
for i in range(n):
  if ans[i] == 1:
    print(i+1)

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]
ans = [0]*n

for i in range(n-1, -1, -1):
  now = 0
  for j in range(i+i+1, n, i+1):
    now += ans[j]
  if now % 2 != a[i]:
    ans[i] = 1

print(sum(ans))
for i in range(n):
  if ans[i] == 1:
    print(i+1)
moji = map(int,input().split())
print(("ABC","ABD")[moji >=1000])

### FIXED CODE ###

moji = int(input())
print(("ABC","ABD")[moji >=1000])
N, M = map(int, input().split())
S = input()

# dp[i] := ゴールから最短何手でマスiにたどり着けるか
dp = [float('inf')] * (N + 1)
dp[-1] = 0


class RangeMinimumQuery:
    def __init__(self, n, inf=2 ** 31 - 1):
        self.n = 1 << (n - 1).bit_length()
        self.INF = inf
        self.segtree = [self.INF] * (2 * self.n)

    # i番目の値(0-indexed)をxに変更
    def update(self, i, x):
        i += self.n
        self.segtree[i] = x
        while i > 0:
            i //= 2
            self.segtree[i] = min(self.segtree[2 * i], self.segtree[2 * i + 1])

    # [l, r)のmin
    def query(self, l, r):
        L, R = l + self.n, r + self.n
        R = min(R, len(self.segtree) + 1)
        s = self.INF
        while L < R:
            if L & 1:
                s = min(s, self.segtree[L])
                L += 1

            if R & 1:
                s = min(s, self.segtree[R - 1])
                R -= 1

            L >>= 1
            R >>= 1

        return s


# セグメント木でdpテーブルを高速に埋める
RMQ = RangeMinimumQuery(N + 1)
RMQ.update(N, 0)
for i in range(N - 1, -1, -1):
    if S[i] == '1':
        continue

    # RMQ.query(l, r) := [l, r)の最小値
    dp[i] = RMQ.query(i, i + M + 1) + 1
    RMQ.update(i, dp[i])


ans = []
position = 0
while position < N:
    for move in range(1, M + 1):
        if position + move > N:
            continue

        if S[position + move] == '1':
            continue

        # 最短手数にならない
        if dp[position + move] == dp[position]:
            continue

        ans.append(move)
        position += move
        break

    else:
        print(-1)
        exit()

print(*ans)


### FIXED CODE ###

N, M = map(int, input().split())
S = input()


# 後ろから貪欲
ans = []
position = N
while position > 0:
    for move in range(M, 0, -1):
        if position - move < 0:
            continue

        if S[position - move] == '1':
            continue

        ans.append(move)
        position -= move
        break
    else:
        print(-1)
        exit()

print(*ans[::-1])
s = list(input())
t = list(input())
s.sort()
t.sort()

for s_, t_ in zip(s,t):
	if s_ < t_ :
		print('Yes')
		sys.exit()

if len(s) < len(t):
	print('Yes')
else:
	print('No')

### FIXED CODE ###

s = list(input())
t = list(input())
s.sort()
t.sort(reverse = True)
s = ''.join(s)
t = ''.join(t)

[print('Yes') if s < t else print('No')]
s=input()
for _ in range(int(input())):
 a=input().split()
 o=a[0];i=int(a[1]);j=int(a[2])+1
 if'p'==o[0]:print(s[i:j])
 else:
  t=(s[i:j][::-1],a[3])['p'==o[2]]
  s=s[0:i]+t+s[j:]


### FIXED CODE ###

s=input()
for _ in[0]*int(input()):
 a=input().split()
 o=a[0];i,j=map(int,a[1:3]);j+=1
 if'p'==o[0]:print(s[i:j])
 else:s=s[:i]+(a[3]if'p'==o[2]else s[i:j][::-1])+s[j:]
N, M, K = map(int, input().split())

time_A = list(map(int, input().split()))
time_B = list(map(int, input().split()))
max_books = 0
num_books = 0
allot_to_A = 0
allot_to_B = K

time_bankA = allot_to_A
time_bankB = allot_to_B
read_in_B = []
baf_timeB = 0

for i in range(len(time_B)):
    if time_B[i] <= time_bankB:
        time_bankB -= time_B[i]
        num_books += 1
        read_in_B.append(time_B[i])
    else:
        baf_timeB = time_bankB
if baf_timeB == 0:
    baf_timeB = K - sum(time_B)
max_books = num_books
tmp = max_books


for i in range(len(time_A)):
    dif = 1
    allot_to_A += time_A[i]
    allot_to_B -= time_A[i]
    if allot_to_B < 0:
        break
    time_to_reduce = time_A[i]
    while time_to_reduce > 0:
        if time_to_reduce <= baf_timeB:
            baf_timeB -= time_to_reduce
            break
        else:
            baf_timeB += read_in_B[-1]
            dif -= 1
            del read_in_B[-1]
    tmp += dif
    max_books = max(tmp, max_books)

print(max_books)

### 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)
# -*- coding: utf-8 -*-
# input
b = int(input())
a = []
for i in range(9):
    for j in range(9):
        a.append((i+1)*(j+1))

if b in set(a)
    print('Yes')
else:
    print('No')

### FIXED CODE ###

# -*- coding: utf-8 -*-
# input
b = int(input())
a = []
for i in range(9):
    for j in range(9):
        a.append((i+1)*(j+1))

if b in set(a):
    print('Yes')
else:
    print('No')
a

### FIXED CODE ###

x1, y1, x2, y2 = map(int, input().split())

X = x2 - x1
Y = y2 - y1

print((x2-Y),(y2 + X),(x1-Y),(y1 + X))
n = int(input())
A = [int(i) for i in input().split()]
def partition(p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1

q = partition(0, n - 1);
print(*A[:q], "[" + str(A[q]) + "]", end="")
if len(A[q + 1:]) > 0:
    print("", *A[q + 1:])

### FIXED CODE ###

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1
n = int(input())
A = list(map(int, input().split()))
p = partition(A, 0, n - 1)
A[p] = f"[{A[p]}]"
print(*A)
N,K=int(input().split())
ans=K
for i in range(N-1):
  ans*=(K-1)
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
ans=K
for i in range(N-1):
  ans*=(K-1)
print(ans)