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

def solve():
    from bisect import bisect_left

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    M = max(A) + max(B)
    K = len(bin(M)) - 2
    mask = 1 << K
    k = K - 1
    T = 1 << k
    ans = 0
    while k >= 0:
        B = [x % mask for x in B]
        B.sort()
        bit = 0
        for a in A:
            a_ = a % mask
            T1 = bisect_left(B, T - a_)
            T2 = bisect_left(B, 2 * T - a_)
            T3 = bisect_left(B, 3 * T - a_)
            T4 = bisect_left(B, 4 * T - a_)
            bit += (T4 - T3) + (T2 - T1)
            bit &= 1
        ans += bit * (1 << k)
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    # from bisect import bisect_left
    import sys

    N = int(input())
    A = [int(x) for x in sys.stdin.readline().split()]
    B = [int(x) for x in sys.stdin.readline().split()]
    M = max(A) + max(B)
    K = len(bin(M)) - 2
    mask = (1 << K) - 1
    k = K - 1
    T = 1 << k
    ans = 0
    while k >= 0:
        for i in range(N):
            B[i] &= mask
            A[i] &= mask
        B = list(sorted(b & mask for b in B))
        A = list(sorted(a & mask for a in A))
        bit = 0
        T1, T2, T3 = 0, 0, 0
        for a in reversed(A):
            while T1 < N and a + B[T1] < T:
                T1 += 1
            while T2 < N and a + B[T2] < 2 * T:
                T2 += 1
            while T3 < N and a + B[T3] < 3 * T:
                T3 += 1
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()
### BUGGY CODE ###

T = list(input())

maxans = 0
ans = ''
def pdcount(t):
    return t.count('D') + t.count('PD')

tcnt = T.count('?')
for i in range(2**tcnt):
    L = []
    for j in range(tcnt):
        if (i >> j) &1 == 1:
            L.append('P')
        else:
            L.append('D')

    A = []
    pos = 0
    for k in range(len(T)):
        if T[k] == '?':
            A.append(L[pos])
            pos += 1
        else:
            A.append(T[k])
    
    if pdcount(''.join(A)) > maxans:
        ans = ''.join(A)
        maxans = pdcount(''.join(A))
print(ans)

### FIXED CODE ###

t = input()
print(t.replace('?', 'D'))
### BUGGY CODE ###

import sys
import math
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
aint = lambda: int(input())
ints = lambda: list(map(int, input().split()))
is_even = lambda x: True if x%2==0 else False

n = aint()
get = [[],[],[],[],[],[],[],[],[],[]]
ans = 0
for i in range(n):
    s = input()
    if s not in get[len(s)-1]:
        get[len(s)-1].append(s)
        ans += 1
print(ans)

### FIXED CODE ###

import sys
import math
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
aint = lambda: int(input())
ints = lambda: list(map(int, input().split()))
is_even = lambda x: True if x%2==0 else False

n = aint()
get = []
for i in range(n):
    s = input()
    get.append(s)
ss = set(get)
print(len(ss))
### BUGGY CODE ###

class BTree:
    def __init__(self):
        self.value = "ZZZ"
        self.left = None
        self.right = None

    def insert(self, s):
        if self.value is "ZZZ":
            self.value = s
        else:
            if self.value < s:
                if self.right is None:
                    self.right = BTree().insert(s)
                else:
                    self.right = self.right.insert(s)
            elif s < self.value:
                if self.left is None:
                    self.left = BTree().insert(s)
                else:
                    self.left = self.left.insert(s)
        return self

    def find(self, s):
        if self.value == s:
            return True
        elif self.value < s:
            if self.right is None:
                return False
            else:
                return self.right.find(s)
        else:
            if self.left is None:
                return False
            else:
                return self.left.find(s)


n = int(input())
tree = BTree()
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        tree = tree.insert(command[1])
    elif command[0] == "find":
        if tree.find(command[1]):
            print("yes")
        else:
            print("no")


### FIXED CODE ###

n = int(input())
data = set()
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        data.add(command[1])
    elif command[0] == "find":
        if command[1] in data:
            print("yes")
        else:
            print("no")
### BUGGY CODE ###

S=input()
count=0
end=0
while "BW" in S:
    i=S.count("BW")
    #i=S.find("BW") + 1
    S=S.replace("BW","WB",i)
    #count+=i-end
    count+=i
    #end+=1
print(count)

### FIXED CODE ###

S=input()
count=0
def sigma(i):
    a=[b for b in range(0,i+1)]
    return sum(a)
