n = int(eval(input()))

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



c = 0

while any(h):

    ans = 0

    for l in range(n):

        tmp = 0

        r = l

        while h[r]:

            tmp += 1

            r += 1

            if r == n:

                break

        if ans < tmp:

            x = l

            y = r

            ans = tmp

    for i in range(x, y):

        h[i] -= 1

    c += 1

print(c)

n = int(eval(input()))

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

ans = h[0]

for i in range(n-1):

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



print(ans)

n = int(eval(input()))
h = list(map(int, input().split()))
c = 0
while any(h):
    ans = 0
    for l in range(n):
        tmp = 0
        r = l
        while h[r]:
            tmp += 1
            r += 1
            if r == n:
                break
        if ans < tmp:
            x = l
            y = r
            ans = tmp
    for i in range(x, y):
        h[i] -= 1
    c += 1
print(c)

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

-c = 0 -while any(h): -    ans = 0 -    for l in range(n): -        tmp = 0 -        r = l -        while h[r]: -            tmp += 1 -            r += 1 -            if r == n: -                break -        if ans < tmp: -            x = l -            y = r -            ans = tmp -    for i in range(x, y): -        h[i] -= 1 -    c += 1 -print(c) +ans = h[0] +for i in range(n - 1): +    ans += max(h[i + 1] - h[i], 0) +print(ans)