N = int(eval(input()))

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



ans = 0

for h_ref in range(1, 101):

    prev = 0

    for i, hi in enumerate(h):

        curr = int(hi >= h_ref)

        if curr > prev: ans += 1

        prev = curr



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

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



h += [0]

prev = 0

imos = [None] * (N + 1)

for i in range(N + 1):

    imos[i] = h[i] - prev

    prev = h[i]

    

# print("#", h)

# print("#", imos)

ans = sum([int(item > 0) * item for item in imos])

print(ans)
N = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
for h_ref in range(1, 101):
    prev = 0
    for i, hi in enumerate(h):
        curr = int(hi >= h_ref)
        if curr > prev:
            ans += 1
        prev = curr
print(ans)

N = int(eval(input()))
h = list(map(int, input().split()))
h += [0]
prev = 0
imos = [None] * (N + 1)
for i in range(N + 1):
    imos[i] = h[i] - prev
    prev = h[i]
# print("#", h)
# print("#", imos)
ans = sum([int(item > 0) * item for item in imos])
print(ans)

-ans = 0 -for h_ref in range(1, 101): -    prev = 0 -    for i, hi in enumerate(h): -        curr = int(hi >= h_ref) -        if curr > prev: -            ans += 1 -        prev = curr +h += [0] +prev = 0 +imos = [None] * (N + 1) +for i in range(N + 1): +    imos[i] = h[i] - prev +    prev = h[i] +# print("#", h) +# print("#", imos) +ans = sum([int(item > 0) * item for item in imos])