N = int(eval(input()))

h = [int(x) for x in input().split()]



ans = 0

sum_height = sum(h)

while sum_height > 0:

    i = 0

    while i < N:

        while i < N and h[i] == 0:

            i += 1

        if i < N:

            ans += 1

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

            h[i] -= 1

            sum_height -= 1

            i += 1



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

h = [int(x) for x in input().split()]



ans = 0

sum_height = sum(h)

while sum_height > 0:

    for i in range(N):

        if h[i] == 0:

            pos = False

            continue

        elif (i == 0 and h[i] > 0) or (i > 0 and not pos):

            ans += 1

        h[i] -= 1

        sum_height -= 1

        pos = True



print(ans)

N = int(eval(input()))
h = [int(x) for x in input().split()]
ans = 0
sum_height = sum(h)
while sum_height > 0:
    i = 0
    while i < N:
        while i < N and h[i] == 0:
            i += 1
        if i < N:
            ans += 1
        while i < N and h[i] > 0:
            h[i] -= 1
            sum_height -= 1
            i += 1
print(ans)

N = int(eval(input()))
h = [int(x) for x in input().split()]
ans = 0
sum_height = sum(h)
while sum_height > 0:
    for i in range(N):
        if h[i] == 0:
            pos = False
            continue
        elif (i == 0 and h[i] > 0) or (i > 0 and not pos):
            ans += 1
        h[i] -= 1
        sum_height -= 1
        pos = True
print(ans)

-    i = 0 -    while i < N: -        while i < N and h[i] == 0: -            i += 1 -        if i < N: +    for i in range(N): +        if h[i] == 0: +            pos = False +            continue +        elif (i == 0 and h[i] > 0) or (i > 0 and not pos): -        while i < N and h[i] > 0: -            h[i] -= 1 -            sum_height -= 1 -            i += 1 +        h[i] -= 1 +        sum_height -= 1 +        pos = True