Harryxun/stf_run huggingface dataset:
h, w, k = map(int, input().split())
grid = [[int(v) for v in input()] for _ in range(h)]


def count_ones(i):
    cnt = 0
    while i:
        if i & 1:
            cnt += 1
        i >>= 1
    return cnt

ans = h + w

for state in range(1 << (h - 1)):
    j = 0
    vcnt = 0
    counters = [0] * h
    is_ok = True
    while j < w:
        hi = 0
        i = 0
        local_counters = [0] * h
        while i < h:
            if (1 << i) & state:
                hi = i + 1
            local_counters[hi] += grid[i][j]
            i += 1
        for i, v in enumerate(local_counters):
            if v > k:
                is_ok = False
                break
            counters[i] += local_counters[i]
        if not is_ok:
            break
        if max(counters) > k:
            counters = local_counters.copy()
            vcnt += 1

        j += 1


    if is_ok and ans > count_ones(state) + vcnt:
        ans = count_ones(state) + vcnt
print(ans)



### FIXED CODE ###

import sys
def ass(v):
    if not v:
        print(-1)
        sys.exit(0)

h, w, k = map(int, input().split())
grid = [[1 if v == '1' else 0 for v in input()] for _ in range(h)]


ass(h > 0 and w > 0 and k > 0)
for row in grid:
    ass(len(row) == w)


def count_ones(i):
    cnt = 0
    while i:
        if i & 1:
            cnt += 1
        i >>= 1
    return cnt

ans = h + w

for state in range(1 << h):
    j = 0
    vcnt = 0
    counters = [0] * (h + 1)
    is_ok = True
    while j < w:
        hi = 0
        i = 0
        local_counters = [0] * (h + 1)
        ass(len(counters) == len(local_counters))
        while i < h:
            if (1 << i) & state:
                hi = i
            # print(hi, i, j)
            # print(grid[i])
            ass(len(local_counters) > hi)
            ass(i < h and j < w)
            ass(len(grid) > i)
            ass(len(grid[i]) > j)
            local_counters[hi] += grid[i][j]
            i += 1
        for i, v in enumerate(local_counters):
            if v > k:
                is_ok = False
                break
            counters[i] += local_counters[i]
        if not is_ok:
            break
        # ass(len(counters))
        # ass(k)
        if max(counters) > k:
            counters = local_counters[:]
            vcnt += 1

        j += 1


    if is_ok and ans > count_ones(state) + vcnt:
        ans = count_ones(state) + vcnt
print(ans)
# -*- coding: UTF-8 -*-
import math

n = int(input())
l = []

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()

p = 0
s = 0
f = 0

for i in range(n):
    if l[i] == l[i+1]:
        s =+ 1
        f = 1
    elif l[i] != l[i+1] and f == 1:
        s += 1
        f = 0
        p += math.factorial(s)/(2 * math.factorial(s-2))


print(p)


### FIXED CODE ###

# -*- coding: UTF-8 -*-

n = int(input())
l = []

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()

p = 0
s = 1
f = 0

for i in range(n-1):
    if l[i] == l[i+1] and i != n-2:
        s += 1
        f = 1

    elif l[i] != l[i+1] and f == 1:
        f = 0
        p += int(s * (s-1) / 2)
        s = 1

    elif l[i] == l[i+1] and i == n-2:
        s += 1
        f = 0
        p += int(s * (s-1) / 2)


print(p)
a = input()
print(1+ a**2 + a**3)

### FIXED CODE ###

a = int(input())
print(a + a**2 + a**3)
import collections

# input
N = int(input())
A = map(int,input().split())
# calculatioin
cnt = collections.Counter(A)
full_cnt = int(sum(cnt[key]*(cnt[key]-1)/2 for key in cnt))
for i in range(N):
  print(full_cnt - cnt[A[i]]+1)

### FIXED CODE ###

import collections

# input
N = int(input())
A = input().split()
# calculatioin
cnt = collections.Counter(A)
full_cnt = int(sum(cnt[key]*(cnt[key]-1)/2 for key in cnt))
for i in range(N):
  print(full_cnt - cnt[A[i]]+1)
h, r = list(map(int, input().split()))
print(int((h+r)/abs(h+r)))


### FIXED CODE ###

h, r = list(map(int, input().split()))
print(int((h+r>0)-(h+r<0)))
a, b = map(int, input().split())

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 = int(input())
l = [list(map(int, input().split())) for _ in range(N)]

diff = [0] * 100001
for k in l :
    diff[k[0] - 1] += 1
    diff[k[1]] -= 1

hist = [0,0]
for i in range(2, N + 1) :
    hist.append(hist[-1] + diff[i-1])

print(max([y - 1 for (x,y) in zip(hist, range(N + 1)) if x + 1 >= y]))

### FIXED CODE ###

N = int(input())
l = [list(map(int, input().split())) for _ in range(N)]

diff = [0] * 100002
for k in l :
    diff[k[0] - 1] += 1
    diff[k[1]] -= 1

hist = [0,0]
for i in range(2, N + 2) :
    hist.append(hist[-1] + diff[i-1])

print(max([0] + [y - 1 for (x,y) in zip(hist, range(N + 2)) if x + 1 >= y]))
n =input()
ans =0
for i in range(n):
	a, b =map(int, input().split())
  	ans +=b-a
print(ans)

### FIXED CODE ###

n =int(input())
ans =0
for i in range(n):
    a, b =map(int, input().split())
    ans +=b-a+1
    
print(ans)
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

index = []

for i, s in enumerate(itertools.permutations(range(1, n+1),n)):
    if s == p or s == q:
        index.append(i)

print(abs(index[0]-index[1]))


### FIXED CODE ###

import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

index = []

for i, s in enumerate(itertools.permutations(range(1, n+1),n)):
    if s == p or s == q:
        index.append(i)


if len(index) == 2:
    print(abs(index[0]-index[1]))
else:
    print('0')
N = int(input())
A = list(map(int, input().split())).sort()

for n in range(N):
    print(A.count(n+1))


### FIXED CODE ###

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

#for n in range(N):
#    print(A.count(n+1))

M = {}
for a in A:
    M[a] = M.get(a,0) + 1

for n in range(N):
    print(M.get(n+1,0))
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=list(map(int,input().split()))
    cunt=[0]*n
    cunt[0]=3
    ans=1
    mod=10**9+7
    for a in A:
        ans=ans*cunt[a]%mod
        if ans==0:break
        cunt[a+1]+=1
        cunt[a]-=1
    print(ans)
    

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    A=list(map(int,input().split()))
    rgb=[-1,-1,-1]
    ans=1
    mod=10**9+7
    for a in A:
        ans=ans*Counter(rgb)[a-1]%mod
        if ans==0:break
        rgb[rgb.index(a-1)]+=1
    print(ans)
    

if __name__=='__main__':
    main()
n,m = list(map(int, input().split()))
a =  list(map(int, input().split()))

