from sys import stdin

n = int(eval(input()))

r=[int(eval(input())) for i in range(n)]

rv = r[::-1][:-1]

m = None

p_r_j = None

for j,r_j in enumerate(rv):

    if p_r_j == None or p_r_j < r_j:

        p_r_j = r_j

    if p_r_j > r_j:

        continue

    r_i = min(r[:-(j+1)])

    t = r_j - r_i

    if m == None or t > m:

        m = t

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

minv = int(eval(input()))

maxv = -2*10**9

for i in range(n-1):

    r = int(eval(input()))

    maxv = max(maxv,r-minv)

    minv = min(minv,r)

print(maxv)
from sys import stdin

n = int(eval(input()))
r = [int(eval(input())) for i in range(n)]
rv = r[::-1][:-1]
m = None
p_r_j = None
for j, r_j in enumerate(rv):
    if p_r_j == None or p_r_j < r_j:
        p_r_j = r_j
    if p_r_j > r_j:
        continue
    r_i = min(r[: -(j + 1)])
    t = r_j - r_i
    if m == None or t > m:
        m = t
print(m)

n = int(eval(input()))
minv = int(eval(input()))
maxv = -2 * 10**9
for i in range(n - 1):
    r = int(eval(input()))
    maxv = max(maxv, r - minv)
    minv = min(minv, r)
print(maxv)

-from sys import stdin - -r = [int(eval(input())) for i in range(n)] -rv = r[::-1][:-1] -m = None -p_r_j = None -for j, r_j in enumerate(rv): -    if p_r_j == None or p_r_j < r_j: -        p_r_j = r_j -    if p_r_j > r_j: -        continue -    r_i = min(r[: -(j + 1)]) -    t = r_j - r_i -    if m == None or t > m: -        m = t -print(m) +minv = int(eval(input())) +maxv = -2 * 10**9 +for i in range(n - 1): +    r = int(eval(input())) +    maxv = max(maxv, r - minv) +    minv = min(minv, r) +print(maxv)