Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import bisect

n,m,q=map(int,input().split())
s=[[] for i in range(n+1)]
a=[]

for i in range(m):
  l,r=map(int,input().split())
  s[l].append(r)

for i in range(n+1):
  s[i].sort()

for i in range(q):
  t=0
  l,r=map(int,input().split())
  for i in range(l,r+1):
    t += bisect.bisect_right(s[i],r)
  a.append(t)

for i in range(q):
  print(a[i])


### FIXED CODE ###

n,m,q=map(int,input().split())
s=[[0 for i in range(n+1)] for j in range(n+1)]

a=list()

for i in range(m):
  l,r=map(int,input().split())
  s[l][r] += 1

for i in range(1,n+1):
  for j in range(1,n+1):
    s[i][j] += s[i][j-1] 

for i in range(1,n+1):
  for j in range(1,n+1):
    s[j][i] += s[j-1][i]

for i in range(q):
  l,r=map(int,input().split())
  t = s[r][r] - s[l-1][r] - s[r][l-1] + s[l-1][l-1]
  a.append(t)

for i in range(q):
  print(a[i])
### BUGGY CODE ###

import bisect
import sys
input = sys.stdin.buffer.readline


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


ans = 0
for keta in range(0, 29)[::-1]:
    MOD = 1 << (keta + 1)
    T = 1 << keta
    for i in range(n):
        a[i] %= MOD
        b[i] %= MOD
    b.sort()

    # T <= a[i] + b[j] < 2T もしくは 3T <= a[i] + b[j] < 4T
    # を満たすi, jの組の個数を二分探索で探す。
    cnt = 0
    for i in range(n):
        l = bisect.bisect_left(b, T - a[i]) 
        r = bisect.bisect_left(b, 2 * T - a[i]) 
        cnt += r - l
        l = bisect.bisect_left(b, 3 * T - a[i]) 
        r = bisect.bisect_left(b, 4 * T - a[i]) 
        cnt += r - l

    # i, jの組の個数が奇数だったら、xorしたときにTが残る
    if cnt % 2 == 1:
        ans += T

print(ans)

### FIXED CODE ###

from bisect import bisect_left
import sys
input = sys.stdin.buffer.readline


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


ans = 0
for keta in range(0, 29)[::-1]:
    MOD = 1 << (keta + 1)
    T = 1 << keta
    for i in range(n):
        a[i] %= MOD
        b[i] %= MOD
    a.sort(reverse=True)
    b.sort()

    # T <= a[i] + b[j] < 2T もしくは 3T <= a[i] + b[j] < 4T
    # を満たすi, jの組の個数を尺取り法で探す
    T1 = [0] * n
    l = 0
    for i in range(n):
        while l < n and a[i] + b[l] < T:
            l += 1
        T1[i] = l

    T2 = [0] * n
    l = 0
    for i in range(n):
        while l < n and a[i] + b[l] < 2 * T:
            l += 1
        T2[i] = l

    T3 = [0] * n
    l = 0
    for i in range(n):
        while l < n and a[i] + b[l] < 3 * T:
            l += 1
        T3[i] = l

    T4 = [0] * n
    l = 0
    for i in range(n):
        while l < n and a[i] + b[l] < 4 * T:
            l += 1
        T4[i] = l

    cnt = 0  
    for i in range(n):
        cnt += (T2[i] - T1[i]) + (T4[i] - T3[i])

    # i, jの組の個数が奇数だったら、xorしたときにTが残る
    if cnt % 2 == 1:
        ans += T

print(ans)
### BUGGY CODE ###

def binary_search_ceiling(list, element):
    i = 0
    j = len(list) - 1
    if element < list[0]:
        return None
    elif element >= list[-1]:
        return len(list) - 1
    while i <= j:
        k = (i + j) // 2
        if list[0] == element:  # k - 1が0にならないので特例
            return 0
        elif list[k - 1] < element <= list[k]:
            return k
        elif list[k] < element < list[k + 1]:
            return k + 1
        elif list[k] < element:
            i = k  # elementがk番とk+1番の間にあるかもしれないのでi = k + 1 ではなくi = k
        else:
            j = k  # 上と同様に考えてj = k

    return None


