n = int(eval(input()))

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

ans = 0

size = sum(H)

while(size > 0):

    count = 0

    temp = 0

    for h in H:

        if(h == 0 and temp > 0):

            ans += 1

            break

        elif(h != 0):

            temp += 1

            H[count] -= 1

            size -= 1

            if(count == n-1):

                ans += 1

        count += 1

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

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

ans = 0

lst = 0

for h in H:

    if(h > lst):

        ans += h-lst

    lst = h



print(ans)
n = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
size = sum(H)
while size > 0:
    count = 0
    temp = 0
    for h in H:
        if h == 0 and temp > 0:
            ans += 1
            break
        elif h != 0:
            temp += 1
            H[count] -= 1
            size -= 1
            if count == n - 1:
                ans += 1
        count += 1
print(ans)

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

-size = sum(H) -while size > 0: -    count = 0 -    temp = 0 -    for h in H: -        if h == 0 and temp > 0: -            ans += 1 -            break -        elif h != 0: -            temp += 1 -            H[count] -= 1 -            size -= 1 -            if count == n - 1: -                ans += 1 -        count += 1 +lst = 0 +for h in H: +    if h > lst: +        ans += h - lst +    lst = h