import copy

n = int(eval(input()))

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



ans = 0

tmp = 0



for i in range(n):

    ans += h[i]

    tmp = copy.deepcopy(h)

    tmp_ = tmp[i]

    for j in range(i, n):

        if h[j] - tmp_ >= 0:

            h[j] -= tmp_

        else:

            tmp_ = tmp[j]

            h[j] = 0



print(ans)

n = int(eval(input()))

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



ans = 0

tmp = 0



for i in range(n):

    ans += h[i]

    tmp = int(h[i])

    for j in range(i, n):

        if h[j] - tmp >= 0:

            h[j] -= tmp

        else:

            tmp = int(h[j])

            h[j] = 0



print(ans)
import copy

n = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
tmp = 0
for i in range(n):
    ans += h[i]
    tmp = copy.deepcopy(h)
    tmp_ = tmp[i]
    for j in range(i, n):
        if h[j] - tmp_ >= 0:
            h[j] -= tmp_
        else:
            tmp_ = tmp[j]
            h[j] = 0
print(ans)

n = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
tmp = 0
for i in range(n):
    ans += h[i]
    tmp = int(h[i])
    for j in range(i, n):
        if h[j] - tmp >= 0:
            h[j] -= tmp
        else:
            tmp = int(h[j])
            h[j] = 0
print(ans)

-import copy - -    tmp = copy.deepcopy(h) -    tmp_ = tmp[i] +    tmp = int(h[i]) -        if h[j] - tmp_ >= 0: -            h[j] -= tmp_ +        if h[j] - tmp >= 0: +            h[j] -= tmp -            tmp_ = tmp[j] +            tmp = int(h[j])