Harryxun/stf_run huggingface dataset:
/// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
    use std::fs::File;
    use std::io::Read;
    let mut s = String::new();
    match option_env!("LOCAL") {
        Some(_) => File::open("src/_in.txt")
            .expect("File not found")
            .read_to_string(&mut s)
            .unwrap(),
        None => std::io::stdin().read_to_string(&mut s).unwrap(),
    };
    s
}

fn main() {
    let s = read_input();
    let mut ws = s.split_whitespace();
    let in_n: i32 = ws.next().unwrap().parse().unwrap();
    let mut txy: Vec<(i32, i32, i32)> = (0..in_n)
        .map(|_| {
            let t: i32 = ws.next().unwrap().parse().unwrap();
            let x: i32 = ws.next().unwrap().parse().unwrap();
            let y: i32 = ws.next().unwrap().parse().unwrap();
            (t, x, y)
        })
        .collect();
    txy.insert(0, (0, 0, 0));

    let mut ok = true;
    for window in txy.windows(2) {
        let ((t1, x1, y1), (t2, x2, y2)) = (window[0], window[1]);
        let dt = t2 - t1;
        let d = (x1 - x2).abs() + (y1 - y2).abs();
        ok &= dt >= d && (dt - d) % 2 == 0
    }
    println!("{}", if ok { "Yes" } else { "No" });
}


### FIXED CODE ###

import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
T, X, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

t, x, y = 0, 0, 0
ok = True
for i in range(N):
    dt = T[i] - t
    d = abs(x - X[i]) + abs(y - Y[i])
    if not (dt >= d and (dt - d) % 2 == 0):
        ok = False
    t = T[i]
    x = X[i]
    y = Y[i]
if ok:
    print('Yes')
else:
    print('No')
import sys
sys.setrecursionlimit(10**6)

from collections import deque
from itertools import chain

def bfs(maze,visited,gy,gx):
    que = deque([[1,1]])
    visited[1][1] = 0
    
    while que:
        y,x = que.popleft()
        if [y,x] == [gy,gx]:
            return visited[y][x]
        for j,k in ([1,0],[-1,0],[0,1],[0,-1]):
            ny,nx = y+j,x+k
            if maze[ny][nx] == "." and visited[ny][nx] == -1:
                visited[ny][nx] = visited[y][x] + 1
                que.append([ny,nx])

h,w = map(int,input().split())
maze = ["#"*(w+2)] + ["#"+input()+"#" for _ in range(h)] + ["#"*(w+2)]
visited = [[-1]*(w+2) for _ in range(h+2)]
sr = bfs(maze,visited,h,w)

num_dot = list(chain.from_iterable(maze))
num_dot = num_dot.count('.')
num_sharp = h*w - num_dot
print(h*w - num_sharp - sr - 1)

### FIXED CODE ###

from collections import deque

def bfs(maze,visited,sy,sx,gy,gx):
    Step = ([1,0],[0,1],[-1,0],[0,-1])
    
    que = deque([[sx,sy]])
    visited[sx][sy] = 1
    
    while que:
        y,x = que.popleft()
        if [y,x] == [gy,gx]:
            return visited[y][x]
        for j,k in Step:
            ny,nx = y+j , x+k
            if 0 <= ny <= gy and 0 <= nx <= gx:
                if maze[ny][nx] == '.' and visited[ny][nx] == INF:
                    visited[ny][nx] = visited[y][x] + 1
                    que.append([ny,nx])


h,w = map(int,input().split())
maze = [input().strip() for _ in range(h)]

cntSharp = 0
for i in range(h):
    cntSharp += maze[i].count('.')

INF = 10**5
visited = [[INF]*w for _ in range(h)]

sx,sy = 0,0
gy,gx = h-1,w-1

minStep = bfs(maze,visited,sy,sx,gy,gx)
print(cntSharp - minStep if visited[gy][gx] != INF else -1)
x = input()
y = input()

a = x*y
b = 2*x+2*y

print a 
print b

### FIXED CODE ###

x,y = map(int,raw_input().split())

a = x*y
b = 2*x+2*y

