N, *H = list(map(int, open(0).read().split()))

cnt = 0

prv = 0

for h in H:

    cnt += max(0, h - prv)

    prv = h

print(cnt)
N, *H = list(map(int, open(0).read().split()))

diff = [H[0]] + [abs(prv - cur) for prv, cur in zip(H, H[1:])] + [H[-1]]

print((sum(diff) // 2))
N, *H = list(map(int, open(0).read().split()))
cnt = 0
prv = 0
for h in H:
    cnt += max(0, h - prv)
    prv = h
print(cnt)

N, *H = list(map(int, open(0).read().split()))
diff = [H[0]] + [abs(prv - cur) for prv, cur in zip(H, H[1:])] + [H[-1]]
print((sum(diff) // 2))

-cnt = 0 -prv = 0 -for h in H: -    cnt += max(0, h - prv) -    prv = h -print(cnt) +diff = [H[0]] + [abs(prv - cur) for prv, cur in zip(H, H[1:])] + [H[-1]] +print((sum(diff) // 2))