place=0
flag=0
start=0
for i in range(len(S)):
    if S[i]=="B":
        flag=1
    elif S[i]=="W":
        if flag == 1:
            count += 1
            place += i - start
        else:
            start+=1
ans=place-sigma(count-1)
print(ans)
### BUGGY CODE ###

def popcount(x):
    ans = 0   
    while x > 0:
        if x & 1:
            ans += 1
        x >>= 1
    return ans
              
def f(x, pc, memo=None):
    if memo and (x, pc) in memo:
        return memo[(x, pc)]
    r = x % pc
    if memo:  
        memo[(x, pc)] = r
    return r  
              
N = int(input())
X = input()   
              
x = int(X, 2) 
              
memo = {}     
pc_x = X.count('1')
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
    else:     
        pc = pc_x + 1
    if pc == 0:
        print('0')
        continue
    f_x = f(x, pc, memo)
    f_res = f(pow(2, (N-i-1), pc), pc, memo)
    if X[i] == '1':
        f_i = f_x - f_res
    else:     
        f_i = f_x + f_res
    f_i = (f_i + 2 * pc) % pc
    ans = 1   
    while f_i > 0:
        ans += 1
        pc = popcount(f_i)
        f_i = f(f_i, pc)
    print(ans)


### FIXED CODE ###

N = int(input())
X = input()   
              
x_val = int(X, 2)
pc_x = X.count('1')
              
x_mod_pc_x_plus_1 = x_val % (pc_x + 1)
x_mod_pc_x_minus_1 = x_val % max(pc_x - 1, 1)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
        if pc == 0:
            print(0)
            continue
        val = (x_mod_pc_x_minus_1 - pow(2, N-i-1, pc)) % pc
    else:     
        pc = pc_x + 1
        val = (x_mod_pc_x_plus_1 + pow(2, N-i-1, pc)) % pc
    ans = 1   
    while val > 0:
        val %= bin(val).count('1')
        ans += 1
    print(ans)
### BUGGY CODE ###

import copy
N,M=map(int,input().split())
linked=[set() for i in range(N)]
for i in range(M):
  s,t=map(int,input().split())
  linked[s-1].add(t-1)
def dp(link):
  dp=[0]*N
  for i in range(N-1):
    k=N-2-i
    size=len(link[k])
    if size==0:
      continue
    p=1/size
    v=0
    for t in link[k]:
      v=v+p*(dp[t]+1)
    dp[k]=v
  return dp
all_dp=dp(linked)
ans=all_dp[0]
for i in range(N-1):
  if len(linked[i])<2:
    continue
  cut=0
  v=0
  for t in linked[i]:
    if v<all_dp[t]:
      cut=t
      v=all_dp[t]
  s=linked[i].copy()
  s.remove(cut)
  link=copy.deepcopy(linked)
  link[i]=s
  d=dp(link)
  ans=min(ans,d[0])
print(ans)

### FIXED CODE ###

import copy
N,M=map(int,input().split())
linked=[set() for i in range(N)]
for i in range(M):
  s,t=map(int,input().split())
  linked[s-1].add(t-1)
def dp(link):
  dp=[0]*N
  for i in range(N-1):
    k=N-2-i
    size=len(link[k])
    if size==0:
      continue
    p=1/size
    v=0
    for t in link[k]:
      v=v+p*(dp[t]+1)
    dp[k]=v
  return dp
all_dp=dp(linked)
ans=all_dp[0]
for i in range(N-1):
  if len(linked[i])<2:
    continue
  cut=0
  v=0
  for t in linked[i]:
    if v<all_dp[t]:
      cut=t
      v=all_dp[t]
  linked[i].remove(cut)
  d=dp(linked)
  ans=min(ans,d[0])
  linked[i].add(cut)
print(ans)
### BUGGY CODE ###

n,m,*a=map(int,open(0).read().split())
dp=[0]*(n+2)
dp[0]=1
div=1000000007
for i in range(n):
  dp[i]%=div
  if i+1 in a:
    dp[i+1]=0
  else:
    dp[i+1]+=dp[i]
  if i+2 in a:
    dp[i+2]=0
  else:
    dp[i+2]+=dp[i]
print(dp[n]%div)

### FIXED CODE ###

n,m=map(int,input().split())
broken=[False]*(n+1)
for i in range(m):
  broken[int(input())]=True
dp=[0]*(n+1)
dp[0]=1
dp[1]=0 if broken[1] else 1

for i in range(2,len(dp)):
  if broken[i]:
    dp[i]=0
  else:
    dp[i]=(dp[i-2]+dp[i-1])%1000000007
  
print(dp[-1])
### BUGGY CODE ###

