Harryxun/stf_run huggingface dataset:
ARC098 - Attention
 
Shoji Taisaku(FJK 庄司 大作)
2020/03/11 (水) 11:33
受信トレイ; 送信済みトレイ
宛先:
Shoji Taisaku(FJK 庄司 大作);
N=int(input())
S=input()

left=[0]*N
right=[0]*N
to_change=[0]*N

if S[0]=="E":
    right[0]=1
else:
    left[0]=1

for i in range(1,N):
    if S[i]=="W":
        left[i] = left[i-1]+1
        right[i] = right[i-1]
    if S[i]=="E":
        right[i] = right[i-1]+1
        left[i]= left[i-1]

to_change[0]=right[-1]-right[0]
to_change[-1]=left[-2]

for j in range(1,N-1):
    to_change[j]=(right[-1]-right[j])+(left[j-1])
#print(to_change)
print(min(to_change))

### FIXED CODE ###

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

left=[0]*N
right=[0]*N
to_change=[0]*N

if S[0]=="E":
    right[0]=1
else:
    left[0]=1

for i in range(1,N):
    if S[i]=="W":
        left[i] = left[i-1]+1
        right[i] = right[i-1]
    if S[i]=="E":
        right[i] = right[i-1]+1
        left[i]= left[i-1]

to_change[0]=right[-1]-right[0]
to_change[-1]=left[-2]

for j in range(1,N-1):
    to_change[j]=(right[-1]-right[j])+(left[j-1])
#print(to_change)
print(min(to_change))
a = [int(input()) for i in range(6)]

# アンテナと距離に分ける
i = [a[0], a[1], a[2], a[3], a[4]]
k = a[5]

flag = False
itr = 0
while True:
  x = itr
  while True:
    x++
    if 
      break
    else if(i[itr] - i[x]) > k:
      flag = True
  itr++
  if itr == 5
    break
    
if flag
  print(":(")
else
  print("Yay!")

### FIXED CODE ###

a = [int(input()) for i in range(6)]

# アンテナと距離に分ける
i = [a[0], a[1], a[2], a[3], a[4]]
k = a[5]

flag = False
itr = 0
while True:
  x = itr
  while True:
    x+=1
    if x >= 5:
      break
    elif(i[x] - i[itr]) > k:
      flag = True
  itr+=1
  if itr == 5:
    break
    
if flag:
  print(":(")
else:
  print("Yay!")
入力
入力は以下の形式で標準入力から与えられる。
K
AB
出力
目標の達成が可能であれば OK と、不可能であれば NG と出力せよ。
k= int(input())
s= input().rsprit().split()
a = int(s[0])
b = int(s[1])
f = "NG"
for i in range(a,b):
	if i%k == 0:
  		f = "OK"
print(f)

### FIXED CODE ###

k= int(input())
s= input().rstrip().split()
a = int(s[0])
b = int(s[1])
f = "NG"
for i in range(a,b+1):
  if i%k == 0:
    f = "OK"
if a == b:
  if a%k == 0:
    f = "OK"
print(f)
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N, X = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]

numbers.append(X)
numbers = sorted(numbers)

diff_numbers = []

for i in range(len(numbers)-1):
    diff_numbers.append(abs(numbers[i] - numbers[i+1]))

gcd = gcd_list(diff_numbers)

print(gcd)

### FIXED CODE ###

import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N, X = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]

numbers.append(X)
numbers = sorted(numbers)

diff_numbers = []

for i in range(len(numbers)-1):
    diff_numbers.append(abs(numbers[i] - numbers[i+1]))

gcd_num = gcd_list(diff_numbers)

print(gcd_num)
N = int(input())
arare = input().split()
y = 0
for i in arare:
  if arare[i] == "Y":
    y += 1
    break
if y == 1:
  print("Four")
else:
  print("Three")


### FIXED CODE ###

N = int(input())
arare = input().split()
y = 0
for i in range(len(arare)):
  if arare[i] == "Y":
    y += 1
    break
if y == 1:
  print("Four")
else:
  print("Three")
N = input()
M = list(map(int,input().split()))
    
mult = 1

if 0 in A:
  print(0)
  
for a in M:
    mult *= a
    if mult> 1000000000000000000:
        print(-1)
        
print(mult)

### FIXED CODE ###

