#!/usr/bin/env python3

# coding: utf-8

# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§??????



# input & calc

n = int(eval(input()))

max_diff = -20**9

minv = 20**9

for i in range(n):

    r = int(eval(input()))

    max_diff = max(max_diff, r - minv)

    minv = min(minv, r)



# output

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

max_diff = -10**10



current_min = int(eval(input()))



for _ in range(n-1):

    current = int(eval(input()))

    diff = current - current_min

    if diff > max_diff:

        max_diff = diff

    if current < current_min:

        current_min = current

print(max_diff)



#!/usr/bin/env python3
# coding: utf-8
# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§??????
# input & calc
n = int(eval(input()))
max_diff = -(20**9)
minv = 20**9
for i in range(n):
    r = int(eval(input()))
    max_diff = max(max_diff, r - minv)
    minv = min(minv, r)
# output
print(max_diff)

n = int(eval(input()))
max_diff = -(10**10)
current_min = int(eval(input()))
for _ in range(n - 1):
    current = int(eval(input()))
    diff = current - current_min
    if diff > max_diff:
        max_diff = diff
    if current < current_min:
        current_min = current
print(max_diff)

-#!/usr/bin/env python3 -# coding: utf-8 -# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§?????? -# input & calc -max_diff = -(20**9) -minv = 20**9 -for i in range(n): -    r = int(eval(input())) -    max_diff = max(max_diff, r - minv) -    minv = min(minv, r) -# output +max_diff = -(10**10) +current_min = int(eval(input())) +for _ in range(n - 1): +    current = int(eval(input())) +    diff = current - current_min +    if diff > max_diff: +        max_diff = diff +    if current < current_min: +        current_min = current