n = int(input())
s = [str(input()) for i in range(n)]
dic = {}
m = 1
for a in s:
    if not a in dic:
        dic[a] = 1
    else:
        dic[a] += 1
        cnt = dic[a]
        m = max(m, cnt)
l = []
for a in s:
    if not a in l and dic[a] == m:
        l.append(a)
l.sort()
for i in range(len(l)):
    print(l[i])

### FIXED CODE ###

n = int(input())
s = [str(input()) for i in range(n)]
dic = {}
m = 1
for a in s:
    if not a in dic:
        dic[a] = 1
    else:
        dic[a] += 1
        cnt = dic[a]
        m = max(m, cnt)
se = set()
for a in s:
    if dic[a] == m:
        se.add(a)
l = ['a'] * len(se)
for i in range(len(se)):
    l[i] = se.pop()
l.sort()
for i in range(len(l)):
    print(l[i])
### BUGGY CODE ###

n = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(len(P)):
  if min(P[0:i+1]) == P[i]:
    ans += 1
  else:
    pass

print(ans)

### FIXED CODE ###

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

ans = 0
tmp = P[0]
for i in range(n):
  if P[i] <= tmp:
    ans += 1
    tmp = P[i]
  else:
    pass
print(ans)
### BUGGY CODE ###

from sys import stdin, stdout
def main():
    N=int(stdin.readline())
    S=stdin.readline().rstrip()
    R, G, B = [], [], []
    for i, c in enumerate(S):
        if c == 'R':
            R.append(i)
        elif c == 'G':
            G.append(i)
        else:
            B.append(i)
    cnt = 0
    R.sort()
    G.sort()
    B.sort()
    seen=set()
    for ri in R:
        for gi in G:
            for bi in B:
                if abs(gi-ri) != abs(bi-gi) and abs(ri-bi) != abs(bi-gi) and abs(ri-bi) != abs(ri-gi):
                    cnt+=1

    stdout.write(str(cnt)+"\n")

main()


### FIXED CODE ###

from sys import stdin, stdout
def main():
    N=int(stdin.readline())
    S=stdin.readline().rstrip()
    R, G, B = set(), set(), set()
    for i, c in enumerate(S):
        if c == 'R':
            R.add(i)
        elif c == 'G':
            G.add(i)
        else:
            B.add(i)
    cnt, total = 0, len(R) * len(G) * len(B)
    for ri in R:
        for gi in G:
            if abs(ri-gi)+gi in B:
                cnt += 1
            if abs(ri-gi)+ri in B:
                cnt += 1
    for ri in G:
        for gi in B:
            if abs(ri-gi)+gi in R:
                cnt += 1
            if abs(ri-gi)+ri in R:
                cnt += 1
    for ri in R:
        for gi in B:
            if abs(ri-gi)+gi in G:
                cnt += 1
            if abs(ri-gi)+ri in G:
                cnt += 1

    stdout.write(str(total-cnt)+"\n")

main()
### BUGGY CODE ###

num = int(input())
for i in range(num):
    X = " " + input()
    Y = " " + input()
    lx = len(X)
    ly = len(Y)
    T = [0] * ly
    for j in range(1,lx):
        C = T[:]
        for k in range(1,ly):
            k1 = k-1
            if X[j] == Y[k]:
                T[k] = C[k1] + 1
            elif C[k] > T[k1]:
                T[k] = C[k]
            else:
                T[k] = T[k1]
    print(T[k])

### FIXED CODE ###

def main():
    num = int(input())
    A = []
    for i in range(num):
        X = input()
        Y = " " + input()
        lx = len(X)
        ly = len(Y)
        T = [0] * ly
        for j in range(lx):
            xj = X[j]
            C = T[:]
            for k in range(1,ly):
                k1 = k-1
                if xj == Y[k]:
                    T[k] = C[k1] + 1
                elif T[k] < T[k1]:
                    T[k] = T[k1]
        print(T[k])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

#C Monsters Battle Rpyale

N = int(input())
monster_life_lst = list(map(int, input().split()))
flag = False 
while True:
    monster_life_lst.sort()
    if len(monster_life_lst) == 1:
        flag = True
        out_flag = monster_life_lst[0]
        break
    else:
        monster_life_lst[1] -= monster_life_lst[0]
        if monster_life_lst[1] == 0:
            monster_life_lst.remove(0)

def out(out_flag):
    print(out_flag)

out(out_flag)

### FIXED CODE ###

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


while True:
    while 0 in monster_life_lst:
        monster_life_lst.remove(0)
    monster_life_lst.sort()
    for i in range(1, len(monster_life_lst)):
        monster_life_lst[i] = monster_life_lst[i] % monster_life_lst[0]
    if len(monster_life_lst) == 1:
        out_flag = monster_life_lst[0]
        break