print a,b
a,p=map(int,inputy().split())
a=3*p
print((a+p)//2)


### FIXED CODE ###

a,p=map(int,input().split())
print((3*a+p)//2)
n=int(input())
x=[]
for i in range(n):
    a,b=map(int,input().split())
    x.append([a,b])

                

d=[]
discount=[]
for i in range(n):
    for j in range(n):
        if i!=j:

            tmp=[x[i][0]-x[j][0],x[i][1]-x[j][1]]

            if tmp not in d:
                d.append(tmp)
                discount.append(1)
            else:
                discount[d.index(tmp)]+=1
                
print(n-max(discount))
                
                

### FIXED CODE ###

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

                

d=[]
discount=[]
for i in range(n):
    for j in range(n):
        if i!=j:

            tmp=[x[i][0]-x[j][0],x[i][1]-x[j][1]]

            if tmp not in d:
                d.append(tmp)
                discount.append(1)
            else:
                discount[d.index(tmp)]+=1
     
    
if n==1:
    print(1)
else:
    print(n-max(discount))
x = int(input())
answer = 0
while x >= 10:
    answer += x%10
    x = int(x/10)
answer += x
if answer % 9 == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = int(input())
nst = str(n)
keta= len(nst)
answer = 0
for i in range(keta):
    answer += int(nst[i])
if answer % 9 == 0:
    print('Yes')
else:
    print('No')
K = int(input())
S = input()
if len(S) =< int(K):
 print(S)
else:
 print(S[:int(K)+1]+'...')


### FIXED CODE ###

K = int(input())
S = input()
if len(S) <= K:
 print(S)
else:
 print(S[:K] + '...')
N = int(input())

X = []
Y = []
h = []
for i in range(N):
    a,b,c = map(int,input().split())

    X.append(a)
    Y.append(b)
    h.append(c)

for Cx in range(101):
    p = False
    for Cy in range(101):
        w = True
        previous = None
        for i in range(0,N):
            H = h[i] + abs(X[i] - Cx) + abs(Y[i] - Cy)
            if H - abs(X[i] - Cx) - abs(Y[i] - Cy) >= 0:
                if not previous:
                    previous = H
                elif H != previous or H < 1:
                    w = False
                    break
        
        if w:
            answer = [Cx,Cy,H]
            p = True
            break

    if p:
        break

print(answer[0],answer[1],answer[2])

### FIXED CODE ###

N = int(input())

X = []
Y = []
h = []
for i in range(N):
    a,b,c = map(int,input().split())

    if c > 0:
        p = i
    X.append(a)
    Y.append(b)
    h.append(c)

for Cx in range(101):
    for Cy in range(101):
        works = True
        H = h[p] + abs(X[p] - Cx) + abs(Y[p] - Cy)
        for i in range(N):
            if h[i] != max(H - abs(X[i] - Cx) - abs(Y[i] - Cy), 0):
                works = False
                break
        
        if works:
            print(Cx,Cy,H)
            quit()
from itertools import *
from heapq import *

def solve(H, W, grid):
  goal = (H-1, W-1)
  fixed = set()
  candicates = [(grid[0], (0, 0))]
  while 1:
    dist, p = heappop(candicates)
    if p == goal:
      return dist
    if p in fixed:
      continue
    fixed.add(p)
    for i,j in product([1,-1], [0,1]):
      y, x = p[0]+i*j, p[1]+i*(1-j)
      if not (0<=y<H and 0<=x<W) or (y, x) in fixed:
        continue
      heappush(candicates, (dist+(1-grid[p])*grid[W*y+x], (y, x)))
  return None

H, W = map(int, input().split())
grid = list(chain.from_iterable(map([".", "#"].index, input()) for i in range(H)))
print(solve(H, W, grid))

### FIXED CODE ###

from itertools import *
from heapq import *

def solve(H, W, grid):
  goal = (H-1, W-1)
  fixed = set()
  candicates = [(grid[0,0], (0, 0))]
  while 1:
    dist, p = heappop(candicates)
    if p == goal:
      return dist
    if p in fixed:
      continue
    fixed.add(p)
    for i in range(2):
      p1 = p[0]+i, p[1]+(1-i)
      if not (p1[0]<H and p1[1]<W) or p1 in fixed:
        continue
      x, y = p
      x1, y1 = p1
      heappush(candicates, (dist+(grid[p1] & ~grid[p]), p1))
  return None

H, W = map(int, input().split())
grid = {(i,j): int(c=="#") for i in range(H) for j, c in enumerate(input())}

print(solve(H, W, grid))
S = input()

ans = 0
N = 2**(len(S) - 1)

for i in range(N):
    bit = bin(i)[2:]
    if len(bit) != len(S):
        bit = '0'*(len(S)-len(bit) - 1) + bit

    tmp = S[0]
#    print(bit)
    for i,b in enumerate(bit):
        if b == '0':
            tmp += S[i+1]
        else:
            ans += int(tmp)
            tmp  = S[i+1]
#            tmp += '+' + S[i+1]
    if len(tmp) > 0:
        ans += int(tmp)
print(ans)


### FIXED CODE ###

S = input()

ans = 0
N = 2**(len(S) - 1)

if len(S) == 1:
    print(S)
    exit()
for i in range(N):
    bit = bin(i)[2:]
    if len(bit) != len(S):
        bit = '0'*(len(S)-len(bit) - 1) + bit

    tmp = S[0]
#    print(bit)
    for i,b in enumerate(bit):
        if b == '0':
            tmp += S[i+1]
        else:
            ans += int(tmp)
            tmp  = S[i+1]
#            tmp += '+' + S[i+1]
    if len(tmp) > 0:
        ans += int(tmp)
print(ans)
from fractions import gcd
n = int(input())
times = [int(input()) for _ in range(n)]

prev_lcm = times[0]
for t in times[1:]:
    tmp = gcd(prev_lcm, t)
    lcm = int(prev_lcm * t / tmp)
    prev_lcm = lcm
if n == 1:
    print(times[0])
else:
    print(lcm)


### FIXED CODE ###

from fractions import gcd
n = int(input())
times = [int(input()) for _ in range(n)]

if n == 1:
    print(times[0])
else:
    prev_lcm = times[0]
    for t in times[1:]:
        tmp = gcd(prev_lcm, t)
        lcm = prev_lcm * (t // tmp)
        prev_lcm = lcm
    print(lcm)
H, W, D = map(int, input().split())
A = [0] * H * W
for i in range(H):
    temp = list(map(int, input().split()))
    for j in range(len(temp)):
        A[temp[j] - 1] = (i + 1, j + 1)

Q = int(input())
L = []
R = []
for _ in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)


def consumption(point_A, point_B):
    return abs(point_A[0] - point_B[0]) + abs(point_A[1] - point_B[1])


X = []
for i in [D] + list(range(1, D)):
    power = 0
    x = []
    for j in range(int((H * W - i) / D)):
        power += consumption(A[i - 1 + j * D], A[i - 1 + (j + 1) * D])
        x.append(power)
    X.append(x)
for i in range(Q):
    l = int(L[i] / D) - 2
    r = int(R[i] / D) - 2
    print(X[L[i] % D][r] - X[L[i] % D][l])


### FIXED CODE ###

H, W, D = map(int, input().split())
A = [0] * H * W
for i in range(H):
    temp = list(map(int, input().split()))
    for j in range(len(temp)):
        A[temp[j] - 1] = (i + 1, j + 1)

Q = int(input())
L = []
R = []
for _ in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)


def consumption(point_A, point_B):
    return abs(point_A[0] - point_B[0]) + abs(point_A[1] - point_B[1])


X = []
for i in [D] + list(range(1, D)):
    power = 0
    x = [0]
    for j in range(int((H * W - i) / D)):
        power += consumption(A[i - 1 + j * D], A[i - 1 + (j + 1) * D])
        x.append(power)
        #print("{}->{}".format(A[i - 1], A[i - 1 + (j + 1) * D]))
    X.append(x)
# print(X)
for i in range(Q):
    k = L[i] % D
    if k == 0:
        l = int((L[i] - D) / D)
        r = int((R[i] - D) / D)
    else:
        l = int((L[i] - k) / D)
        r = int((R[i] - k) / D)
    #print(X[k], l, r)
    print(X[k][r] - X[k][l])
import bisect
import heapq 

Q=int(input())

que=list(map(int,input().split()))
b=que[2]
l,r=[-que[1]],[que[1]]
heapq.heapify(l)
heapq.heapify(r)
a=0
tmp=que[1]
j=1
for i in range(Q-1):
    que=list(map(int,input().split()))
    if que[0]==1:
        j+=1
        b+=que[2]
        q1=que[1]
        if j%2==0:
            if q1<-l[0]:
                heapq.heappushpop(l,-q1)
            else:
                heapq.heappushpop(r,q1)

        else:
            if q1<-l[0]:
                heapq.heappush(r, -heapq.heappushpop(l,-q1))
            else:
                heapq.heappush(l, -heapq.heappushpop(r,q1))
        
        if -l[0]!=r[0]: a+=abs(tmp-q1)
        else: a+=abs(tmp-q1)-abs(-l[0]-tmp)
        tmp=-l[0]

    elif que[0]==2:
        print(tmp,a+b)

### FIXED CODE ###

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

if A>12: print(B)
elif A>5: print(B//2)
else: print(0)
n, a, b, c = map(int, input().split())
abc = list((a, b, c))
ans = [0] * n
dic = {'A': 0, 'B': 1, 'C': 2}
flag = True
s = [input() for i in range(n)]
for i in range(n):
    if abc[dic[s[i][0]]] == 0 and abc[dic[s[i][1]]] == 0:
        flag = False
        break
    elif sum(abc) == 2 and abc[dic[s[i][0]]] == 1 and abc[dic[s[i][1]]] == 1:
        ps = (set(s[i]) & set(s[i + 1])).pop()
        ms = (set(s[i]) - set(ps)).pop()
        abc[dic[ps]] += 1
        abc[dic[ms]] -= 1
        ans[i] = ps
    elif abc[dic[s[i][0]]] <= abc[dic[s[i][1]]]:
        abc[dic[s[i][0]]] += 1
        abc[dic[s[i][1]]] -= 1
        ans[i] = s[i][0]
    else:
        abc[dic[s[i][0]]] -= 1
        abc[dic[s[i][1]]] += 1
        ans[i] = s[i][1]
if flag:
    print('Yes')
    print(*ans, sep='\n')
else:
    print('No')

### FIXED CODE ###

n, a, b, c = map(int, input().split())
abc = list((a, b, c))
ans = [0] * n
dic = {'A': 0, 'B': 1, 'C': 2}
flag = True
s = [input() for i in range(n)]
for i in range(n):
    if abc[dic[s[i][0]]] == 0 and abc[dic[s[i][1]]] == 0:
        flag = False
        break
    elif sum(abc) == 2 and abc[dic[s[i][0]]] == 1 and abc[dic[s[i][1]]] == 1 and i != n - 1:
        ps = (set(s[i]) & set(s[i + 1])).pop()
        ms = (set(s[i]) - set(ps)).pop()
        abc[dic[ps]] += 1
        abc[dic[ms]] -= 1
        ans[i] = ps
    elif abc[dic[s[i][0]]] <= abc[dic[s[i][1]]]:
        abc[dic[s[i][0]]] += 1
        abc[dic[s[i][1]]] -= 1
        ans[i] = s[i][0]
    else:
        abc[dic[s[i][0]]] -= 1
        abc[dic[s[i][1]]] += 1
        ans[i] = s[i][1]
if flag:
    print('Yes')
    print(*ans, sep='\n')
else:
    print('No')
import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=10,10
#a=[158260522, 877914575, 602436426, 24979445,
#   861648772, 623690081, 433933447, 476190629,
#   262703497, 211047202]

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(1000):
#    print(m,rf(m))
    if rf(m)>(n+k) :
#        print("1:",m,rf(m))
        lm=m
        m=(um+m)//2
    elif rf(m)<(n+k):
#        print("2:",m,rf(m))
        um=m
        m=(lm+m)//2
    elif rf(m)==n+k and rf(m-1)==n+k:
#        print("5:",m,rf(m))
        um=m
        m=(lm+m)//2+1
    elif rf(m)==n+k and rf(m-1)>n+k:
#        print("3:",m,rf(m))
        break
    else:
#        print("4:",m,rf(m))
        m=m-1

print(m)


### FIXED CODE ###

import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)
from heapq import *

n, m, s = map(int, input().split())
tree = [[] for _i in range(n+1)]
for _i in range(m):
    u, v, a, b = map(int, input().split())
    tree[u].append([v, a, b])
    tree[v].append([u, a, b])

cd = [[0,0]]
for _i in range(n):
    cd.append(list(map(int, input().split())))

dp = [[float('inf') for _i in range(50*n+1)] for _j in range(n+1)]
hq = [[0, 1, s]]
dp[1][s] = 0
heapify(hq)
while hq:
    t, p, g = heappop(hq)
    if g+cd[p][0] <= 50*n:
        x, y = t+cd[p][1], min([g+cd[p][0], 50*n])
        if dp[p][y] > x:
            dp[p][y] = x
            heappush(hq, [x, p, y])
    for x, y, z in tree[p]:
        if g-y >= 0 and dp[x][g-y] > t+z:
            dp[x][g-y] = t+z
            heappush(hq, [t+z, x, g-y])

for i in dp[2:]:
    print(min(i))

### FIXED CODE ###

from heapq import *

n, m, s = map(int, input().split())
s = min([s, 50*n])
tree = [[] for _i in range(n+1)]
for _i in range(m):
    u, v, a, b = map(int, input().split())
    tree[u].append([v, a, b])
    tree[v].append([u, a, b])

cd = [[0,0]]
for _i in range(n):
    cd.append(list(map(int, input().split())))

dp = [[float('inf') for _i in range(50*n+1)] for _j in range(n+1)]
hq = [[0, 1, s]]
dp[1][s] = 0
heapify(hq)
while hq:
    t, p, g = heappop(hq)
    if g+cd[p][0] <= 50*n:
        x, y = t+cd[p][1], min([g+cd[p][0], 50*n])
        if dp[p][y] > x:
            dp[p][y] = x
            heappush(hq, [x, p, y])
    for x, y, z in tree[p]:
        if g-y >= 0 and dp[x][g-y] > t+z:
            dp[x][g-y] = t+z
            heappush(hq, [t+z, x, g-y])

for i in dp[2:]:
    print(min(i))
maps = {'1':'a',
       '2':'b',
       '3':'c',
       '4':'d',
       '5':'e',
       '6':'f',
       '7':'g',
       '8':'h',
       '9':'i',
       '10':'j',
       '11':'k',
       '12':'l',
       '13':'m',
       '14':'n',
       '15':'o',
       '16':'p',
       '17':'q',
       '18':'r',
       '19':'s',
       '20':'t',
       '21':'u',
       '22':'v',
       '23':'w',
       '24':'x',
       '25':'y',
       '26':'z',
       }
n = int(input())
s=''
while True:
  s = maps[str(n%26)] + s
  n //= 26
  if n < 26:
    break
print(s)

### FIXED CODE ###

n = int(input())
s=''
while n!=0:
  n-=1
  tmp=n%26
  s=chr(96+tmp+1)+s
  n//=26
print(s)
M=10**9+7
f=input
n,m=map(int,f().split())
s,t,u=0,1,int(f())
for i in range(n):
  if i==u-1:
    s,t=t,0
    try: u=int(f())
    except: pass
  else: s,t=t,(s+t)%M
print(t)

### FIXED CODE ###

mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 0
t1 = 1

for i in range(1,n+1):
  if l == [] or i != l[0]:
    t0 = (t2+t1)%mod
  else:
    l.pop(0)
    t0 = 0
  t2 = t1
  t1 = t0

print(t0)
import sys
sys.setrecursionlimit(1000000)

ma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]
N, M = (int(i) for i in input().split())
ma = list(int(i) for i in input().split())
memo = [-1] * 100000