A,B = map(int,input().split())
print(A*B)
def getNumNeg(L):
  return sum([i<0 for i in L])
  
def findmax2(L):
  numNeg = getNumNeg(L)
  absL = list(map(abs, L))
  if numNeg % 2 == 0:
    print(sum(absL))
  else:
    print(sum(absL)-min(absL))
        
n = int(input())
a = list(map(abs, input().split()))
findmax2(a)


### FIXED CODE ###

def getNumNeg(L):
  return sum([i<0 for i in L])
  
def findmax2(L):
  numNeg = getNumNeg(L)
  absL = list(map(abs, L))
  if numNeg % 2 == 0:
    print(sum(absL))
  else:
    print(sum(absL)-2*min(absL))
        
n = int(input())
a = list(map(int, input().split()))
findmax2(a)
S = input()
S[:4] = "2018"
print(S)


### FIXED CODE ###

S = input()
S = S.replace("2017", "2018")
print(S)
n = int(input())
list_ = [int(input()) for _ in range(n)]

dict_ = dict()
for key in set(list_):
    dict_[key] += dict_.get(key, 0) + 1
print(sum(num % 2 for num in dict_.values()))

### FIXED CODE ###

n = int(input())
list_ = [int(input()) for _ in range(n)]

dict_ = dict()
for key in list_:
    dict_[key] = dict_.get(key, 0) + 1
print(sum(num % 2 for num in dict_.values()))
import numpy as np
X, N = map(int, input().split())
p_list = set([int(i) for i in input().split()])
set_all = set(np.arange(-100, 101))
ex_list = set_all-p_list
ex_list = list(ex_list)
diff_list = [np.abs(i-X) for i in ex_list]
min_index = np.argmin(diff_list)
print(ex_list[min_index])

### FIXED CODE ###

import numpy
input_x = [int(i) for i in input().split(" ")]
for i in range(5):
    if not i+1 in input_x:
        print(i+1)
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
cd=[tuple(map(int,input().split())) for i in range(m)]
for a,b in ab:
    tmp=inf
    candi=0
    for j in range(n):
        c=cd[j][0]
        d=cd[j][1]
        k=abs(a-c)+abs(b-d)
        if tmp>k:
            tmp=k
            candi=j
    print(candi+1)
    



### FIXED CODE ###

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
cd=[tuple(map(int,input().split())) for i in range(m)]
for a,b in ab:
    tmp=inf
    candi=0
    for j in range(m):
        c=cd[j][0]
        d=cd[j][1]
        k=abs(a-c)+abs(b-d)
        if tmp>k:
            tmp=k
            candi=j
    print(candi+1)
N,M=map(int,input().split())

parent=[i for i in range(N)]
depth=[0 for i in range(N)]

def root(x):
  if parent[x]==x:
    return x
  else:
    return root(parent[x])

def same(x,y):
  return root(x)==root(y)

def unite(x,y):
  rx=root(x)
  ry=root(y)
  if rx==ry:
    return
  if depth[x]<depth[y]:
    parent[rx]=ry
  else:
    parent[ry]=rx
    if depth[x]==depth[y]:
      depth[x]+=1
      
for i in range(M):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  unite(a,b)
  
roots=set()
for i in range(N):
  roots.add(root(i))

print(len(roots)-1)

### FIXED CODE ###

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

parent=[i for i in range(n)]
rank=[0 for i in range(n)]

def find(a):
  if parent[a]==a:
    return a
  else:
    return find(parent[a])

def union(a,b):
  ar=find(a)
  br=find(b)
  if ar==br:
    return
  if rank[a]>rank[b]:
    parent[br]=ar
  else:
    parent[ar]=br
    if rank[a]==rank[b]:
      rank[a]+=1
      
def same(a,b):
  ar=find(a)
  br=find(b)
  return ar==br

q=[None]*m

for i in range(m):
  x,y,z=map(int,input().split())
  q[i]=[x-1,y-1]

for i in range(len(q)):
  union(q[i][0],q[i][1])
  
roots=[0]*len(parent)
for i in range(len(parent)):
  roots[i]=find(i)

print(len(set(roots)))
n=int(input())%10
if n=3:
  print('bon')
