n=int(eval(input()))

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

ans=0

while sum(h)>0:

    i=0

    while i < n:

        if h[i]>0:

            ans+=1    

            while i<n and h[i]>0:

                h[i]-=1

                i+=1

        i+=1

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

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

ans=0

pre=0

for hi in h:

  if hi-pre>0:

    ans+=hi-pre

  pre=hi

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

n = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
pre = 0
for hi in h:
    if hi - pre > 0:
        ans += hi - pre
    pre = hi
print(ans)

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