def dfs(num):
	if memo[num] != -1: return memo[num]
	if num == 0: return 0

	ret = -1
	for p in ma:
		if 0 <= num - ma_map[p]:
			d = dfs(num - ma_map[p])
			if d == -1: continue
			ret = max(dfs(num - ma_map[p]) * 10 + p, ret)

	memo[num] = ret
	return ret

print(ma_map[2])
ma.sort()
println("{}".format(dfs(N)))

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

ma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]
N, M = (int(i) for i in input().split())
ma = list(int(i) for i in input().split())
memo = [-1] * 100000

def dfs(num):
	if memo[num] != -1: return memo[num]
	if num == 0: return 0

	ret = -1
	for p in ma:
		if 0 <= num - ma_map[p]:
			d = dfs(num - ma_map[p])
			if d == -1: continue
			ret = max(dfs(num - ma_map[p]) * 10 + p, ret)

	memo[num] = ret
	return ret

ma.sort()
print("{}".format(dfs(N)))
def kaijo(N):
    if N == 1:
        return 1
    else:
        return N * kaijo(N-1)

if __name__ == '__main__':
    n = int(input().strip())
    print(kaijo(n) % (10**9 + 7))

### FIXED CODE ###

def process(N):
    ans = 1
    while N > 1:
        ans = ans * N % (10**9 + 7)
        N -= 1
    return ans

