R = [0 for i in range(0,200000)] 

n = int(input())

for i in range(n):

	R[i] = int(eval(input()))

maxv = -2000000000

minv = R[0]

for j in range(1, n):

	maxv = max(maxv, R[j]-minv)

	minv = min(minv, R[j])

print(maxv) 
n = int(input())

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

maxv = -2000000000

minv = R[0]

for j in range(1, n):

	maxv = max(maxv, R[j]-minv)

	minv = min(minv, R[j])

print(maxv) 
R = [0 for i in range(0, 200000)]
n = int(input())
for i in range(n):
    R[i] = int(eval(input()))
maxv = -2000000000
minv = R[0]
for j in range(1, n):
    maxv = max(maxv, R[j] - minv)
    minv = min(minv, R[j])
print(maxv)

n = int(input())
R = [eval(input()) for i in range(n)]
maxv = -2000000000
minv = R[0]
for j in range(1, n):
    maxv = max(maxv, R[j] - minv)
    minv = min(minv, R[j])
print(maxv)

-R = [0 for i in range(0, 200000)] -for i in range(n): -    R[i] = int(eval(input())) +R = [eval(input()) for i in range(n)]