N = int(eval(input()))

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

H.append(0)



t = 1

ans = 0

while t > 0:

    p = H[-1]

    t = 0

    for i in range(N):

        if H[i] > 0 and p <= 0:

            ans += 1

        p = H[i]

        H[i] -= 1

        t = max(H[i], t)

        #print(ans, H[i], t)



print(ans)

N = int(eval(input()))

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



ans = 0

pre = 0

for h in H:

    if pre < h:

        ans += h - pre



    pre = h



print(ans)

N = int(eval(input()))
H = list(map(int, input().split()))
H.append(0)
t = 1
ans = 0
while t > 0:
    p = H[-1]
    t = 0
    for i in range(N):
        if H[i] > 0 and p <= 0:
            ans += 1
        p = H[i]
        H[i] -= 1
        t = max(H[i], t)
        # print(ans, H[i], t)
print(ans)

N = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
pre = 0
for h in H:
    if pre < h:
        ans += h - pre
    pre = h
print(ans)

-H.append(0) -t = 1 -while t > 0: -    p = H[-1] -    t = 0 -    for i in range(N): -        if H[i] > 0 and p <= 0: -            ans += 1 -        p = H[i] -        H[i] -= 1 -        t = max(H[i], t) -        # print(ans, H[i], t) +pre = 0 +for h in H: +    if pre < h: +        ans += h - pre +    pre = h