print(max(n - sum(a), -1)

### FIXED CODE ###

n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
 
print(max(n - sum(a), -1))
def counter():#島の数をカウントする
    count=0
    #12*12個の値をひとつずつ調べる
    for x in range(12):
        for y in range(12):
            if is_data[x][y] == 1:#島が発見されたら
                dfs(x,y)
                count+=1
    return count
def dfs(x,y):
    if x<0 or x == len(is_data[x]) or y<0 or y == len(is_data):
        return
    if is_data[x][y] == 1:
        is_data[x][y] = 0
        dfs(x+1,y)
        dfs(x,y+1)
        dfs(x-1,y)
        dfs(x,y-1)

try:
    while True:
        s = input()#入力
        for i in range(len(s)):
            is_data[i] = list(is_data[i].strip())
        is_data = np.array(is_data).reshape(12,12)
except EOFError:
    print(counter())


### FIXED CODE ###

def counter():#島の数をカウントする
    count=0
    #12*12個の値をひとつずつ調べる
    for x in range(len(is_data)):
        for y in range(len(is_data)):
            if is_data[x][y] == '1':#島が発見されたら
                dfs(x,y)
                count+=1
    return count
def dfs(x,y):
    if x<0 or x == len(is_data) or y<0 or y == len(is_data):
        return
    if is_data[x][y] == '1':
        is_data[x][y] = '0'
        dfs(x+1,y)
        dfs(x,y+1)
        dfs(x-1,y)
        dfs(x,y-1)

is_data=[]
while True:
    try:
        s = list(input())#入力
        if not s:#空入力のとき
            print(counter())
            is_data=[]
            s = []
        else:
            is_data.append(s)
    except EOFError:
        print(counter())
        break
def main10():
    buf = int(input(""));
    strbuf = input("");
    strbufs = strbuf.split();
    buf2 = [];
    for i in range(buf):
        buf2.append(int(strbufs[i]));
    if len(buf2) == 1:
        return("YES");
    else:
        ki = 0;
        for i in range(buf):
            if buf2[i] % 2 == 1:
                ki += 1;
        if ki % 2 == 0:
            print("YES");
        else:
            print("NO");



if __name__ == '__main__':
    main10()

### FIXED CODE ###

def main24():
    strbuf = input("");
    strbufs = strbuf.split();
    buf = [];
    for i in range(3):
        buf.append(int(strbufs[i]));
    if (buf[0]%2==1)and(buf[1]%2==1)and(buf[2]%2==1):
        buf.sort();
        are = buf[0] * buf[1];
        print(are);
    else:
        print(0);

if __name__ == '__main__':
    main24()
import math

def cost(n,h,mincost):
  if (n == 1):
    return 0
  elif (n == 2):
    return abs(h(1) - h(0))
  elif (mincost(n) is not None):
    return mincost[n]
  else:
  	mincost[n] = min(cost(n-1,h,mincost) + abs(h[n]-h[n-1]), cost(n-2,h,mincost) + abs(h[n]-h[n-2]))
  return mincost[n]

n = input()
h = [None]*n
mincost = [None]*n
i = 0

while(i<n):
  h[i] = input()
  i = i + 1 

return cost(n,h,mincost)

### FIXED CODE ###

import math
import sys
sys.setrecursionlimit(10**6)

n = int(input())
mincost = [None]*n

def cost(n,h):
  if (mincost[n-1] is not None):
    return mincost[n-1]
  elif (n == 1):
    mincost[n-1] = 0
  elif (n == 2):
    mincost[n-1] =  abs(h[1] - h[0])
  else:
    mincost[n-1] = min(cost(n-1,h) + abs(h[n-1]-h[n-2]), cost(n-2,h) + abs(h[n-1]-h[n-3]))
  return mincost[n-1]

h = [None]*n

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

print(cost(n,h))
temp=input().split()
L=int(temp[0])
R=int(temp[1])

print(min([(i*j)%2019 for i in range(L, R-1) for j in range(i, R)]))

### FIXED CODE ###

temp=input().split()
L=int(temp[0])
R=int(temp[1])

if R-L>=2019:
  print(0)
else:
  print(min([(i*j)%2019 for i in range(L, R) for j in range(i+1, R+1)]))
Jupyter Notebook
Untitled
(unsaved changes)
Current Kernel Logo
Python 3 
File
Edit
View
Insert
Cell
Kernel
Widgets
Help

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

if A == B and B == C:
    re = 'Yes'
else:
    re = 'No'
    
print(re)
A, B, C = list(map(int, input().split()))
​
if A == B and B == C:
    re = 'Yes'
else:
    re = 'No'
    
print(re)
3 4 5
No
1
N = int(input())
s = input()
​
R = 0
B = 0
for c in s:
    if c == 'R':
        R += 1
    else:
        B +=1
        
if R > B:
    re = 'Yes'
else:
    re = 'No'
    
print(re)
4
BRBR
No
​


### FIXED CODE ###

N = int(input())
s = input()

R = 0
B = 0
for c in s:
    if c == 'R':
        R += 1
    else:
        B +=1
        
if R > B:
    re = 'Yes'
else:
    re = 'No'
    
print(re)
N = str(N)
answer = 'hon'
pon_list = [0, 1, 6, 8]
bon_list = [3]
if N[-1] in bon_list:
  answer = 'bon'
elif N[-1] in pon_list:
  answer = 'pon'
print(answer)

### FIXED CODE ###

N = str(input())
identify = N[-1]
answer = ''
pon_list = ['0','1', '6', '8']
bon_list = ['3']
if identify in pon_list:
  answer = 'pon'
elif identify in bon_list:
  answer = 'bon'
else:
  answer = 'hon'
print(answer)
N = int(input())

y = []

for i in range(1, N//2):
    if N % i == 0:
        y.append( max( len(str(i)),  len(str(int(N/i))) ) )
print(min(y))

### FIXED CODE ###

N = int(input())

ans = 10**18

for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        b = N//i
        ans = min(ans, max( len(str(i)),  len(str(b))))
print(ans)
n,m=map(int,input().split())
p=[[]for _ in range(n)]
c=[0]*n
import sys
sys.setrecursionlimit(n)
for i in range(m):
    x,y=map(int,input().split())
    p[x-1].append(y-1)
from functools import lru_cache
@lru_cache(maxsize=n)
def l(k):
    return max([l(i)for i in p[k]]+[0])+1
print(max([l(i)for i in range(n)])-1)

### FIXED CODE ###

n,m=map(int,input().split())
p=[[]for _ in range(n)]
c=[0]*n
import sys
sys.setrecursionlimit(10**6)
for i in range(m):
    x,y=map(int,input().split())
    p[x-1].append(y-1)
from functools import lru_cache
@lru_cache(maxsize=n)
def l(k):
    return max([l(i)for i in p[k]]+[0])+1
print(max([l(i)for i in range(n)])-1)
from operator import itemgetter
N,M = [int(x) for x in input().split()]
LRC = []
event = []
dists = [float('inf')]*N
dists[0] = 0
cnt_key = 0
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    event.append((l-1, c, 1, cnt_key))
    event.append((r-1, c, -1, cnt_key))
    cnt_key += 1

event.sort(key=itemgetter(0))
paths = {}
now_dist = 0
for ev in event:
    x = ev[0]
    for s in paths:
        if(dists[x]<paths[s][1]):
            paths[s][1] = dists[x]
        dists[x] = min(dists[x], paths[s][0]+paths[s][1])

    if(ev[2]==1):
        paths[ev[3]] = [ev[1], dists[ev[0]]]
    else:
        del paths[ev[3]]

if(dist[-1]==float('inf')):
    print(-1)
else:
    print(dist[-1])


### FIXED CODE ###

from operator import itemgetter
from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

N,M = [int(x) for x in input().split()]
graph = Graph()
for n in range(N):
    graph.add_edge(n+1, n, 0)
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    graph.add_edge(l-1, r-1, weight=c)

dijkstra = Dijkstra(graph, 0)
ans = dijkstra.shortest_distance(N-1)
if(ans == float('inf')):
    print(-1)
else:
    print(ans)
n=int(input())
b=list(map(int,input().split()))

x=a[1]

i=0
while n>i:
  if b[i]<=b[i+1]:
    x+=b[i]
    i+=1
  else:
    x+=b[i+1]
    i+=1
    
print(x)

  

### FIXED CODE ###

n=int(input())
b=list(map(int,input().split()))

x=b[0]+b[n-2]

i=1
while n-1>i:
  if b[i-1]<=b[i]:
    x+=b[i-1]
    i+=1
  else:
    x+=b[i]
    i+=1
    
print(x)
s = [1 if si == 'o' else 0 for si in list(input())]
t0 = [[1, 1], [1, 0], [0, 1], [0, 0]]
for ti in t0:
    flag = True
    for i in range(1, n - 1):
        if ti[i] * (1 - s[i]) or (1 - ti[i]) * s[i]:
            ti.append(1 - ti[i - 1])
        else:
            ti.append(ti[i - 1])
    for i in range(2):
        if ti[i - 1]:
            if (s[i - 1] and not ti[i - 2] == ti[i]) or (1 - s[i - 1] and ti[i - 2] == ti[i]):
                flag = False
        else:
            if (s[i - 1] and ti[i - 2] == ti[i]) or (1 - s[i - 1] and not ti[i - 2] == ti[i]):
                flag = False
    if flag:
        ans = ['S' if x else 'W' for x in ti]
        print(''.join(ans))
        exit()
print(-1)

### FIXED CODE ###

n = int(input())
s = [1 if si == 'o' else 0 for si in list(input())]
t0 = [[1, 1], [1, 0], [0, 1], [0, 0]]
for ti in t0:
    flag = True
    for i in range(1, n - 1):
        if ti[i] * (1 - s[i]) or (1 - ti[i]) * s[i]:
            ti.append(1 - ti[i - 1])
        else:
            ti.append(ti[i - 1])
    for i in range(2):
        if ti[i - 1]:
            if (s[i - 1] and not ti[i - 2] == ti[i]) or (1 - s[i - 1] and ti[i - 2] == ti[i]):
                flag = False
        else:
            if (s[i - 1] and ti[i - 2] == ti[i]) or (1 - s[i - 1] and not ti[i - 2] == ti[i]):
                flag = False
    if flag:
        ans = ['S' if x else 'W' for x in ti]
        print(''.join(ans))
        exit()
print(-1)
string = input()
for i in range(len(string)):
    if i % 2 == 0:
        if string[i] == 'h':
            continue
        else:
            print('No')
            break
    elif i % 2 == 1:
        if string[i] == 'i':
            continue
        else:
            print('No')
            break
else:
  	if len(string) == 1:
      	print('No')
    else:
    	print('Yes')

### FIXED CODE ###

string = input()
for i in range(len(string)):
    if i % 2 == 0:
        if string[i] == 'h':
            continue
        else:
            print('No')
            break
    elif i % 2 == 1:
        if string[i] == 'i':
            continue
        else:
            print('No')
            break
else:
    if len(string) % 2 == 1:
        print('No')
    else:
        print('Yes')
s=input()
r=set()
last=0
power=0
d={}
total=0
for i in range(len(s)-1,-1,-1):
    n=int(s[i])*(10**(power))+last
    power+=1
    last=n%2019
    rem=n%2019
    if rem==0:
        total+=1
        r.add(rem)
    if rem in r:
        d[rem]+=1
        total+=d[rem]-1
    else:
        r.add(rem)
        d[rem]=1
        
print(total)

### FIXED CODE ###

s=input()
r=set()
last=0
power=1
d={0:0}
total=0
rem=0
for i in range(len(s)-1,-1,-1):#handling of 0's as n and rem
    n=int(s[i])*power+rem
    power*=10
    power=power%2019
    rem=n%2019
    if rem in d.keys():
        d[rem]+=1
    else:
        d[rem]=1
    total+=d[rem]-1
print(total+d[0])
# ruiseki
from collections import Counter
F = open("/Users/yamataku/Downloads/subtask_1_09.txt")
# N = int(input())
# A_s = list(map(int,input().split()))
N = int(F.readline())
A_s = list(map(int,F.readline().split()))
ruiseki = [0]
for i,a in enumerate(A_s):
    ruiseki.append(ruiseki[i]+a)
counter = Counter(ruiseki)

answer = 0
for k,v in counter.items():
    if v > 1:
        answer += v * (v-1)//2
print(answer)

### FIXED CODE ###

from collections import Counter
N = int(input())
A_s = list(map(int,input().split()))
ruiseki = [0]
for i,a in enumerate(A_s):
    ruiseki.append(ruiseki[i]+a)
counter = Counter(ruiseki)


answer = 0
for k,v in counter.items():
    if v > 1:
        answer += v * (v-1)//2
print(answer)
import sympy

N=int(input())
count=0
for i in range(1,N):
    count+=len(sympy.divisors(i))
    
print(count)

### FIXED CODE ###

def ndt(n):
    table = [0] * (n + 1)
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    return table

N=int(input())
print(sum(ndt(N-1)))
n, m = map(int, input().split())
cnt = [0] * m
for _ in range(n):
    k, *a = map(int, input().split())
    for A in a:
        cnt[A - 1] += 1
print(sum(c == n for c in cnt))


### FIXED CODE ###

a, b = map(int, input().split())
if b % a == 0:
  print(a + b)
else:
  print(b - a)
n=list(map(int,input().split()))
for i in range(3):
  if n[i] == 1:
    n[i] = 9
  else:
    n[i] = 1
print("".join(n))

### FIXED CODE ###

n=list(input())
for i in range(3):
  if n[i] == "1":
    n[i] = "9"
  else:
    n[i] = "1"
print("".join(n))
N = int(input())

def check(a, b, i):
  if (a + 1) * 10 ** i + b - 10 <= N:
    return 10 ** (i - 1)
  else:
    ret = 0
    for j in range(10 ** (i - 1)):
      if a * 10 ** i + j * 10 + a <= N:
        ret += 1
      else:
        return ret
ans = 0
for a in range(1, 10):
  for b in range(1, 10):
    if a == b:
      n = 0
      if a * 10 + b <= N:
        n += 2
      elif a <= N:
        ans += 1
      for i in range(2, 6):
        n += check(a, b, i)
      ans += n ** 2
    else:
      n, m = 0, 0
      if a * 10 + b <= N:
        n += 1
      if b * 10 + a <= N:
        m += 1
      for i in range(2, 6):
        n += check(a, b, i)
        m += check(b, a, i)
      ans += n * m
print(ans)

### FIXED CODE ###

N = int(input())

c = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, 10):
  for j in range(1, 10):
    cnt = 0
    for n in range(1, N + 1):
      if n // (10 ** (len(str(n)) - 1)) == i and n % 10 == j:
        cnt += 1
    c[i - 1][j - 1] = cnt

ans = 0
for i in range(9):
  for j in range(9):
    ans += c[i][j] * c[j][i]
print(ans)
n = int(input())
for i in range(1, 10)
  for j in range(1, 10)
    if n == i * j:
      print("Yes")
      break
 
print("No")



### FIXED CODE ###

n = int(input())
ans = ('No')
for i in range(1,10):
    for j in range(1,10):
        if i * j == n:
            ans = ('Yes')
            break
print(ans)
a,b==map(int,input().split())
print("Even" if a*b%2==0 else "Odd")

### FIXED CODE ###

a,b=map(int,input().split())
print("Even" if a*b%2==0 else "Odd")
# ABC C-Tsundoku
n,m,k = map(int,input().split())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))