if __name__ == '__main__':
    n = int(input().strip())
    print(process(n))
import math
n = int(input())
la = [int(i) for i in input().split()]
ans = 1
for a in la:
    ans *= a

if(math.log10(ans) > 18):
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import math
n = int(input())
la = [int(i) for i in input().split()]
la.sort(reverse=True)
ans = 1

if la[-1] == 0:
    print(0)
    exit()

for a in la:
    if a > 1000000000000000000:
        print(-1)
        exit()
    ans *= a
    if ans > 1000000000000000000:
        print(-1)
        exit()
print(ans)
n, m, k=map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

acum1=[0]

#それぞれの累積和(ai, bj)をもとめる
for i in range(n):
	# accum[-1]で一番最後のリストの値を参照している
    # うしろからみている
	acum1.append(acum[-1]+arr1[i])
    
acum2 = [0]

for i in range(m):
	# accum[-1]で一番最後のリストの値を参照している
    # うしろからみている
	acum2.append(acum2[-1]+arr2[i])

ans = 0
for i in range(n+1):
	# ai > K ->どのようにjを選んでもai+bj<=Kとなることはない
    # 探索を終了する
	if acum1[i] > k:
    	break
    #各iについて、bj<=K-aiを満たす最大のjを求める
    #bj>K-aiの間、ループ。jを大きい方から順に調べていく
    #限界ギリギリを調べるのだから、後ろから調べた方がよいという感じかな
    while acum2[j]>k - acum1[i] and j>0:
    	j -= 1
        ans = max(ans, i+j)