def main():
    A, B, Q = map(int, input().split())
    INF = 10 ** 11
    s_list = [-2 * INF, -INF] + [int(input()) for i in range(A)] + [INF, 2 * INF]
    t_list = [-2 * INF, -INF] + [int(input()) for i in range(B)] + [INF, 2 * INF]
    x_list = [int(input()) for i in range(Q)]

    for xi in x_list:
        dist_list = [INF for i in range(8)]

        ind_s = binary_search_ceiling(s_list, xi)
        ws = s_list[ind_s - 1]
        dist_list[0] = dist_list[1] = abs(ws - xi)
        es = s_list[ind_s]
        dist_list[2] = dist_list[3] = abs(es - xi)

        ind_t = binary_search_ceiling(t_list, xi)
        wt = t_list[ind_t - 1]
        dist_list[4] = dist_list[5] = abs(wt - xi)
        et = t_list[ind_t]
        dist_list[6] = dist_list[7] = abs(et - xi)

        ws_ind_t = binary_search_ceiling(t_list, ws)
        wswt = t_list[ws_ind_t - 1]
        dist_list[0] += abs(wswt - ws)
        wset = t_list[ws_ind_t]
        dist_list[1] += abs(wset - ws)

        es_ind_t = binary_search_ceiling(t_list, es)
        eswt = t_list[es_ind_t - 1]
        dist_list[2] += abs(eswt - es)
        eset = t_list[es_ind_t]
        dist_list[3] += abs(eset - es)

        wt_ind_s = binary_search_ceiling(s_list, wt)
        wtws = s_list[wt_ind_s - 1]
        dist_list[4] += abs(wtws - wt)
        wtes = s_list[wt_ind_s]
        dist_list[5] += abs(wtes - wt)

        et_ind_s = binary_search_ceiling(s_list, et)
        etws = s_list[et_ind_s - 1]
        dist_list[6] += abs(etws - et)
        etes = s_list[et_ind_s]
        dist_list[7] += abs(etes - et)

        print(min(dist_list))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import bisect as b


def main():
    A, B, Q = map(int, input().split())
    INF = 10 ** 11
    s_list = [-INF] + [int(input()) for i in range(A)] + [INF]
    t_list = [-INF] + [int(input()) for i in range(B)] + [INF]

    len_s = A + 1
    len_t = B + 1

    for i in range(Q):
        xi = int(input())
        ind_s = b.bisect_left(s_list, xi)
        ws = s_list[ind_s - 1]
        es = s_list[ind_s]

        ind_t = b.bisect_left(t_list, xi)
        wt = t_list[ind_t - 1]
        et = t_list[ind_t]

        dist_list = [
                     xi - min(ws, wt),
                     max(es, et) - xi,
                     xi + es - wt * 2,
                     xi + et - ws * 2,
                     (es * 2) - wt - xi,
                     (et * 2) - ws - xi
                     ]

        print(min(dist_list))


if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

ans=''
for i in range(n):
    ans+=str(a.count(i+1))+'\r\n'

print(ans)

### FIXED CODE ###

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

ans=[0]*(n)
for i in a:
    ans[i-1]+=1

for i in ans:
    print(i)
### BUGGY CODE ###

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

mod=10**9+7
ans=0

for i in range(60):
    a=0
    for x in A:
        if x>>i&1:
            a+=1
    ans+=a*(N-a)*pow(2,i,mod)
    ans%=mod

    
print(ans)


### FIXED CODE ###

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

mod=10**9+7
ans=0
cnt=[[0]*2 for _ in range(60)]

for x in A:
    for i in range(60):
        a=x%2
        x//=2
        cnt[i][a]+=1

for p,q in enumerate(cnt):
    i,j=q
    ans+=((i*j)%mod)*pow(2,p,mod)
    ans%=mod
    
print(ans)
### BUGGY CODE ###

N = int(input())
S =list(input())
count = float("inf")

for i in range(N):
    count = min(S[0:i].count('W') + S[i+1:N].count('E'), count)
print(count)

### FIXED CODE ###

N = int(input())
S =list(input())
ans = N
W = 0
E = S.count('E')

for i in range(N):
    if S[i] =='E':
        E -= 1
    ans = min(ans, W+E)
    if S[i] == 'W':
        W += 1
print(ans)
### BUGGY CODE ###

n=int(input())
from itertools import groupby
from collections import deque
s=list(input())
gr=groupby(s)
#flg=0:白の状態
flg=0
black=[]
white=[]
for k,v in gr:
    if flg==0 and k=='#':
        flg=1
        black.append(len(list(v)))
    elif flg==1:
        if k=='#':
            black.append(len(list(v)))
        else:
            white.append(len(list(v)))
