import sys

b,s=-1e10,1e10

eval(input())

for r in map(int,sys.stdin.readlines()):

 b,s=max(b,r-s),min(s,r)

print(b)

import sys

b,s=-1e10,1e10

eval(input())

for r in map(int,sys.stdin.readlines()):

 if b<r-s:b=r-s

 if s>r:s=r

print(b)

import sys

b, s = -1e10, 1e10
eval(input())
for r in map(int, sys.stdin.readlines()):
    b, s = max(b, r - s), min(s, r)
print(b)

import sys

b, s = -1e10, 1e10
eval(input())
for r in map(int, sys.stdin.readlines()):
    if b < r - s:
        b = r - s
    if s > r:
        s = r
print(b)

-    b, s = max(b, r - s), min(s, r) +    if b < r - s: +        b = r - s +    if s > r: +        s = r