print(ans)

### FIXED CODE ###

n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n): #累積和ai,bjを求める
 acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
 acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
 if acum1[i]>k: #ai>Kであれば、どのようにjを選んでもai+bj<=Kとなることはないので探索を終了する
   break
 while acum2[j]>k-acum1[i] and j>0: #各iについて、bj<=K-aiを満たす最大のjを求める
   j-=1
 ans=max(ans,i+j)
print(ans)
# ABC096B - Maximum Sum
a, b, c = sorted(list(map(int, input().rstrip().split())), reverse=True)
k = int(input())
if k == 1:
    print(a * 2 + b + c)
else:
    for i in range(1, k + 1):
        A = a * 2 + b + c
        B = a + b * 2 ++ c
        C = a + b + c * 2
        if max(A, B, C) == A:
            a *= 2
        elif max(A, B, C) == B:
            b *= 2
        else:
            c *= 2
	print(a + b + c)

### FIXED CODE ###

# ABC096B - Maximum Sum
a, b, c = sorted(list(map(int, input().rstrip().split())), reverse=True)
k = int(input())
if k == 1:
    print(a * 2 + b + c)
else:
    for i in range(1, k + 1):
        A = a * 2 + b + c
        B = a + b * 2 ++ c
        C = a + b + c * 2
        if max(A, B, C) == A:
            a *= 2
        elif max(A, B, C) == B:
            b *= 2
        else:
            c *= 2
    print(a + b + c)
