N = int(eval(input()))

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



H.append(0)

cnt = 0

for i in range(N + 1):

    cnt += max(H[i] - H[i - 1], 0)





print(cnt)
N = int(eval(input()))

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



H = [0] + H

cnt = 0

for i in range(1, N + 1):

    cnt += max(H[i] - H[i - 1], 0)





print(cnt)
N = int(eval(input()))
H = list(map(int, input().split()))
H.append(0)
cnt = 0
for i in range(N + 1):
    cnt += max(H[i] - H[i - 1], 0)
print(cnt)

N = int(eval(input()))
H = list(map(int, input().split()))
H = [0] + H
cnt = 0
for i in range(1, N + 1):
    cnt += max(H[i] - H[i - 1], 0)
print(cnt)

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