suma = [0]
sumb = [0]
a = 0
b = 0
for i in an:
    a += i
    suma.append(a)
for i in bn:
    b += i
    sumb.append(b)

res = [0]
for j in range(n+1):
    if k-suma[j] < 0:
        break
    for l in range(m+1):
        if k-suma[j]-sumb[l] > 0:
        res.append(j+l)
print(max(res))

### FIXED CODE ###

n,m,k = map(int, input().split( ))
A = list(map(int, input().split( )))
B = list(map(int, input().split( )))
acc1 = [0]
for i in range(n):
  acc1.append(acc1[-1] + A[i])
acc2 = [0]
for i in range(m):
  acc2.append(acc2[-1] + B[i])

ans = 0
j = m
for i in range(n+1):
  if acc1[i] > k:
    break
  while acc2[j] > k - acc1[i] and j > 0:
    j -= 1
  ans = max(ans,i+j)
print(ans)
n = int(input())
a = [int(n) for n in input().split()]

b = [0] * n

for i in a:
    b[i-1] += 1
 
for i in b:
    print(i)

### FIXED CODE ###

from math import pi
R = int(input())
C = 2 * R * pi
print(C)
a=input()
b=[]
c=0
for i in range(len(a)):
  b.append(a[i])
b.sort()
for i in range(len(a-1)):
  if b[i]==b[i+1]:
    c=c+1
