N=int(eval(input()))

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



maxh=max(A)

ans=0

for i in range(1,maxh+1):

  # i 以上の高さのブロック数をカウントする

  block=0

  cur=False

  if A[0]>=i:

    block+=1

    cur=True

  for j in range(1,len(A)):

    if A[j]>=i:

      if not cur:

        block+=1

        cur=True

    else:

      cur=False

  ans+=block



print(ans)

N=int(eval(input()))

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

cur=0

ans=0

for i in range(N):

  if A[i]>cur:

    ans+=A[i]-cur

  cur=A[i]

print(ans)
N = int(eval(input()))
A = list(map(int, input().split()))
maxh = max(A)
ans = 0
for i in range(1, maxh + 1):
    # i 以上の高さのブロック数をカウントする
    block = 0
    cur = False
    if A[0] >= i:
        block += 1
        cur = True
    for j in range(1, len(A)):
        if A[j] >= i:
            if not cur:
                block += 1
                cur = True
        else:
            cur = False
    ans += block
print(ans)

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

-maxh = max(A) +cur = 0 -for i in range(1, maxh + 1): -    # i 以上の高さのブロック数をカウントする -    block = 0 -    cur = False -    if A[0] >= i: -        block += 1 -        cur = True -    for j in range(1, len(A)): -        if A[j] >= i: -            if not cur: -                block += 1 -                cur = True -        else: -            cur = False -    ans += block +for i in range(N): +    if A[i] > cur: +        ans += A[i] - cur +    cur = A[i]