count=input()
list=int(input()).rstrip().split(" ")
list2= sorted(list)
sa=(int(list2[0])-int(list2[int(count)-1]))
if sa<0:
  print(-1*int(sa))
else:
  print(int(sa))

### FIXED CODE ###

count=input()
list=input().rstrip().split(" ")
list_1=[int(s) for s in list]
list2= sorted(list_1)
sa=(int(list2[0])-int(list2[int(count)-1]))
if sa<0:
  print(-1*int(sa))
else:
  print(int(sa))
x,a,b=[int(input()) for i range(3)]
c=int(x-a)
print(c%b)

### FIXED CODE ###

x,a,b=[int(input()) for i in range(3)]
c=x-a
print(c%b)
import math 
A, B, H, M = map(int,input().split())

timeHr = H + (M / 60)
angVelA = (1/6) * 180
angVelB = (2) * 180

degA = (angVelA * timeHr)
degB = (angVelB * timeHr) 

defDiff = math.radians(abs(degB - degA))

disX_2 = math.pow(B, 2) + math.pow(A, 2) - (2 * A * B * math.cos(degDiff))
disX = math.sqrt(disX_2)

print(disX)

### FIXED CODE ###

import math 
A, B, H, M = map(int,input().split())

timeHr = H + (M / 60)
angVelA = (1/6) * 180
angVelB = (2) * 180

degA = (angVelA * timeHr)
degB = (angVelB * timeHr) 

degDiff = math.radians(abs(degB - degA))

disX_2 = math.pow(B, 2) + math.pow(A, 2) - (2 * A * B * math.cos(degDiff))
disX = math.sqrt(disX_2)

print(disX)
# coding: utf-8
# Your code here!

import pandas as pd

k, s = map(int, input().split())

lst = [i for i in range(k+1)]



ans = 0
ans = s_bool.sum()

print(ans)











### FIXED CODE ###

# coding: utf-8
# Your code here!

k, s = map(int, input().split())

cnt = 0

for i in range(k+1):
    for j in range(k+1):
        if s-i-j <= k and s-i-j>=0:
            cnt += 1

print(cnt)