N = int(eval(input()))

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



ans = 0

i = 0

while i < N:

    while h[i] == 0:

        i += 1

        if i == N: break

    j = i

    if i == N: break

    while h[j] > 0:

        h[j] -= 1

        j += 1

        if j == N: break

    ans += 1



print(ans)

n = int(eval(input()))

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



ans = 0

cur = 0

for hh in h:

    if cur < hh:

        ans += hh - cur

        cur = hh

    else:

        cur = hh

print(ans)

N = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
i = 0
while i < N:
    while h[i] == 0:
        i += 1
        if i == N:
            break
    j = i
    if i == N:
        break
    while h[j] > 0:
        h[j] -= 1
        j += 1
        if j == N:
            break
    ans += 1
print(ans)

n = int(eval(input()))
h = tuple(map(int, input().split()))
ans = 0
cur = 0
for hh in h:
    if cur < hh:
        ans += hh - cur
        cur = hh
    else:
        cur = hh
print(ans)

-N = int(eval(input())) -h = list(map(int, input().split())) +n = int(eval(input())) +h = tuple(map(int, input().split())) -i = 0 -while i < N: -    while h[i] == 0: -        i += 1 -        if i == N: -            break -    j = i -    if i == N: -        break -    while h[j] > 0: -        h[j] -= 1 -        j += 1 -        if j == N: -            break -    ans += 1 +cur = 0 +for hh in h: +    if cur < hh: +        ans += hh - cur +        cur = hh +    else: +        cur = hh