def out(out_flag):
    print(out_flag)

out(out_flag)
### BUGGY CODE ###

n=int(input())
s=list(input())
d={}
ans=0
for i in range(0,10):
  for x in range(0,n-2):
    if s[x]==str(i):
      
      for j in range(0,10):
        for y in range(x+1,n-1):
          if s[y]==str(j):
           
          
            for k in range(0,10):
              for z in range(y+1,n):
                if s[z]==str(k):
                  v=str(i)+str(j)+str(k)
                  v1=int(v)
                  if v1 not in d:
                    d[v1]=0
                    ans+=1
                  
print(ans)

### FIXED CODE ###

n=int(input())
s=list(input())
d={}
ans=0
for x in range(n-2):
  if s[x] not in d:
    d[s[x]]=0
    for y in range(x+1,n-1):
      if (s[x]+s[y]) not in d:
        d[(s[x]+s[y])]=0
        for z in range(y+1,n):
          if (s[x]+s[y]+s[z]) not in d:
            d[(s[x]+s[y]+s[z])]=0
            ans+=1
    
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math
    
N, K = mi()
A = li()

#light = [0] * (N+2)
#A = [0] + A + [0]
#print(math.log(N, 2))
'''
thre = 0
for i in range(N):
    if A[i] < i:
        thre = max(thre, i-A[i])
'''
if K > pow(N, 0.5) + 1:
        for i in range(N):
            print(N, '', end='')
        print()
        exit()


for i in range(K):
    new = [0] * (N+1)
    for j in range(N):
        new[max(j-A[j], 0)] += 1
        new[min(j+A[j]+1, N)] += -1
        #print(new)
    new = list(accumulate(new))
    A = new[:N]

for i in range(N):
    print(A[i], '', end='')
print()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))
import math
    
N, K = mi()
A = li()
 
#light = [0] * (N+2)
#A = [0] + A + [0]
#print(math.log(N, 2))
'''
thre = 0
for i in range(N):
    if A[i] < i:
        thre = max(thre, i-A[i])
'''
if K > pow(N, 0.5) + 1:
        for i in range(N):
            print(N, '', end='')
        print()
        exit()
 
 
for i in range(K):
    new = [0] * (N+1)
    for j in range(N):
        new[max(j-A[j], 0)] += 1
        new[min(j+A[j]+1, N)] += -1
        #print(new)
    new = list(accumulate(new))
    A = new[:N]
 
for i in range(N):
    print(A[i], '', end='')
print()
### BUGGY CODE ###

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

oder = min(S[1:].count('E'), S[:-1].count('W'))

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

print(oder)


### FIXED CODE ###

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

oder = N
l = [0 for _ in range(N)]
r = [0 for i in range(N)]

for i in range(1, N):
  l[i] = l[i-1] + (S[i-1] == 'W')
  r[-i-1] = r[-i] + (S[-i] == 'E')

for i in range(N):
  oder = min(oder, l[i]+r[i])

print(oder)
### BUGGY CODE ###

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

for i in range(1, n):
  if h[i] < max(h[:i])-1:
    print("No")
    exit(0)
print("Yes")

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
   
h_max = h[0]
for i in range(1, n):
  if h[i-1] > h_max:
    h_max = h[i-1]
  if h[i] < h_max -1:
    print("No")
    exit(0)
print("Yes")
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def factorization(n):

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

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

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

    return arr


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

    result = 0

    for a in A:
        fact = factorization(a)[0]
        if fact[0] == 2:
            result += fact[1]
    print(result)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def div_two(num):
    cnt = 0
    while num % 2 == 0:
        num = num // 2
        cnt += 1
    return cnt


def main():
    N = int(input())

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

    print(sum(div_two(i) for i in A))


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


import sys
input = lambda : sys.stdin.readline().rstrip()

# 小さすぎても怒られるので
from collections import defaultdict
n = int(input())
sys.setrecursionlimit(max(1000, 2*n))

cs = [0] + [int(c) for c in input().split()]
ns = defaultdict(set)
for _ in range(n-1):
    a,b = [int(c) for c in input().split()]
    ns[a].add(b)
    ns[b].add(a)

