N = int(eval(input()))

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

count = 0

while(h.count(0)!=N):

    for k in range(N):

        if h[k]!=0:

            break

    for j in range(k,N):

        if h[j]==0:

            j-=1

            break

    for i in range(k,j+1):

        h[i]-=1

    count+=1

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

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

count = h[0]

x = h[0]

for i in range(N):

  if x<h[i]:

    count+=h[i]-x

  x = h[i]

print(count)

N = int(eval(input()))
h = list(map(int, input().split()))
count = 0
while h.count(0) != N:
    for k in range(N):
        if h[k] != 0:
            break
    for j in range(k, N):
        if h[j] == 0:
            j -= 1
            break
    for i in range(k, j + 1):
        h[i] -= 1
    count += 1
print(count)

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

-count = 0 -while h.count(0) != N: -    for k in range(N): -        if h[k] != 0: -            break -    for j in range(k, N): -        if h[j] == 0: -            j -= 1 -            break -    for i in range(k, j + 1): -        h[i] -= 1 -    count += 1 +count = h[0] +x = h[0] +for i in range(N): +    if x < h[i]: +        count += h[i] - x +    x = h[i]