elif n in [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')
return a + a ** a + a ** a ** a

### FIXED CODE ###

a = int(input())
b = a + a ** 2 + a ** 3
print(b)
import itertools
import sys


c = list(itertools.product(range(10), repeat=4))

if __name__ == '__main__':
    for n in sys.stdin.readlines():
        print sum([l for l in c if int(n) == sum(l)])

### FIXED CODE ###

import sys


for n in sys.stdin:
    ret = 0
    for a in xrange(10):
        for b in xrange(10):
            for c in xrange(10):
                for d in xrange(10):
                    if a+b+c+d == int(n):
                        ret += 1
    print ret
n,k = map(int(),input().split())
print((n+k-3)/(k-1))


### FIXED CODE ###

import math
n,k = map(int,input().split())
print(math.floor((n+k-3)/(k-1)))
import math

N = int(input())
A = list(map(int, input().split()))
digit = math.floor(math.log2(max(A))) + 1

ans = 0
fil = 1
for i in range(digit):
    num1 = len([1 for j in range(N) if A[j] & fil])
    num0 = N - num1
    ans += (num1 * num0) * fil
    fil <<= 1

print(ans % (10 ** 9 + 7))

### FIXED CODE ###

import math

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

ans = 0
fil = 1
for i in range(60):
    num1 = len([1 for j in range(N) if A[j] & fil])
    num0 = N - num1
    ans += (num1 * num0) * fil
    fil <<= 1

print(ans % (10 ** 9 + 7))
s=input()

s[5]=' '
s[13]=' '

print(s)

### FIXED CODE ###

s=input()

print(s.replace(',',' '))
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
x,y=input().split()
if x,y is in a or x,y is in b:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
x,y=map(int,input().split())
if x in a and y in a:
  print("Yes")
elif x in b and y in b:
  print("Yes")
else:
  print("No")
i = lambda: list(map(int, input().split()))
N, = i()
M = [i() for j in range(N)]
H = 0
for k in range(101):
    if M[i][2] != 0:
        H = abs(M[0][0] - Cx) + abs(M[0][1] - Cy) + M[0][2]
        break
for Cx in range(101):
    for Cy in range(101):
        if all([False for d in M if H != abs(d[0] - Cx) + abs(d[1] - Cy) + d[2]]):
            print(Cx, Cy, H)

### FIXED CODE ###

i = lambda: list(map(int, input().split()))
N, = i()
M = [i() for j in range(N)]
k = -1
for k in range(len(M)):
    if M[k][2] > 0:
        break
for Cx in range(101):
    for Cy in range(101):
        H = abs(M[k][0] - Cx) + abs(M[k][1] - Cy) + M[k][2]
        if all([False for d in M if d[2] != max(H - abs(d[0] - Cx) - abs(d[1] - Cy), 0)]):
            print(Cx, Cy, H)
            break
mod = 10**9+7
n = int(input())
fish = {}
rish = {}
att = 0
for _ in range(n):
  a,b = map(int,input().split())
  if a*b != 0:
    try:
      fish[a/b] += 1
    except:
      fish[a/b] = 1
    rish[-b/a] = 1
  elif a == 0 and b == 0:
    att += 1
  elif a == 0:
    try:
      fish[0] = 1
    except:
      fish[0] = 1
    rish[10**20] = 1
  else:
    try:
      fish[10**20] = 1
    except:
      fish[10**20] = 1
    rish[0] = 1
#print(fish)
#print(rish)
double = [1]
for _ in range(3*10**5):
  double.append(double[-1]*2%mod)
ans = 1
for x in fish:
  if not fish[x]:
    #print('#',x)
    continue
  if x in rish:
    ans *= double[fish[x]] + double[fish[-1/x]] - 1
    ans %= mod
    fish[x] = 0
    fish[-1/x] = 0
  else:
    ans *= double[fish[x]]
    ans %= mod
  #print(ans)
ans = ans-1+att
ans %= mod
print(ans)

### FIXED CODE ###

mod = 10**9+7
n = int(input())
inf = 10**20
fish = {}
rish = {}
att = 0
raw = []
raz = []
def lon(a,b,p):
  return p*10**40 + a*10**20 + b
def rev(z):
  p,a,b = z//(10**40),(z//(10**20))%(10**20),z%(10**20)
  return lon(b,a,1-p)
for _ in range(n):
  a,b = map(int,input().split())
  r = 1
  if a*b == 0:
    if a == b == 0:
      att += 1
    elif a == 0:
      raw.append(lon(0,1,1))
      raz.append(lon(1,0,0))
      fish[lon(0,1,1)] = [0,0]
      fish[lon(1,0,0)] = [0,0]
    else:
      raw.append(lon(1,0,0))
      raz.append(lon(0,1,1))
      fish[lon(1,0,0)] = [0,0]
      fish[lon(0,1,1)] = [0,0]
    continue
  if a*b < 0:
    r = 0
  a = abs(a)
  b = abs(b)
  big = int(a)
  sml = int(b)
  while sml != 0:
    big,sml = sml,big%sml
  a //= big
  b //= big
  raw.append(lon(a,b,r))
  raz.append(lon(b,a,1-r))
  fish[lon(a,b,r)] = [0,0]
  fish[lon(b,a,1-r)] = [0,0]
for x in raw:
  fish[x][0] += 1
for x in raz:
  fish[x][1] += 1
double = [1]
for _ in range(3*10**5):
  double.append(double[-1]*2%mod)
ans = 1
#print(fish)
for x in fish:
  re = rev(x)
  #print(x,fish[x][0],fish[x][1])
  #print(re)
  ans *= double[fish[x][0]] + double[fish[x][1]] - 1
  ans %= mod
  fish[x] = [0,0]
  fish[re] = [0,0]
ans -= 1
ans += att
ans %= mod
print(ans)
n=int(input())
i=0
while 1:
  if 2**i>n:break
  i+=1
print(2**(i-1))

### FIXED CODE ###

s=input();print(s[0]+str(len(s)-2)+s[-1])
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    
	INF = 999999999999999999999999
	MOD = 10**9+7

	n = int(input())

	ans = 0
	for i in range(1, n+1):
	    for j in range(i, n+1, i):
    	    ans += j

	print(ans)
main()

### FIXED CODE ###

import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

n = int(input())

# factors = [1] * (n+1)

ans = 0
for i in range(1, n+1):
    for j in range(i, n+1, i):
        ans += j

print(ans)
from collections import Counter
N, K = map(int,input().split())
A = list(map(int,input().split()))
i = k = 0
B = [1]
while k <= N or k <= K:
    i = A[i] - 1
    B.append(i + 1)
    k += 1
S = Counter(B)
idx = S.most_common(1)[0][0]
i = k = cnt = 0
while k < 10 ** 6:
    if B[k] == idx and cnt == 1:
        k_s = k
        break
    elif B[k] == idx:
        k_f = k
    k += 1
if k_s:
    k_max = K % (k_s - k_f)
else:
    k_max = K
i = k = 0
while k < k_max:
    i = A[i] - 1
    k += 1
print(i + 1)   

### FIXED CODE ###

from collections import Counter
N, K = map(int,input().split())
A = list(map(int,input().split()))
i = k = 0
B = [1]
while k <= 10 ** 6:
    i = A[i] - 1
    B.append(i + 1)
    k += 1
S = Counter(B)
idx = S.most_common(1)[0][0]
i = k = cnt = 0
k_s = None
while k < 10 ** 6:
    if B[k] == idx and cnt == 1:
        k_s = k
        break
    elif B[k] == idx:
        k_f = k
        cnt += 1
    k += 1
if k_s and k_s < K:
    k_max = (K - B.index(idx)) % (k_s - k_f) + B.index(idx)
else:
    k_max = K
i = k = 0
while k < k_max:
    i = A[i] - 1
    k += 1
print(i + 1)
#
# AIZU ONLINE JUDGE: Digit Number
# cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002&lang=jp
#


import sys
import re


file = open(sys.argv[1], "r")

for line in file:
    ab = map((lambda x: int(x)), re.split(" +", line))
    answer = reduce((lambda x, y: x + y), ab, 0)
    digits = len(str(answer))
    print digits

file.close()

### FIXED CODE ###

#
# AIZU ONLINE JUDGE: Digit Number
# cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002&lang=jp
#


import sys
import re


#file = open(sys.argv[1], "r")

for line in sys.stdin:
    ab = map(int, re.split(" +", line))
    answer = reduce((lambda x, y: x + y), ab, 0)
    digits = len(str(answer))
    print digits
N, M = map(int, input().split())
a = [0]*M
for i in range(M):
    a[i] = int(input())

now = 0
ans = 1
j = 0
for i in range(M):
    if now == a[i] - 1:
       now = a[i] + 1 
    elif now == a[i]:
        ans = 0
        break
    else:
        j = (a[i] - 1) - now
        k1 = 0
        k2 = 1
        k3 = 1
        for n in range(j):
            k3 = k2
            k2 += k1
            k1 = k3
        ans *= k2
        now = a[i] + 1

j = N - now
k1 = 0
k2 = 1
k3 = 1
for n in range(j):
    k3 = k2
    k2 += k1
    k1 = k3
ans *= k2
now = a[i] + 1
print(ans % 1000000007)

### FIXED CODE ###

N, M = map(int, input().split())
a = [0]*M
for i in range(M):
    a[i] = int(input())

now = 0
ans = 1
j = 0
for i in range(M):
    if now == a[i] - 1:
       now = a[i] + 1 
    elif now == a[i]:
        ans = 0
        break
    else:
        j = (a[i] - 1) - now
        k1 = 0
        k2 = 1
        k3 = 1
        for n in range(j):
            k3 = k2
            k2 += k1
            k1 = k3
        ans *= k2
        now = a[i] + 1
if ans > 0:
  j = N - now
  k1 = 0
  k2 = 1
  k3 = 1
  for n in range(j):
      k3 = k2
      k2 += k1
      k1 = k3
  ans *= k2
print(ans % 1000000007)
a,s,c=map(input().split())
print(a[0]+s[0]+c[0])

### FIXED CODE ###

a,s,c=input().split()
print(a[0]+s[0]+c[0])
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    if N == 0 or K == 1:
        print(0)
        exit()
    """
    if N < abs(N - K):
        print(N)
        exit()
    """
    print(min(abs(N % (N - K)), abs(N - (N - K) * (N // K + 1))))


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    if N % K == 0:
        print(0)
        exit()

    print(min(N % K, abs(N - K * (N // K + 1))))


if __name__ == '__main__':
    solve()
A_B_K = input()

A = int(A_B_K[0])
B = int(A_B_K[1])
K = int(A_B_K[2])
 
result = K - (A+B)
 
if (result <=0):
  print(0)
else:
  print(result)

### FIXED CODE ###

ABK = input().split()
A = int(ABK[0])
B = int(ABK[1])
K = int(ABK[2])

if (K >= A):
    K -= A
    B -= K
    A = 0

    if (B <= 0):
        B = 0
else:
    A -= K

print(str(A) + " " + str(B))
s = input()
q = int(input())
hanten = True
atm = ""
kts = ""
for i in range(q):
    l = input().split()
    if l[0] == "1":
        hanten = not hanten
    else:
        if l[1] == "1":
            if hanten == True:
                atm = l[2] + atm
            else:
                kts = kts + l[2]
        else:
            if hanten == True:
                kts = kts + l[2]
            else:
                atm = l[2] + atm

ans = atn + s + kts
if hanten == False:
    print(ans[::-1])
else:
    print(ans)

### FIXED CODE ###

s = input()
q = int(input())
hanten = True
atm = ""
kts = ""
for i in range(q):
    l = input().split()
    if l[0] == "1":
        hanten = not hanten
    else:
        if l[1] == "1":
            if hanten:
                atm = l[2] + atm
            else:
                kts = kts + l[2]
        else:
            if hanten:
                kts = kts + l[2]
            else:
                atm = l[2] + atm

ans = atm + s + kts
if hanten == False:
    print(ans[::-1])
else:
    print(ans)
N,M,K=map(int,input().split())
par=[i for i in range(N)]
siz=[1 for i in range(N)]
fri=[0 for i in range(N)]
blo=[0 for i in range(N)]

def find(x):
    if(par[x]==x):
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def union(a,b):
    a=find(a)
    b=find(b)
    if(a==b):
        return 0
    else:
        par[a]=b
        siz[b]+=siz[a]

def size(a):
    return siz[find(a)]

def same(a,b):
    return find(a)==find(b)

ans=[0 for i in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    A,B=A-1,B-1
    union(A,B)
    ans[A]-=1
    ans[B]-=1
for i in range(N):
    ans[i]+=size(i)-1
for i in range(K):
    C,D=map(int,input().split())
    C,D=C-1,D-1
    if(same(C,D)):
        ans[C]-=1
        ans[D]-=1
        
print(*ans)

### FIXED CODE ###

N,M,K=map(int,input().split())
par=[i for i in range(N)]
siz=[1 for _ in range(N)]
rank=[0 for _ in range(N)]

def find(x):
    if(par[x]==x):
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def union(a,b):
    a=find(a)
    b=find(b)
    if(a==b):
        return 0
    else:
        if rank[a]>rank[b]:
            par[b]=a
            siz[a]+=siz[b]
        else:
            par[a]=b
            siz[b]+=siz[a]
            if rank[a]==rank[b]:
                rank[b]+=1
            

def size(a):
    return siz[find(a)]

def same(a,b):
    return find(a)==find(b)

ans=[0 for i in range(N)]
for _ in range(M):
    A,B=map(int,input().split())
    A,B=A-1,B-1
    union(A,B)
    ans[A]-=1
    ans[B]-=1
for i in range(N):
    ans[i]+=size(i)-1
for _ in range(K):
    C,D=map(int,input().split())
    C,D=C-1,D-1
    if(same(C,D)):
        ans[C]-=1
        ans[D]-=1
        
print(*ans)
K = int(input())

X = 10
ans = 1

if 
while ans <= 9000000:
    x = X%(9*K)
    if x == 1:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 

if x != 1:
    print(-1) 

### FIXED CODE ###

K = int(input())

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if x != 0:
    print(-1)
n = int(input())

if n/9 == n//9:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n = int(input())

if n%9 ==0:
    print("Yes")
else:
    print("No")
import math

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

print(math.ceil(a[0]/a[1]) * math[2])

### FIXED CODE ###

import math

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

print(math.ceil(a[0] / a[1]) * a[2])
import sys
import time

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

queue = {}

start = -1
count = 1

now_town = 1

for i in range(N):
    if town_list[now_town - 1] in queue:
        start = town_list[now_town - 1]
        break
    queue[town_list[now_town - 1]] = count
    now_town = town_list[now_town - 1]
    count += 1

if start == -1:
    print(queue[now_town])
    sys.exit()

before_len = len(queue) - queue[start] - 1
roop = len(queue) - before_len

print(list(queue.keys())[(K - before_len) % roop + before_len - 1])


### FIXED CODE ###

import sys
import time

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

queue = {}

start = -1
count = 1

now_town = 1

for i in range(K):
    if town_list[now_town - 1] in queue:
        start = town_list[now_town - 1]
        break
    queue[town_list[now_town - 1]] = count
    now_town = town_list[now_town - 1]
    count += 1

if start == -1:
    print(now_town)
    sys.exit()

roop = len(queue) - (queue[start] - 1)
before_len = queue[start]

print(list(queue.keys())[(K - before_len) % roop + before_len - 1])
n = int(input())
a = list(map(int,input().split()))
ans = 0
b = []

for i in range(n):
    for j in range(i+1,n+1):
        b = a[i:j]
#        print(b)

        if sum(b) == 0:
            ans += 1

print(ans)


### FIXED CODE ###


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

num = 0
count = 0

for i in range(n):
    if a[i] % 2 == 0:
        count += 1

if count == n:
    if p == 0:
        print(2**n)
    elif p == 1:
        print(0)
else:
    print(2**(n-1))
def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    a = list(map(int, lines[1].strip().split(' ')))
    b = list(map(int, lines[2].strip().split(' ')))
    c_max = 0
    c = 0
    s = 0
    for q in b:
        s += q
        if s > k:
            break
        c += 1
    c_max = max(c, c_max)
    s = 0
    c = 0
    for p in a:
        s += p
        c += 1
        if s > k:
            break
        sb = s
        cb = c
        for q in b:
            sb += q
            if sb > k:
                break
            cb += 1
        c_max = max(cb, c_max)


    print(c_max)
    
resolve()

### FIXED CODE ###

import sys

def resolve():
    lines = sys.stdin.readlines()

    n, m, k = tuple(map(int, lines[0].strip().split(' ')))
    A = list(map(int, lines[1].strip().split(' ')))
    B = list(map(int, lines[2].strip().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])

    res = 0
    j = m
    for i in range(n+1):
        if a[i] > k:
            break
        while a[i] + b[j] > k:
            j -= 1
        res = max(res, i+j)
    print(res)

resolve()