CodeEff/ECCO huggingface dataset:
# Original solution
num = int(eval(input()))
num_list = [int(eval(input())) for x in range(num)]
max_difference = float("-inf")

for i in range(num):
    for j in range(i+1, num):
        difference = num_list[j] - num_list[i]
        if max_difference < difference:
            max_difference = difference

print(max_difference)

# Optimized solution

num = int(eval(input()))
max_value = float("-inf")
min_value = float("inf")

for i in [int(eval(input())) for x in range(num)]:

    if max_value < (i - min_value):
        max_value = i - min_value

    if min_value > i:
        min_value = i

print(max_value)
# Original solution
n = int(eval(input()))
l = []
for i in range(n):
    l.append(int(eval(input())))

result = l[1] - l[0]
for j in range(1, n):
    for i in range(0, j):
        if l[j] - l[i] > result:
            result = l[j] - l[i]
print(result)

# Optimized solution
n = int(eval(input()))
maxv = -2 * 10 ** 9
minv = 2 * 10 ** 9
for i in range(n):
    v = int(eval(input()))
    maxv = max(maxv, v - minv)
    minv = min(minv, v)
print(maxv)
# Original solution
numberOfInput=int(eval(input()))
numberForStock=[]
index=0
while index<numberOfInput:
    inputNumber=int(eval(input()))
    numberForStock.append(inputNumber)
    index+=1

numberForReturn=-10**9
for indexForMax in range(1,numberOfInput):
    for indexForMin in range(0,indexForMax):
        if numberForReturn<numberForStock[indexForMax]-numberForStock[indexForMin]:
            numberForReturn=numberForStock[indexForMax]-numberForStock[indexForMin]
            
        
print(numberForReturn)


# Optimized solution
n = int(eval(input()))
index=0
minL=[]
moneyL=[]
while index < n:
    inputN = int(eval(input()))
    moneyL.append(inputN)
    if index==0:
        minL.append(inputN)
    else:
        if minL[index-1] < inputN:
            minL.append(minL[index-1])
        else:
            minL.append(inputN)
    index+=1

index2=1
maxProfit = -10**9
while index2 < len(moneyL):
    if moneyL[index2] - minL[index2-1] > maxProfit:
        maxProfit = moneyL[index2] - minL[index2-1]
    else:
        pass
    index2+=1

print(maxProfit)
# Original solution
#!/usr/bin/env python3
# input
n = int(eval(input()))
R = []
for i in range(n):
    R.append(int(eval(input())))

# calc
maximum = -10**9
for i in range(n):
    for j in range(i+1, n):
        if R[j] - R[i] > maximum:
            maximum = R[j] - R[i]

# output
print(maximum)

# Optimized solution
#!/usr/bin/env python3
# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§??????

# 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)
# Original solution
#!/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)

# Optimized solution
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)
# Original solution
n = int(eval(input()))
R_max = -10**9
R_min = int(eval(input()))
for i in range(n-1):
    R = int(eval(input()))
    if R_max < R - R_min:
        R_max = R - R_min

    if R < R_min:
        R_min = R

print(R_max)

# Optimized solution
n = int(eval(input()))
R = [int(eval(input())) for i in range(n)]
minx = R[0]
maxx = -10**9
for i in range(1, n):
    if R[i] - minx > maxx:
        maxx = R[i] - minx
    if R[i] < minx :
        minx = R[i]
print(maxx)
# Original solution
# coding: utf-8
# Here your code !
prof = 0
d = int(eval(input()))
li =[int(eval(input())) for i in range(d)]
max =li[1]-li[0]

while len(li)>1:
    for i in range(len(li)):
        if li[i]-li[0]>max and i!=0:
            max= li[i]-li[0]
    li=li[1:]
    
print(max)

# Optimized solution
# coding: utf-8
# Here your code !
import math
prof = 0
d = int(eval(input()))
li =[int(eval(input())) for i in range(d)]
max=float("-inf")
min=li[0]
for j in range(1,d):
    if li[j]-min>max:
        max=li[j]-min
    if li[j]<min:
        min=li[j]

print(max)
# Original solution
n = int(input())
minv = int(input())
maxv = 0 - 1000000000
  
for j in range( n-1 ):
  num = int( input( ) )  
  diff = num - minv
  if maxv < diff:
    maxv = diff
  if num < minv:
    minv = num
  
print(maxv)

