N = int(eval(input()))

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

count = 0

i = 0

while sum(h) > 0:

    if h[i] > 0:

        j = i

        count += 1

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

            h[j] = h[j] - 1

            j += 1

    else:

        i += 1

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

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

cnt = 0

i = 0

for _ in range(100 * 100):

    if h[i] > 0:

        j = i

        cnt += 1

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

            h[j] = h[j] - 1

            j += 1

    else:

        i += 1

        if i == N:

            break

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

N = int(eval(input()))
h = list(map(int, input().split()))
cnt = 0
i = 0
for _ in range(100 * 100):
    if h[i] > 0:
        j = i
        cnt += 1
        while j < N and h[j] > 0:
            h[j] = h[j] - 1
            j += 1
    else:
        i += 1
        if i == N:
            break
print(cnt)

-count = 0 +cnt = 0 -while sum(h) > 0: +for _ in range(100 * 100): -        count += 1 +        cnt += 1 -print(count) +        if i == N: +            break +print(cnt)