N = int(eval(input()))

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

board = [[0] * (N + 1) for _ in range(max(h))]

for i in range(N):

    for j in range(h[i]):

        board[j][i + 1] = 1

print((sum(row[i] == 0 and row[i + 1] == 1 for row in board for i in range(N))))

eval(input())

ans, tmp = 0, 0

for h in map(int, input().split()):

    ans += max(0, h - tmp)

    tmp = h

print(ans)

N = int(eval(input()))
h = list(map(int, input().split()))
board = [[0] * (N + 1) for _ in range(max(h))]
for i in range(N):
    for j in range(h[i]):
        board[j][i + 1] = 1
print((sum(row[i] == 0 and row[i + 1] == 1 for row in board for i in range(N))))

eval(input())
ans, tmp = 0, 0
for h in map(int, input().split()):
    ans += max(0, h - tmp)
    tmp = h
print(ans)

-N = int(eval(input())) -h = list(map(int, input().split())) -board = [[0] * (N + 1) for _ in range(max(h))] -for i in range(N): -    for j in range(h[i]): -        board[j][i + 1] = 1 -print((sum(row[i] == 0 and row[i + 1] == 1 for row in board for i in range(N)))) +eval(input()) +ans, tmp = 0, 0 +for h in map(int, input().split()): +    ans += max(0, h - tmp) +    tmp = h +print(ans)