# Optimized solution
n = int(input())
minv = int(input())
maxv = -1*10**9
  
for j in range( n-1 ):
  num = int( input( ) )  
  diff = num - minv
  if maxv < diff:
    maxv = diff
  if num < minv:
    minv = num
  
print(maxv)
# Original solution
s_max = -float('inf')
s = 0
for i in range(int(eval(input()))):
	r = int(eval(input()))
	if i:
		d = r - prev
		s = max(s, 0) + d
		s_max = max(s, s_max)
	prev = r
print(s_max)


# Optimized solution
s_max = -float('inf')
s = 0
for i in range(int(eval(input()))):
	r = int(eval(input()))
	if i:
		s = max(s, 0) + r - prev
		s_max = max(s, s_max)
	prev = r
print(s_max)
# Original solution
f = lambda: int(eval(input()))
d = -float('inf')
n = f()
l = f()
for _ in range(n-1):
	r = f()
	d = max(d, r-l)
	l = min(l, r)
print(d)


# Optimized solution
import sys
d = -float('inf')
n = int(eval(input()))
l = int(eval(input()))
for s in sys.stdin:
	r = int(s)
	d = max(d, r-l)
	l = min(l, r)
print(d)
# Original solution
N = int(eval(input()))
A = [] 
for i in range (N):
    A.append(eval(input()))
A = list(map(int,A))
Max = A[1]-A[0]
for i in range(N-1):
    for j in range(i+1,N):
        if (A[j]-A[i]) > Max :
            Max = A[j]-A[i]
print(Max)


# Optimized solution
n = int(eval(input()))
numbers = []

minv = int(eval(input()))
num = int(eval(input()))

max_r = num - minv

if(minv > num):
    minv = num

for i in range(2,n):
    num = int(eval(input()))
    if(max_r <(num - minv)):
        max_r = num - minv

    if(minv > num):
        minv = num

print(max_r)
# Original solution
n = int(eval(input()))
R = []
for _ in range(n):
    R.append(int(eval(input())))

maxv = R[1] - R[0]
for i in range(1, n):
    for j in range(0, i):
        maxv = max(R[i] - R[j], maxv)
print(maxv)

# Optimized solution
n = int(eval(input()))
R = []
for _ in range(n):
    R.append(int(eval(input())))

maxv = R[1] - R[0]
minv = R[0]
for j in range(1, n):
    maxv = max(R[j] - minv, maxv)
    minv = min(R[j],minv)
print(maxv)
# Original solution
n=int(eval(input()))
z=[]
for i in range(n):
    z+=[int(eval(input()))]
a=0
zz=[]
zzz=[]
while True:
    if a==len(z):
        break
    j=a+1
    for i in z[j:]:
        
        zz+=[i-z[a]]
        
    zzz+=[max(zz)]
    a+=1
print((max(zzz)))

# Optimized solution
n=int(eval(input()))
r_min=int(eval(input()))
r_t=int(eval(input()))
g_max=r_t-r_min
r_min=min(r_t,r_min)

for _ in range(n-2):
    r_t=int(eval(input()))
    g_max=max(g_max,r_t-r_min)
    r_min=min(r_t,r_min)

print(g_max)
# Original solution
import functools

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

benefit = [[rj - ri for j,rj in enumerate(R[i:]) if j+i > i] for i,ri in enumerate(R)]
print((max(functools.reduce(lambda a,b: a+b, benefit))))

# Optimized solution
n = int(eval(input()))
R = [int(eval(input())) for i in range(n)]

minv = float('inf')
maxv = -float('inf')
for r in R:
    maxv = max(maxv, r-minv)
    minv = min(minv, r)
print(maxv)
# Original solution
R = [(int(eval(input())), i) for i in range(int(eval(input())))]
print((max([max(y-x for y, j in R[i+1:]) for x, i in R[:-1]])))

# Optimized solution
R = [int(eval(input())) for i in range(int(eval(input())))]
maxp = R[1] - R[0]
minv = R[0]
for r in R[1:]:
    maxp = max(maxp, r-minv)
    minv = min(minv, r)
print(maxp)
# Original solution
res = -10 ** 9
n   = int(eval(input()))
a   = int(eval(input()))
Min = int(a)

for mak in range(n - 1) :
    tem = 0
    b = int(eval(input()))
    Min = min(b, Min)
    
    if   b < a : tem = b - a
    else       : tem = b - Min

    if tem > res : res = int(tem)
    a   = int(b)