if len(black)==0 or len(white)==0:
    print(0)
    exit(0)

ans=white.copy()
cnt=sum(ans)

white=deque(white)
black=deque(black)
ans=deque(ans)

while white:
    ans.popleft()
    white.popleft()
    ans.append(black.popleft())
    cnt=min(cnt,sum(ans))

print(cnt)





### FIXED CODE ###

n=int(input())
s=list(input())

from itertools import groupby

gr=groupby(s)
#flg=0:白の状態
flg=0
black=[]
white=[]
for k,v in gr:
    if flg==0 and k=='#':
        flg=1
        black.append(len(list(v)))
    elif flg==1:
        if k=='#':
            black.append(len(list(v)))
        else:
            white.append(len(list(v)))
if len(black)==0 or len(white)==0:
    print(0)
    exit(0)




cnt=sum(white)
ans=[cnt]
for i in range(len(white)):
    cnt+=(black[i]-white[i])
    ans.append(cnt)

print(min(ans))
### BUGGY CODE ###

import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    li=[[-1 for i in range(3)]for j in range(n)]
    a.append(x)
    b.append(y)
    c.append(z)
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))



### FIXED CODE ###

import sys
def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


n=int(input())
a, b, c = [], [], []
for _ in range(n):
    x,y,z=get_ints()
    
    a.append(x)
    b.append(y)
    c.append(z)
li=[[-1 for i in range(3)]for j in range(n)]
li[0][0],li[0][1],li[0][2]=a[0],b[0],c[0]
for i in range(1,n):


        li[i][0] = max(a[i] + li[i-1][1] ,a[i] + li[i - 1][2])

        li[i][1] = max(b[i] + li[i - 1][0], b[i] +li[i - 1][2])

        li[i][2] = max(c[i] + li[i - 1][1], c[i] + li[i - 1][0])
print(max(li[n-1]))
### BUGGY CODE ###

N=int(input())
A = [int(input()) for i in range(N)]
import bisect



mina = [A[0]]

# print(mina)
# ans = 
for i in range(1,N):
    # print(mina)
    if mina[0]>=A[i]:
        ind = bisect.bisect_left(mina,A[i])
        mina.insert(ind,A[i])
        # ans +=1 
    else:
        ind = bisect.bisect_left(mina,A[i])
        # mina.insert(ind,A[i])
        mina[ind-1]=A[i]
        # if ind == len(mina)-1:
            
        #     del(mina[-2])
        # else:
        #     # print("a")
        #     del(mina[ind-1])


# print(mina)
    
print(len(mina))


### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]

import bisect

bilist = [A[0]]
ans = 0

for a in A[1:]:
    index = bisect.bisect_left(bilist,a)
    if index == 0:
        bisect.insort_left(bilist,a)
    else:
        bilist[index-1] = a


print(len(bilist))
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
s = []
cnt = 0
n = 1
f = False
while True:
  cnt += 1
  s.append(n)
  if A[n - 1] == 2:
    f = True
    break
  elif s.count(A[n - 1]) == 1:
    break
  n = A[n - 1]
print(cnt if f else -1)


### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

cnt = 0
n = 1
f = False
while cnt <= N:
  cnt += 1
  n = A[n - 1]
  if n == 2:
    f = True
    break
print(cnt if f else -1)
### BUGGY CODE ###

#1,0が隣り合ったところを取り出していく　

L = [int(i) for i in list(input())]
N = len(L)
count = 0
flag = 0

k = 0
while 1:
  flag = 0
  i = N - 1
  while (i != 0) and (i > 0) :
    if (((L[i - 1] == 1) and (L[i] == 0)) or ((L[i - 1] == 0) and (L[i] == 1))):
      del L[i - 1:i + 1]
      N = N - 2
      count += 2
      i -= 1
      flag = 1
    i -= 1

  if flag == 0:
    break

print(count)


### FIXED CODE ###

L = [int(i) for i in list(input())]
N = len(L)

one = L.count(1)
zero = L.count(0)

if one < zero :
  print(one * 2)
else :
  print(zero * 2)
### BUGGY CODE ###

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 100000
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

n = k()
a = l()

for i in range(n-1):
    for j in range(i+1, n):
        ans += (a[i]*a[j])

print(ans % mod)

### FIXED CODE ###

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 100000
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

