import numpy as np

N = int(eval(input()))

hlist = np.array([_ for _ in map(int,input().split())])



max = np.max(hlist)

min = np.min(hlist)



newlist = np.zeros_like(hlist)

num = 0



list = []

#+++++

for i in range(1,N):

    sa = hlist[i-1]-hlist[i]

    if sa > 0:

        list.append(sa)

list.append(hlist[N-1])



print((sum(list)))

N = int(eval(input()))

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

def count_island(height):

    res = 0

    sink = True

    for h in hlist:

        if sink and h > height:

            res += 1

            sink = False

        if h <= height:

            sink = True

    return res



ans = 0

for height in range(max(hlist)):

    ans += count_island(height)

print(ans)
import numpy as np

N = int(eval(input()))
hlist = np.array([_ for _ in map(int, input().split())])
max = np.max(hlist)
min = np.min(hlist)
newlist = np.zeros_like(hlist)
num = 0
list = []
# +++++
for i in range(1, N):
    sa = hlist[i - 1] - hlist[i]
    if sa > 0:
        list.append(sa)
list.append(hlist[N - 1])
print((sum(list)))

N = int(eval(input()))
hlist = list(map(int, input().split()))


def count_island(height):
    res = 0
    sink = True
    for h in hlist:
        if sink and h > height:
            res += 1
            sink = False
        if h <= height:
            sink = True
    return res


ans = 0
for height in range(max(hlist)):
    ans += count_island(height)
print(ans)

-import numpy as np +N = int(eval(input())) +hlist = list(map(int, input().split())) -N = int(eval(input())) -hlist = np.array([_ for _ in map(int, input().split())]) -max = np.max(hlist) -min = np.min(hlist) -newlist = np.zeros_like(hlist) -num = 0 -list = [] -for i in range(1, N): -    sa = hlist[i - 1] - hlist[i] -    if sa > 0: -        list.append(sa) -list.append(hlist[N - 1]) -print((sum(list))) + +def count_island(height): +    res = 0 +    sink = True +    for h in hlist: +        if sink and h > height: +            res += 1 +            sink = False +        if h <= height: +            sink = True +    return res + + +ans = 0 +for height in range(max(hlist)): +    ans += count_island(height) +print(ans)