print(res)

# Optimized solution
res = -10 ** 9
n   = int(eval(input()))
a   = int(eval(input()))
Min = int(a)

for mak in range(n - 1) :
    tem = 0
    b = int(eval(input()))
    if b < Min : Min = int(b)
    
    if   b < a : tem = b - a
    else       : tem = b - Min

    if tem > res : res = int(tem)
    a   = int(b)
print(res)
# Original solution
N = int(eval(input()))
list = []

for i in range(N):
    tmp = int(eval(input()))
    list.append(tmp)

maxDiff = - 10 ** 9
for i in range(N):
    for j in range(i+1, N):
        tmpDiff = list[j] - list[i]
        if tmpDiff > maxDiff:
            maxDiff = tmpDiff
print(maxDiff)


# Optimized solution
N = int(eval(input()))
list = []

for i in range(N):
    tmp = int(eval(input()))
    list.append(tmp)

maxDiff = - 10 ** 9
tmpMin = list[0]
for i in range(N-1):
    maxDiff = max([maxDiff, list[i+1] - tmpMin])
    tmpMin = min([tmpMin, list[i+1]])
print(maxDiff)
# Original solution
N = int(eval(input()))
R = [int(eval(input())) for i in range(N)]

sa = R[N - 1] - R[N - 2]
for i in reversed(list(range(N))):
    for j in reversed(list(range(i))):
        tmp = R[i] - R[j]
        if tmp > sa:
            sa = tmp
print(sa)


# Optimized solution
N = int(eval(input()))
R = [int(eval(input())) for i in range(N)]

min_v = R[0]
max_v = R[1] - R[0]
for i in range(1, len(R)):
    if min_v > R[i - 1]:
        min_v = R[i - 1]
    if max_v < R[i] - min_v:
        max_v = R[i] - min_v
print(max_v)
# Original solution
#Reference : http://qiita.com/lethe2211/items/6cbade2bc547649bc040
n = eval(input())

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

start_point = 0
peak = 0
max_diff = -pow(10, 9)

while (start_point < n - 1):
    diff = -pow(10, 9)
    for i in range(start_point + 1, n):
         diff_temp = R[i] - R[start_point]
         if (diff_temp >= diff):
             diff = diff_temp
             peak = i
    for i in range(start_point, peak):
        diff_temp = R[peak] - R[i]
        if (diff_temp > max_diff):
            max_diff = diff_temp
    start_point = peak

print(max_diff)

# Optimized solution
#Reference : http://qiita.com/lethe2211/items/6cbade2bc547649bc040
#Reference : http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D
n = eval(input())

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

min_v = R[0]
max_v = -pow(10, 9)
for i in range(1, n):
    temp = R[i] - min_v
    if (temp >= max_v):
        max_v = temp
    temp = R[i]
    if (min_v >= temp):
        min_v = temp
print(max_v)
# Original solution
import sys

x = []

max = -(10**9)

for line in sys.stdin.readlines():
  x.append(line.strip())

length = int(x[0])

x.remove(x[0])

for i in range(0, length):
  for j in range(i + 1, length):
    sa = int(x[j]) - int(x[i])
    if max < sa:
      max = sa

print(max)

# Optimized solution
import sys

x = []

for line in sys.stdin.readlines():
  x.append(line.strip())

max = -(10**9)
min = int(x[1])

for i in range(2, int(x[0])+1):
  sa = int(x[i]) - min
  if max < sa:
    max = sa
  if min > int(x[i]):
    min = int(x[i])

  

print(max)
# Original solution
n = int(eval(input()))

R = []

for i in range(0,n):
    R.insert(i,int(eval(input())))

MAX = R[1] - R[0]
for r in range(2,n):
    o = R[r] - min(R[:r])
    if(MAX < o):
        MAX = o
print(MAX)

# Optimized solution
n = int(eval(input()))

R = []

for i in range(0,n):
    R.insert(i, int(eval(input())))

m = min(R[0:2])
MAX = R[1] - R[0]
for r in range(2, n):
    if(R[r-1] < m):
        m = R[r-1]
    MAX2 = R[r] - m
    if(MAX2 > MAX):
        MAX = MAX2

print(MAX)
# Original solution
n = int(eval(input()))
x = []
for i in range(n):
    x.append(int(eval(input())))