n = k()
a = l()

ruiseki = list(itertools.accumulate(a))

for i in range(n-1):
    ans += a[i]*(ruiseki[-1]-ruiseki[i])

print(ans % mod)
### BUGGY CODE ###

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

m = max(p)
l = [0]
for i in range(1,m + 1):
    l.append(l[-1] + i)
for i in range(1,len(l)):
    l[i]/=i
for i in range(n):
    p[i] = l[p[i]]

ans = 0
for i in range(len(p) - k + 1):
    ans = max(ans,sum(p[i:i + k]))

print(ans)

### FIXED CODE ###

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

m = max(p)
l = [0]
for i in range(1,m + 1):
    l.append(l[-1] + i)
for i in range(1,len(l)):
    l[i]/=i
for i in range(n):
    p[i] = l[p[i]]

#累積和
for i in range(1,len(p)):
    p[i]+=p[i - 1]
p=[0]+p

ans = 0
for i in range(len(p) - k):
    ans = max(ans,p[i + k] - p[i])

print(ans)
### BUGGY CODE ###

import numpy as np
N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

ans = np.inf
for b in A:
    tmp = A - b
    tmp = np.absolute(tmp)
    tmp = tmp.sum()
    if ans > tmp:
        ans = tmp

print(ans)

### FIXED CODE ###

import numpy as np

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

A = np.asarray(A)
i = np.asarray([x for x in range(1, N+1)])
A = A - i

b = np.round(np.median(A))
A = A - b
A = np.absolute(A)
print(A.sum().astype(np.uint64))
### BUGGY CODE ###

V, E = map(int, raw_input().split())
g = [[] for i in xrange(V)]
for i in xrange(E):
    s, t, d = map(int, raw_input().split())
    g[s].append((t, d))
INF = 10**9
dp = [[-1]*V for i in xrange(2**V)]
tmp = {}
def dfs(state, v, s):
    if dp[state][v] != -1:
        return dp[state][v]
    if state == 2**V-1:
        for t, d in g[v]:
            if t==s:
                dp[state][v] = d
                return d
        return INF
    res = INF
    idx = -1
    for t, d in g[v]:
        if state & (1 << t):
            continue
        r = dfs(state | (1 << t), t, s) + d
        if r < res:
            idx = t
        res = min(res, r)

    tmp[state, v] = (idx, res)

    return res
def solve(v):
    global dp
    dp = [[-1]*V for i in xrange(2**V)]
    return dfs(1<<v, v, v)
res = min(solve(v) for v in xrange(V))
print res if res<INF else -1

### FIXED CODE ###

import sys
readline = sys.stdin.readline
V, E = map(int, readline().split())
g = [[] for i in xrange(V)]
cost = {}
to = [0]*V
for i in xrange(E):
    s, t, d = map(int, readline().split())
    g[s].append((t, d))
    cost[s,t] = d
    to[s] |= 1 << t
get = cost.get
INF = 10**9
ALL = 2**V-1
dp = {}
start = 0
def dfs(state, v):
    key = (state, v)
    if key in dp: return dp[key]
    if state == ALL:
        dp[key] = res = get((v, start), INF)
        return res
    dp[key] = res = min((dfs(state | (1 << t), t) + d for t, d in g[v] if not state & (1 << t))) if state & to[v] != to[v] else INF
    return res
res = dfs(1, 0)
print res if res<INF else -1
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, T = map(int, readline().split())

AB= list(map(int, read().split()))
A = AB[0::2]
B = AB[1::2]
ls = sorted(zip(A, B))
#ls = list(zip(A, B))
# 食べるのにかかる時間で昇順にソート
#ls.sort()
# 上の並び順において、ls[i:]の美味しさの最大値をdeli[i]とする
deli = [0]*N
deli[- 1] = ls[-1][- 1]
for i in range(N - 2, 0, - 1):
    deli[i] = max(deli[i + 1], ls[i][- 1])

res = 0
dp = [0]*T
for i in range(N - 1):
    for j in range(T - 1, - 1, - 1):
        if ls[i][0] <= j:
            dp[j] = max(dp[j], dp[j - ls[i][0]] + ls[i][1])
    res = max(res, dp[- 1] + deli[i + 1])
print(res)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, T = map(int, readline().split())

