## https://yukicoder.me/problems/no/944 from collections import deque def bisearch(N, D, f, low_index): if low_index == N: return N if D[-1] > f: return N low = low_index high = N - 1 while high - low > 1: mid = (high + low) //2 if D[mid] <= f: high = mid else: low = mid if D[low] <= f: return low else: return high def main(): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) D = list(map(int, input().split())) D.sort(reverse=True) queue = deque() queue.append((0, 0)) min_d_index = {(0, 0): -1} passed = [[False] * (N + 1) for _ in range(N + 1)] while len(queue) > 0: a_index, b_index = queue.popleft() if passed[a_index][b_index]: continue passed[a_index][b_index] = True d_index = min_d_index[(a_index, b_index)] if d_index == N - 1: continue # a_index + 1する new_a_index = a_index + 1 new_b_index = b_index f = A[new_a_index] + B[new_b_index] eat_index = bisearch(N, D, f, d_index + 1) if eat_index < N: key = (new_a_index, new_b_index) if key not in min_d_index: min_d_index[key] = 2 * N min_d_index[key] = min(min_d_index[key], eat_index) queue.append((new_a_index, new_b_index)) new_a_index = a_index new_b_index = b_index + 1 f = A[new_a_index] + B[new_b_index] eat_index = bisearch(N, D, f, d_index + 1) if eat_index < N: key = (new_a_index, new_b_index) if key not in min_d_index: min_d_index[key] = 2 * N min_d_index[key] = min(min_d_index[key], eat_index) queue.append((new_a_index, new_b_index)) answer = 0 for a, b in min_d_index.keys(): answer = max(answer, a + b) print(answer) if __name__ == "__main__": main()