m = float("inf") * (-1)
for i in range(n-1):
    for j in range(i+1,n):
        if m < (x[j] - x[i]):
            m = x[j] - x[i]
print(m)



# Optimized solution
n = int(eval(input()))
x = []
for i in range(n):
    x.append(int(eval(input())))
mx = float("inf") * (-1)
mn = x[0]
for i in range(1,n):
    if mx < (x[i] - mn):
        mx = x[i] - mn
    if mn > x[i]:
        mn = x[i]
print(mx)
# Original solution
n = int(eval(input()))
ns = []
max_profit = -1000000000
min_value = 1000000000
for i in range(n):
    num = int(eval(input()))
    if i > 0:
        max_profit = max(max_profit, num-min_value)
    min_value = min(num, min_value)
print(max_profit)
    


# Optimized solution
n = int(eval(input()))
ns = []
max_profit = -1000000000
min_value = int(eval(input()))
for i in range(1,n):
    num = int(eval(input()))
    max_profit = max(max_profit, num-min_value)
    min_value = min(num, min_value)
print(max_profit)
# Original solution
n = int(input().rstrip())
R = [0 for _ in range(n)]
for i in range(n):
    R[i] = int(input().rstrip())

max_margin = 1 - 10**9
for i in range(n):
    for j in range(i+1, n):
        margin = R[j] - R[i]
        if margin > max_margin:
            max_margin = margin

print(max_margin) 


# Optimized solution
n = int(input().rstrip())
R = [0 for _ in range(n)]
for i in range(n):
    R[i] = int(input().rstrip())

margin = - 10**9
min_R = R[0]
for j in range(1, n):
    margin = max(margin, R[j] - min_R)
    min_R = min(min_R, R[j])

print(margin)
# Original solution
# -*- coding : utf-8 -*-

def maximum_profit(price_list):
    max = price_list[1] - price_list[0]
    for x in range(len(price_list)-1):
        for y in range(x+1, len(price_list)):
            if max < price_list[y] - price_list[x]:
                max = price_list[y] - price_list[x]
    return max

input_num = int(eval(input()))
price_list = list()
for i in range(input_num):
    input_price = int(eval(input()))
    price_list.append(input_price)
print((maximum_profit(price_list)))

# Optimized solution
# -*- coding : utf-8 -*-

def maximum_profit(price_list):
    max = price_list[1] - price_list[0]
    min = price_list[0]
    for i in range(1, len(price_list)):
        if max < price_list[i] - min:
            max = price_list[i] - min
        if min > price_list[i]:
            min = price_list[i]
    return max

input_num = int(eval(input()))
price_list = list()
for i in range(input_num):
    input_price = int(eval(input()))
    price_list.append(input_price)
print((maximum_profit(price_list)))
# Original solution
n = int(eval(input()))
DifMax = -999999999

R = [int(eval(input()))]
for i in range(1, n):
  RMin = min(R)
  R.append(int(eval(input())))
  if DifMax < R[i] - RMin:
    DifMax = R[i] - RMin

print(DifMax)

# Optimized solution
n = int(eval(input()))
DifMax = -9999999999999

R = [int(eval(input()))]
RMin = R[0]
for i in range(1, n):
  if RMin > R[i-1]:
      RMin = R[i-1]
  R.append(int(eval(input())))
  if DifMax < R[i] - RMin:
    DifMax = R[i] - RMin

print(DifMax)
# Original solution

n = int(eval(input()))

R = []

for i in range(n):
    R.append(int(eval(input())))

kouho = set()
diff_max = None

for (i, rt) in enumerate(R):
    if i == 0:
        rt_min = rt
    else:
        if rt < rt_min and not (diff_max is None):
            kouho.add(diff_max)
            diff_max = None
            rt_min = rt
        elif rt < rt_min and diff_max is None:
            rt_min = rt
        elif rt >= rt_min:
            if diff_max is None:
                diff_max = rt - rt_min
            else:
                diff_max = max(diff_max, rt - rt_min)

if not (diff_max is None):
    kouho.add(diff_max)

# print(kouho)

if kouho != set():
    print((max(kouho)))
else:
    diff_tonari = {R[i + 1] - R[i] for i in range(n - 1)}
    print((max(diff_tonari)))

# Optimized solution

n = int(eval(input()))

R = []

for i in range(n):
    R.append(int(eval(input())))

minv = R[0]
maxv = R[1] - R[0]