AB= list(map(int, read().split()))
A = AB[0::2]
B = AB[1::2]
ls = list(zip(A, B))
# 食べるのにかかる時間で昇順にソート
ls.sort()
# 上の並び順において、ls[i:]の美味しさの最大値をdeli[i]とする
deli = [0]*N
deli[- 1] = ls[-1][- 1]
for i in range(N - 2, - 1, - 1):
    deli[i] = max(deli[i - 1], ls[i][- 1])

res = 0
dp = [0]*T
for i in range(N - 1):
    for j in range(T - 1, - 1, - 1):
        if ls[i][0] <= j:
            dp[j] = max(dp[j], dp[j - ls[i][0]] + ls[i][1])
    res = max(res, dp[- 1] + deli[i + 1])
print(res)
### BUGGY CODE ###

from sys import stdin
from collections import deque

n, d, a = (int(v) for v in stdin.readline().split())
monsters = [(int(v) for v in stdin.readline().split()) for i in range(n)]

monsters = [[x, (h // a + 1) if h % a > 0 else (h // a)] for x, h in monsters]
monsters = deque(sorted(monsters))
bomb_size = 2 * d + 1
num_bombs = 0

while len(monsters) > 0:
    while len(monsters) > 0 and monsters[0][1] <= 0:
        monsters.popleft()
    if len(monsters) > 0:
        position = monsters[0][0]
        bombs_now = monsters[0][1]
        i = 0
        while i < len(monsters) and monsters[i][0] - position < bomb_size:
            monsters[i][1] -= bombs_now
            i += 1
        num_bombs += bombs_now

print(num_bombs)

### FIXED CODE ###

from sys import stdin
from collections import deque

n, d, a = (int(v) for v in stdin.readline().split())
monsters = [(int(v) for v in line.split()) for line in stdin.readlines()]

monsters = [[x, (h // a + 1) if h % a > 0 else (h // a)] for x, h in monsters]
monsters = sorted(monsters)
bomb_size = 2 * d + 1
num_bombs = 0

current_bombs = 0
bomb_endpoints = deque()
bomb_endnumbers = deque()

for i in range(len(monsters)):
    while len(bomb_endpoints) > 0 and bomb_endpoints[0] <= monsters[i][0]:
        current_bombs -= bomb_endnumbers[0]
        bomb_endpoints.popleft()
        bomb_endnumbers.popleft()
    monsters[i][1] -= current_bombs
    if monsters[i][1] > 0:        
        bombs_now = monsters[i][1]
        monsters[i][1] = 0
        num_bombs += bombs_now
        current_bombs += bombs_now
        bomb_endpoints.append(monsters[i][0] + bomb_size)
        bomb_endnumbers.append(bombs_now)

print(num_bombs)
### BUGGY CODE ###

S = str(input())
s = len(S)
cnt = 0
A = []
for i in range(s):
  A.append(int(S[i:])%2019)

for i in range(s-1):
  for j in range(i+1,s):
    if (A[i]-A[j])%2019 == 0:
      cnt += 1
cnt += A.count(0)
print(cnt)

### FIXED CODE ###

S = str(input())
s = len(S)
cnt = 0
A = [0]*2019
r = 0
for i in range(s):
  x = (r+pow(10, i, 2019)*int(S[s-i-1]))%2019
  A[x] += 1
  r = x
  
for i in range(1,2019):
  if A[i] >= 2:
    cnt += A[i]*(A[i]-1)//2
cnt += A[0]*(A[0]+1)//2

print(cnt)
### BUGGY CODE ###

from functools import reduce
import operator
input()

result = reduce(operator.mul, [int(x) for x in input().split()], 1)
if result > 10 ** 18:
  print(-1)
else:
  print(result)

### FIXED CODE ###

input()

result = 1
a = [int(x) for x in input().split()]
if 0 in a:
  print(0)
  exit()

for x in a:
  if result > 10 ** 18:
    print(-1)
    exit()
  result *= x
  
if result > 10 ** 18:
  print(-1)
else:
  print(result)
### BUGGY CODE ###

n, m = map(int, input().split())
A = sorted(list(map(int, input().split())))
for i in range(m):
    b, c = map(int, input().split())
    for j in range(b):
        A[j] = max(A[j], c)
    A = sorted(A)
print(sum(A))

### FIXED CODE ###

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

bc = []
for i in range(m):
    b, c = map(int, input().split())
    bc.append([b,c])

from operator import itemgetter
bc.sort(key=itemgetter(1), reverse = True)
k = 0
c = bc[0][1]
b = bc[0][0]
bn = 0
while A[k] < c:
    A[k]=c
    k+=1
    if k == len(A):
        break
    b-=1
    if b  == 0:
        bn += 1
        if bn == len(bc):
            break
        b = bc[bn][0]
        c = bc[bn][1]
print(sum(A))
### BUGGY CODE ###

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

csA = A
for i in range(1, N+1):
    csA[i] = csA[i-1] + csA[i]
csB = B
for i in range(1, M+1):
    csB[i] = csB[i-1] + csB[i]

if csA[-1] + csB[-1] <= K:
    print(N+M)

else:
    
    ans = 0
               
    for i in range(N+1):
        wa = csA[i]
        numA = i
        if wa <= K:
            for j in range(M+1):
                numB = j
                wa += csB[j]
                if wa > K:
                    if numA + numB - 1 > ans:
                        ans = numA + numB - 1
                    break
                else:
                    wa = csA[i]
        else:
            break

    print(ans)

### FIXED CODE ###

import numpy as np
N, M, K = map(int, input().split())
A = np.cumsum([0] + list(map(int, input().split())))
B = np.cumsum([0] + list(map(int, input().split())))
ans = 0
j = M
for i in range(N+1):
  if A[i] > K:
    break
  while A[i] + B[j] > K:
    j -= 1
  ans = max(ans,i+j)
print(ans)
### BUGGY CODE ###

H,W,K=map(int,input().split())
s=[[int(x) for x in list(input())] for _ in range(H)]
ans = H*W
for h in range(2**(H-1)):
  parts = list()
  upper = 0
  cnt = 0
  for j in range(H-1):
    if h >> j & 1:
      cnt += 1
      parts.append([sum([s[y][x] for y in range(upper, j+1)]) for x in range(W)])
      upper = j+1
  parts.append([sum([s[y][x] for y in range(upper, H)]) for x in range(W)])
  # 貪欲
  summary = [0]*len(parts)
  for i in range(W):
    temp_sum = [summary[j] + parts[j][i] for j in range(len(parts))]
    for ts in temp_sum:
      if ts > K:
        cnt += 1
        summary = [parts[j][i] for j in range(len(parts))]
        break
    else:
      summary = temp_sum
  ans = min(ans, cnt)
print(ans)

### FIXED CODE ###

H,W,K=map(int,input().split())
s=[[int(x) for x in list(input())] for _ in range(H)]
ans = H*W
for h in range(2**(H-1)):
  parts = list()
  upper = 0
  cnt = 0
  inv_flg = 0
  for j in range(H-1):
    if h >> j & 1:
      cnt += 1
      appending = [sum([s[y][x] for y in range(upper, j+1)]) for x in range(W)]
      if any([x> K for x in appending]):
        inv_flg = 1
        break
      parts.append(appending)
      upper = j+1
  else:
    appending = [sum([s[y][x] for y in range(upper, H)]) for x in range(W)]
    if any([x > K for x in appending]):
      inv_flg = 1
    else:
      parts.append(appending)
  if inv_flg:
    continue
  # 貪欲
  summary = [0]*len(parts)
  for i in range(W):
    temp_sum = [summary[j] + parts[j][i] for j in range(len(parts))]
    for ts in temp_sum:
      if ts > K:
        cnt += 1
        summary = [parts[j][i] for j in range(len(parts))]
        break
    else:
      summary = temp_sum
  ans = min(ans, cnt)
print(ans)
### BUGGY CODE ###

mod = 10**9 + 7

S = input()[::-1]
N = len(S)

dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(13):
        if s == "?":
            for k in range(10):
                l = (j + k * pow(10,i,13)) % 13
                dp[i+1][l] += dp[i][j]
                dp[i+1][l] %= mod
        else:
            l = (j + (int(s) * pow(10,i,13))) % 13
            dp[i+1][l] += dp[i][j]
            dp[i+1][l] %= mod

ans = dp[N][5]
print(ans)

### FIXED CODE ###

mod = 10**9 + 7

S = input()
N = len(S)

dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(13):
        if s == "?":
            for k in range(10):
                l = (10*j + k) % 13
                dp[i+1][l] += dp[i][j]
                dp[i+1][l] %= mod
        else:
            l = (10*j + int(s)) % 13
            dp[i+1][l] += dp[i][j]
            dp[i+1][l] %= mod

ans = dp[N][5]
print(ans)