n = int(eval(input()))

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

ans = 0

co = 0

for i in range(n):

    while lis[i] != 0:

        cou = i

        while lis[cou] > 0:

            lis[cou] -= 1

            cou += 1

            if cou == n:

                break

        ans += 1

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

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

ans = 0

status = 0

for high in range(1,101):

    for i in range(n):

        if lis[i] >= high:

            status = 1

        else:

            if status == 1:

                ans += 1

                status = 0

    ans += status

    status = 0

print(ans)
n = int(eval(input()))
lis = list(map(int, input().split()))
ans = 0
co = 0
for i in range(n):
    while lis[i] != 0:
        cou = i
        while lis[cou] > 0:
            lis[cou] -= 1
            cou += 1
            if cou == n:
                break
        ans += 1
print(ans)

n = int(eval(input()))
lis = list(map(int, input().split()))
ans = 0
status = 0
for high in range(1, 101):
    for i in range(n):
        if lis[i] >= high:
            status = 1
        else:
            if status == 1:
                ans += 1
                status = 0
    ans += status
    status = 0
print(ans)

-co = 0 -for i in range(n): -    while lis[i] != 0: -        cou = i -        while lis[cou] > 0: -            lis[cou] -= 1 -            cou += 1 -            if cou == n: -                break -        ans += 1 +status = 0 +for high in range(1, 101): +    for i in range(n): +        if lis[i] >= high: +            status = 1 +        else: +            if status == 1: +                ans += 1 +                status = 0 +    ans += status +    status = 0