for r in R[1:]:
    maxv = max(maxv, r - minv)
    minv = min(minv, r)

print(maxv)
# Original solution

n = int(eval(input()))

dif_max = -float("inf")
min_v = float("inf")

for i in range(n):
    r = int(eval(input()))
    dif_max = max(dif_max, r - min_v)
    min_v = min(min_v, r)

print(dif_max)

# Optimized solution
import sys

n = int(eval(input()))

dif_max = -float("inf")
min_v = float("inf")

for i in range(n):
    r = int(sys.stdin.readline())
    dif_max = max(dif_max, r - min_v)
    min_v = min(min_v, r)

print(dif_max)
# Original solution
from sys import stdin
 
inf = 10**9 + 1

def solve():
    n = int(stdin.readline())
    R = [int(stdin.readline()) for i in range(n)]

    ans = max_profit2(n, R)

    print(ans)

def max_profit(n, R):
    max_d = -inf
    min_v = R[0]

    for i in range(1, n):
        max_d = max(max_d, R[i] - min_v)
        min_v = min(min_v, R[i])

    return max_d

def max_profit2(n, R):
    max_dif = -inf

    for left in range(n):
        for j in range(left + 1, n):
            max_dif = max(max_dif, R[j] - R[left])

    return max_dif
    
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
 
if __name__ == '__main__':
    solve()


# Optimized solution
from sys import stdin
 
inf = 10**9 + 1

def solve():
    n = int(stdin.readline())
    max_d = -inf
    min_v = inf * 2

    for i in range(n):
        r = int(stdin.readline())

        max_d = max(max_d, r - min_v)
        min_v = min(min_v, r)

    print(max_d)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None
 
if __name__ == '__main__':
    solve()
# Original solution

def calcMax(i):
  now = numbers[i] 

  future_max = max(numbers[i+1:])
  #print(numbers[i+1:])
  t = numbers[i+1:]
  #print((max(t)))
  return future_max - now

n = int(eval(input()))

numbers = []
for i in range(n):
  numbers.append(int(eval(input())))

m = -1000000001
for i in range(len(numbers) - 1):
    if i == 0 or i == len(numbers) - 1 or (numbers[i-1] >= numbers[i] and numbers[i] < numbers[i+1]) or (numbers[i-1] > numbers[i] and numbers[i] <= numbers[i+1]):
      temp = calcMax(i)
      #print("temp: " + str(temp))
      if temp > m:
          m = temp

print (m)



# Optimized solution
def calcMax(i):
  now = numbers[i]

  future_max = max(numbers[i+1:])
  #print(numbers[i+1:])
  t = numbers[i+1:]
  #print((max(t)))
  return future_max - now

n = int(eval(input()))

numbers = []
for i in range(n):
  numbers.append(int(eval(input())))

m = -1000000001
ti = 1000000001
for i in range(len(numbers) - 1):
    if numbers[i] < ti:
      if (i == 0 or i == len(numbers) - 1 or (numbers[i-1] >= numbers[i] and numbers[i] <= numbers[i+1])):
        temp = calcMax(i)
        #print("temp: " + str(temp))
        if temp > m:
            m = temp
            ti = numbers[i]

print (m)
# Original solution
n = int(eval(input()))
values = []
for i in range(n):
    value = int(eval(input()))
    values.append(value)

def profit(values):
    sorted_values = sorted(values)
    minimum = sorted_values[0]
    maximum = sorted_values[-1]
    diff_list = []
    while values != []:
        diff = minimum - maximum
        start = values[0]
        for v in values[1:]:
            tmp_diff = v - start
            if tmp_diff > diff:
                diff = tmp_diff
        diff_list.append(diff)
        values.remove(values[0])
    diff_list.sort(reverse = True)
    return diff_list[0]


print((profit(values)))

# Optimized solution
n = int(eval(input()))
values = [int(eval(input())) for i in range(n)]

maxv = -999999999
minimum = values[0]

for i in range(1, n):
    if values[i] - minimum > maxv:
        maxv = values[i] - minimum
    if values[i] < minimum:
        minimum = values[i]

print(maxv)
# Original solution
# -*- coding: utf-8 -*-


def maximum_profit(profits):
    max_v = profits[1] - profits[0]

    for j in range(1, len(profits)):
        for i in range(0, j):
            max_v = max(profits[j] - profits[i], max_v)

    print(max_v)


