import numpy as np

n = int(eval(input()))

h = np.array([0] + list(map(int, input().split())))

r = 0

while np.any(h>0):

    r += np.sum(np.logical_and(h[1:]>0, h[:-1]<=0))

    h -= 1

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

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

print((sum(max(0, h[i-1]-h[i]) for i in range(1, n)) + h[-1]))
import numpy as np

n = int(eval(input()))
h = np.array([0] + list(map(int, input().split())))
r = 0
while np.any(h > 0):
    r += np.sum(np.logical_and(h[1:] > 0, h[:-1] <= 0))
    h -= 1
print(r)

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

-import numpy as np - -h = np.array([0] + list(map(int, input().split()))) -r = 0 -while np.any(h > 0): -    r += np.sum(np.logical_and(h[1:] > 0, h[:-1] <= 0)) -    h -= 1 -print(r) +h = list(map(int, input().split())) +print((sum(max(0, h[i - 1] - h[i]) for i in range(1, n)) + h[-1]))