s = int(eval(input()))

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



incFlg = True   #登る場合はTure,　降る場合はFalse

before_height = 0

sum = 0



for i in range(len(a)-1):

    #降る場合

    if a[i] > a[i+1]:

        #その前が登り

        if incFlg:

            sum += a[i] - before_height

            incFlg = False

        #その前が下り

        else:

            before_height = a[i]

    #登る場合

    else:

        if not incFlg:

            before_height = a[i]

        incFlg = True



if incFlg:

    sum += a[len(a)-1] - before_height



print(sum)

s = int(eval(input()))

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



incFlg = True   #登る場合はTure,　降る場合はFalse

before_height = 0

sum = 0



for i in range(len(a)-1):

    #降る場合

    if a[i] > a[i+1]:

        #その前が登り

        if incFlg:

            sum += a[i] - before_height

            incFlg = False

        #その前が下り

        # else:

        #     # before_height = a[i]

    #登る場合

    else:

        if not incFlg:

            before_height = a[i]

        incFlg = True



if incFlg:

    sum += a[len(a)-1] - before_height



print(sum)

s = int(eval(input()))
a = list(map(int, input().split()))
incFlg = True  # 登る場合はTure,　降る場合はFalse
before_height = 0
sum = 0
for i in range(len(a) - 1):
    # 降る場合
    if a[i] > a[i + 1]:
        # その前が登り
        if incFlg:
            sum += a[i] - before_height
            incFlg = False
        # その前が下り
        else:
            before_height = a[i]
    # 登る場合
    else:
        if not incFlg:
            before_height = a[i]
        incFlg = True
if incFlg:
    sum += a[len(a) - 1] - before_height
print(sum)

s = int(eval(input()))
a = list(map(int, input().split()))
incFlg = True  # 登る場合はTure,　降る場合はFalse
before_height = 0
sum = 0
for i in range(len(a) - 1):
    # 降る場合
    if a[i] > a[i + 1]:
        # その前が登り
        if incFlg:
            sum += a[i] - before_height
            incFlg = False
        # その前が下り
        # else:
        #     # before_height = a[i]
    # 登る場合
    else:
        if not incFlg:
            before_height = a[i]
        incFlg = True
if incFlg:
    sum += a[len(a) - 1] - before_height
print(sum)

-        else: -            before_height = a[i] +        # else: +        #     # before_height = a[i]