n = int(eval(input()))

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

ans = h[0]

for i in range(1,n):

    if h[i-1]<h[i]: ans += h[i]-h[i-1]

print(ans)
n = int(eval(input()))

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

ans = h[0]

for i in range(1,n):

    if h[i]>h[i-1]:ans+=h[i]-h[i-1]

print(ans)
n = int(eval(input()))
h = list(map(int, input().split()))
ans = h[0]
for i in range(1, n):
    if h[i - 1] < h[i]:
        ans += h[i] - h[i - 1]
print(ans)

n = int(eval(input()))
h = list(map(int, input().split()))
ans = h[0]
for i in range(1, n):
    if h[i] > h[i - 1]:
        ans += h[i] - h[i - 1]
print(ans)

-    if h[i - 1] < h[i]: +    if h[i] > h[i - 1]: