n = int(eval(input()))

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



ans=0



for i in range(max(h_input)):

    x = h_input[:]

    for j in range(n):

        if j==0 and x[0]!=0:#左端

            ans+=1

            h_input[j]-=1

        if j!=0:

            if x[j-1]==0 and x[j]!=0:#探索の左が0でかつ自身が0になっていない解き

                ans+=1

            if x[j]!=0:

                h_input[j]-=1

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

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



ans = 0

tmp = 0

max_h = max(H)

for i in range(max_h,0,-1):

    H_c = H.copy()

    if H[0]==i:

        ans+=1

        H_c[0]-=1

    for j in range(1,n):

        if H[j]==i:

            if H[j-1]!=H[j]:

                ans+=1

                H_c[j]-=1

            else:

                H_c[j]-=1

    H = H_c

print(ans)
n = int(eval(input()))
h_input = list(map(int, input().split()))
ans = 0
for i in range(max(h_input)):
    x = h_input[:]
    for j in range(n):
        if j == 0 and x[0] != 0:  # 左端
            ans += 1
            h_input[j] -= 1
        if j != 0:
            if x[j - 1] == 0 and x[j] != 0:  # 探索の左が0でかつ自身が0になっていない解き
                ans += 1
            if x[j] != 0:
                h_input[j] -= 1
print(ans)

n = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
tmp = 0
max_h = max(H)
for i in range(max_h, 0, -1):
    H_c = H.copy()
    if H[0] == i:
        ans += 1
        H_c[0] -= 1
    for j in range(1, n):
        if H[j] == i:
            if H[j - 1] != H[j]:
                ans += 1
                H_c[j] -= 1
            else:
                H_c[j] -= 1
    H = H_c
print(ans)

-h_input = list(map(int, input().split())) +H = list(map(int, input().split())) -for i in range(max(h_input)): -    x = h_input[:] -    for j in range(n): -        if j == 0 and x[0] != 0:  # 左端 -            ans += 1 -            h_input[j] -= 1 -        if j != 0: -            if x[j - 1] == 0 and x[j] != 0:  # 探索の左が0でかつ自身が0になっていない解き +tmp = 0 +max_h = max(H) +for i in range(max_h, 0, -1): +    H_c = H.copy() +    if H[0] == i: +        ans += 1 +        H_c[0] -= 1 +    for j in range(1, n): +        if H[j] == i: +            if H[j - 1] != H[j]: -            if x[j] != 0: -                h_input[j] -= 1 +                H_c[j] -= 1 +            else: +                H_c[j] -= 1 +    H = H_c