def dfs(ns, prev, now, toru, results):
    end = defaultdict(int)
    k = cs[now]
    end[k] = 1
    s = 1 # nowで終わるパスの種類
    for u in ns[now]:
        if u==prev:
            continue
        tmp_end, tmp_toru, tmp_s = results[u]  # dfs(ns, now, u, toru)
        # toruの更新
        for kk, vv in tmp_end.items():
            if kk not in end:
                toru[kk] += vv * s
            else:
                toru[kk] += vv * s + end[kk] * (tmp_s+1) - ((vv+1) * end[kk])
        for kk, vv in end.items():
            if kk not in tmp_end:
                toru[kk] += vv * tmp_s
        # end, sの更新
        end[k] += tmp_s
        for kk,vv in tmp_end.items():
            if k!=kk:
                end[kk] += tmp_end[kk]
        s += tmp_s
    toru[k] += 1
#     print(now, prev, end, toru, s)
    results[now] = end, toru, s

toru = [0] * (n+1)
q = [(1, -1)] # now, prev
args = []
while q:
    u, prev = q.pop()
    args.append((u,prev))
    for v in ns[u]:
        if prev==v:
            continue
        q.append((v, u))
results = {}
for arg in args[::-1]:
    dfs(ns, arg[1], arg[0], toru, results)

for item in toru[1:]:
    print(item)

### FIXED CODE ###


import sys
# 小さすぎても怒られるので
from collections import defaultdict
n = int(input())
sys.setrecursionlimit(max(1000, 2*n))

cs = [0] + [int(c) for c in input().split()]
ns = defaultdict(set)
for _ in range(n-1):
    a,b = [int(c) for c in input().split()]
    ns[a].add(b)
    ns[b].add(a)

ans = [0] * (n+1) # kを通らないパスの総数
minus = [0] * (n+1) # uの部分木のうち
minus0 = defaultdict(int)
st = {k: [] for k in range(1, n+1)}
nextu = {}
def dfs(u, prev, ans):
    global minus, st, minus0
    k = cs[u]
    st[k].append(u)
    ss = 1
    for v in ns[u]:
        if v==prev:
            continue
        nextu[u] = v
        s = dfs(v, u, ans)
        ss += s
        tmp = s - minus[v]
        ans[k] += (int(tmp * (tmp - 1) / 2) + tmp)
    st[k].pop()
    if st[k]:
        minus[nextu[st[k][-1]]] += ss
    else:
        minus0[k] += ss
#     print(ss)
    return ss

dfs(1, -1, ans)
for k in range(1, n+1):
    tmp = n - minus0[k]
    ans[k] += (int(tmp * (tmp - 1) / 2) + tmp)
    
total = int(n * (n+1) / 2)
for i in range(1, n+1):
    print(total - ans[i])
### BUGGY CODE ###

import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans


n, m,k  = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa  = [0]
pb = [0]
ans = 0
for i in range(n):
    pa.append(a[i]+pa[i])
for i in range(m):
    pb.append(b[i]+pb[i])
for c in range(n+1):
    tmp=pa[c]
    if(tmp > k):
        break
    else:
        for d in range(m+1):
            if(pb[d] <= k-tmp):
                ans = max(ans, c+d)
            else:
                break
print(ans)

### FIXED CODE ###

import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans


n, m,k  = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa  = [0]
pb = [0]
ans = 0
for i in range(n):
    pa.append(a[i]+pa[i])
for i in range(m):
    pb.append(b[i]+pb[i])
for c in range(n+1):
    if(pa[c] > k):
        break
    else:
        while(pb[m] > k-pa[c]):
            m-=1
        ans = max(ans, c+m)
            
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9+7
dp=[INF]*n
dp[0]=0

for i in range(1,n):
    s=min(k,i)
    for j in range(1,s+1):
        dp[i]=min(dp[i],abs(h[i]-h[i-j])+dp[i-j])
print(dp[n-1])

### FIXED CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9+7
dp=[INF]*n
dp[0]=0

for i in range(1,n):
    s=min(k,i)
    for j in range(1,s+1):
        dp[i]=min(dp[i],abs(h[i]-h[i-j])+dp[i-j])
print(dp[n-1])
### BUGGY CODE ###

n,k = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
l,r = 0, 10**18
if sum(A)<=k:
    print(0)
else:
    while r-l!=1:
        mid = (r+l)//2
        ex = 0
        for i in range(n):
            need = mid // F[i]
            ex += max(0, A[i]-need)
        if ex <= k:
            r = mid
        else:
            l = mid
    print(r)

### FIXED CODE ###

n,k = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
l,r = 0, 10**18
if sum(A)<=k:
    print(0)
else:
    while r-l!=1:
        mid = (r+l)//2
        ex = 0
        for i in range(n):
            need = mid // F[i]
            ex += max(0, A[i]-need)
        if ex <= k:
            r = mid
        else:
            l = mid
    print(r)