N = int(eval(input()))

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

h = [0] + h

ans = 0



while(sum(h)>0):

    for i in range(N):     

        if h[i] == 0 and h[i+1] > 0:

            ans += 1

    for i in range(N+1):

        if h[i] > 0:

            h[i] -= 1

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

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

h = [0] + h

ans = 0



for i in range(N):

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

        ans += h[i+1]-h[i]

print(ans)

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

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

-while sum(h) > 0: -    for i in range(N): -        if h[i] == 0 and h[i + 1] > 0: -            ans += 1 -    for i in range(N + 1): -        if h[i] > 0: -            h[i] -= 1 +for i in range(N): +    if h[i] < h[i + 1]: +        ans += h[i + 1] - h[i]