N=int(eval(input()))

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

c=i=0

while sum(h)>0:

  if h[i]>0:

    j=i

    c+=1

    while j<N and h[j]>0:

      h[j]-=1

      j+=1

  else:

    i+=1

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

h=[0]+list(map(int,input().split()))

c=0

for i in range(N):

  c+=max(h[i+1]-h[i],0)

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

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

-h = list(map(int, input().split())) -c = i = 0 -while sum(h) > 0: -    if h[i] > 0: -        j = i -        c += 1 -        while j < N and h[j] > 0: -            h[j] -= 1 -            j += 1 -    else: -        i += 1 +h = [0] + list(map(int, input().split())) +c = 0 +for i in range(N): +    c += max(h[i + 1] - h[i], 0)