def to_int(v):
    return int(v)


if __name__ == '__main__':
    l = to_int(eval(input()))
    profits = [to_int(eval(input())) for i in range(l)]

    maximum_profit(profits)

# Optimized solution
# -*- coding: utf-8 -*-


def maximum_profit(profits):
    max_v = profits[1] - profits[0]
    min_v = profits[0]

    for j in range(1, len(profits)):
        max_v = max(max_v, profits[j]-min_v)
        min_v = min(min_v, profits[j])

    print(max_v)


def to_int(v):
    return int(v)


if __name__ == '__main__':
    l = to_int(eval(input()))
    profits = [to_int(eval(input())) for i in range(l)]

    maximum_profit(profits)
# Original solution
n = int(input())
num_list = [int(input()) for i in range(n)]
#print num_list

ans = max(num_list[1:]) - num_list[0]
chk = num_list[0]
# print "ans=%d, chk=%d" % (ans, chk)

for i in range(1, n - 1):
  if num_list[i] >= chk:
    continue
  max_num = max(num_list[i+1:])
  # print max_num
  tmp = max_num - num_list[i]
  if tmp > ans:
    ans = tmp
  # print "i = %d, tmp = %d, ans = %d" % (i, tmp, ans)

print(ans)

# Optimized solution
n = int(input())
num_list = [int(input()) for i in range(n)]

minv = num_list[0]
maxv = -1000000000

for i in range(1, n):
  tmp = num_list[i] - minv
  maxv = tmp if tmp > maxv else maxv
  minv = num_list[i] if minv > num_list[i] else minv
  # print "i = %d, tmp = %d, maxv = %d, minv = %d" % (i, tmp, maxv, minv)

print(maxv)
# Original solution
n = int(eval(input()))
r = [int(eval(input())) for x in range(n)]

cur_max_diff = min(r) - max(r)
cur_min_idx = -1

for i in range(n) :
    
    if i == 0 :
        for j in range(1, n) :
            if r[j] - r[i] > cur_max_diff :
                cur_max_diff = r[j] - r[i]
                cur_min_idx = j
                
    elif i >= cur_min_idx :
        for j in range(i + 1, n) :
            if r[j] - r[i] > cur_max_diff :
                cur_max_diff = r[j] - r[i]
                cur_min_idx = j
    else :
        cur_max_diff = max(cur_max_diff, r[cur_min_idx] - r[i])
        
print(cur_max_diff)
        


# Optimized solution
n = int(eval(input()))

# initial observation
cur_min = int(eval(input()))
max_diff = -1 * (10**9) - 1

for i in range(n - 1) :
    num = int(eval(input()))
    
    max_diff = max(max_diff, num - cur_min)
    
    if num < cur_min :
        cur_min = num
    
print(max_diff)
# Original solution
#coding:utf-8
#1_1_D
n = int(eval(input()))
maxv = -2 * 10 ** 9
prices = [int(eval(input())) for x in range(n)]

for i in range(1, n):
    for j in range(i):
        if prices[i] - prices[j] > maxv:
            maxv = prices[i] - prices[j]

print(maxv)

# Optimized solution
#coding:utf-8
#1_1_D
n = int(eval(input()))
prices = [int(eval(input())) for x in range(n)]
maxv = -2 * 10 ** 9
minv = prices[0]
for i in range(1, n):
    maxv = max(maxv, prices[i] - minv)
    minv = min(minv, prices[i])

print(maxv)
# Original solution
#-*- coding:utf-8 -*-

def main():
    n , data = input_data()
    vMax = float('-inf')

    i = 1
    for i, Ri in enumerate(data):
        for Rj in data[i+1:]:
            n = Rj - Ri
            if vMax < n:
                vMax = n
    print(vMax)

def input_data():
    n = int(eval(input()))
    lst = [int(eval(input())) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()

# Optimized solution
#-*- coding:utf-8 -*-

def main():
    n , data = input_data()
    vMax = float('-inf')

    i = 1
    minIndex = min(enumerate(data) , key = lambda x:x[1])[0]
    for i, Ri in enumerate(data):
        if data[i+1:]:
            n = max(data[i+1:]) - Ri
            if vMax < n:
                vMax = n

        if i == minIndex: # Ri???????°???????????????¨????????????????¨??????????
            break

    print(vMax)

def input_data():
    n = int(eval(input()))
    lst = [int(eval(input())) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()