if c==0:
  print("yes")
else:
  print("no")

### FIXED CODE ###

a=input()
b=[]
c=0
for i in range(len(a)):
  b.append(a[i])
b.sort()
for i in range(len(a)-1):
  if b[i]==b[i+1]:
    c=c+1
if c==0:
  print("yes")
else:
  print("no")
a, b, c = map(int, input().split())
x =a*10 + b
y = b*10+ c
print([x, y] if x < y)

### FIXED CODE ###

a, b, c = map(int, input().split())
x = a*10 + b + c
y = b*10+ c + a
z = c*10+ a + b
print(max([x, y,z]))
s = raw_input()
w = int(raw_input())

result = ""
for i in xrange((len(s) / w) + 1):
  result += s[i * w]

print result

### FIXED CODE ###

s = raw_input()
w = int(raw_input())

result = ""
for i in xrange((len(s) / w)):
  result += s[i * w]
  
if len(s) % w != 0:
  result += s[-(len(s) % w)]
print result
n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n):
  ans[a[i]] += 1
for i in range(n):
  print(ans[i])

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(n-1):
  ans[a[i]-1] += 1
for i in range(n):
  print(ans[i])
# 初期入力
N,K = (int(x) for x in input().split(" "))

#
zeroika = N//K
N1 =abs(N-K*zeroika) #N1がマイナスになって初めてABS、そこまではKの倍数単調に減る
    N =N1
    N1 =abs(N-K)
    #print(N1,end=" ")
print(N)

### FIXED CODE ###

# 初期入力
N,K = (int(x) for x in input().split(" "))

#
zeroika = 0
if K <N:
    zeroika = N//K
else:
    zeroika = 1
N1 =abs(N-K*zeroika) #N1がマイナスになって初めてABS、そこまではKの倍数単調に減る
while N1<N:
    N =N1
    N1 =abs(N-K)
    #print(N1,end=" ")
print(N)
a,b=map(int,input().split())
if (a=="H" and b=="H") or (a=="D" and b=="D"):
    print("H")
else:
    print("D")

### FIXED CODE ###

a,b=input().split()
if (a=="H" and b=="H") or (a=="D" and b=="D"):
    print("H")
else:
    print("D")