n = int(eval(input()))

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



cnt = 0

while max(set(h)) > 0:

    flg = False

    for i in h:

        if i <= 0:

            flg = False

            continue

        else:

            if not flg:

                cnt += 1

            flg = True

    h = list([x-1 for x in h])



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

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



ans = h[0]

for i in range(n-1):

    ans += h[i+1] - h[i] if h[i] < h[i+1] else 0



print(ans)
n = int(eval(input()))
h = list(map(int, input().split()))
cnt = 0
while max(set(h)) > 0:
    flg = False
    for i in h:
        if i <= 0:
            flg = False
            continue
        else:
            if not flg:
                cnt += 1
            flg = True
    h = list([x - 1 for x in h])
print(cnt)

n = int(eval(input()))
h = list(map(int, input().split()))
ans = h[0]
for i in range(n - 1):
    ans += h[i + 1] - h[i] if h[i] < h[i + 1] else 0
print(ans)

-cnt = 0 -while max(set(h)) > 0: -    flg = False -    for i in h: -        if i <= 0: -            flg = False -            continue -        else: -            if not flg: -                cnt += 1 -            flg = True -    h = list([x - 1 for x in h]) -print(cnt) +ans = h[0] +for i in range(n - 1): +    ans += h[i + 1] - h[i] if h[i] < h[i + 1] else 0 +print(ans)