Problem:
Maximum Profit You can obtain profits from foreign exchange margin transactions. For example,  if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ . Input The first line contains an integer $n$. In the following $n$ lines, $R_t$ ($t = 0, 1, 2, ... n-1$) are given in order. Output Print the maximum value in a line. Constraints  $2 \leq n \leq 200,000$  $1 \leq R_t \leq 10^9$  Sample Input 1 6
5
3
1
3
4
3 Sample Output 1 3 Sample Input 2 3
4
3
2 Sample Output 2 -1

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
mina =a[0]
maxa=a[1]-a[0]
for i in range(1,n):
    maxa = max(a[i]-mina,maxa)
    mina = min(mina,a[i])
print(maxa)

Solution (Python):
n = int(input())

x = [int(input()) for i in range(n)]
minx = x[0]
maxx = -10000000000

for i in range(1,n):
    r = x[i] - x[i-1]
    maxx = max(maxx,x[i] - minx)
    minx = min(minx,x[i])

print(maxx)

Solution (Python):
def isPrime(x):
    if x > 2 and x % 2 == 0:
        return False
    if x == 1:
        return True
    for a in range(3,round(x**(1/2))+1,2):
        if x % a == 0:
            return False
    return True

n = int(input())

R= []
for a in range(n):
    R.append(int(input()))



min_R = []
min = 10**9
for a in R:
    if a < min:
        min = a
    min_R.append(min)


R.pop(0)
calculated = [a-b for (a,b) in zip(R,min_R)]

print(max(calculated))
'''
minv = 999999999999
maxv = R[1]-R[0]
for a in range(len(R)):
    maxv = max(maxv, R[a]-minv)
    minv = min(minv, R[a])
    
print(maxv)
'''

Solution (Python):
n = int(input())
r = [0]*n
for i in range(n):
    r[i] = int(input())

r_min = r[0]
ans = -2000000000
for i in range(1, n):
    ans = max(ans, r[i] - r_min)
    r_min = min(r[i], r_min) 
    
print(ans)

Solution (Python):
count = int(input())
l = []

for i in range(count):
    l.append(int(input()))

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

for i in range(1, len(l)):
    maxv = max(maxv, l[i] - minv)
    minv = min(minv, l[i])

print(maxv)

Solution (Python):
n = int(input())
r = []
for i in range(0, n):
	r.append(int(input()))

rmax = r[1] - r[0]  
imin = 0 

for i in range(1, len(r)):
	if r[i]-r[imin] > rmax:
		rmax = r[i]-r[imin]
	if r[i] < r[imin]:
		imin = i

print(rmax)

Solution (Python):
import math
import itertools

def main():
  n = int(input())
  r0 = int(input())
  minR = r0
  r1 = int(input())
  if minR > r1:
    minR = r1
  maxDiff = r1 - r0

  for _ in range(2,n):
    r = int(input())

    diff = r - minR

    if maxDiff < diff:
      maxDiff = diff

    if minR > r:
      minR = r
  
  print(maxDiff)

if __name__ == '__main__':
  main()

Solution (Python):

import sys
import itertools

DEBUG = True if (len(sys.argv) > 1 and sys.argv[1] == "DEBUG") else False


def dp(value):
    if DEBUG:
        print(value)
    return


def input_text(split=" "):
    
    result = []
    while True:
        try:
            row = list(
                map(lambda x: int(x) if x.isdecimal() else x, input().split(split))
            )
            result.append(row)
        except EOFError:
            break
    return result



it = input_text()

r = list(itertools.chain.from_iterable(it[1:]))
r_min = sys.maxsize
diff_max = -sys.maxsize

if len(r) == 0:
    print(0)
    sys.exit()

for rj in r:
    dif = rj - r_min
    if diff_max < dif:
        diff_max = dif
    if rj < r_min:
        r_min = rj

print(diff_max)

Solution (Python):
n = int(input())
R = []
for i in range(n):
    R.append(int(input()))

maxv = -20000000000
minv = R[0]

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

print(maxv)

Solution (Python):
num = int(input())
a = []
[a.append(int(input())) for _ in range(num)]
minn = a[0]
maxn = (10 ** 9) * -1
for i in range(1,len(a)):
  maxn = max(maxn,a[i] - minn)
  minn = min(minn,a[i])
print(maxn)

Solution (Python):
n=int(input())
R=[int(input()) for _ in range(n)]

r_min = R[0]
ans = -10**9
for r in R[1:]:
    ans = max(ans, r-r_min)
    r_min = min(r, r_min)

print(ans)

Solution (Python):
from sys import stdin
n = int(stdin.readline())

minprice = 2000000000
maxdifference = -1000000000
for _ in range(n):
    price = int(stdin.readline())
    if price - minprice > maxdifference:
        maxdifference = price - minprice
    if price < minprice:
        minprice = price
print(maxdifference)

Solution (Python):
n = int(input())
R = list()

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

minimum = R[0]
sa = R[1] - R[0]

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

    if sa < R[i] - minimum:
        sa = R[i] - minimum

print(sa)

Solution (Python):
n = int(input())
ans = -10**10
a = []
for i in range(n):
    a.append(int(input()))
min_ = a[0]
for i in range(1,n):
    ans = max(ans, a[i]-min_)
    min_ = min(min_,a[i])
print(ans)

Solution (Python):
num = int(input())
t_list = []
for i in range(num):
    t = int(input())
    t_list.append(t)

minv = t_list[0]
maxv = t_list[1] - t_list[0]
for j in range(1,len(t_list)):
    m_buf = t_list[j] - minv
    if m_buf > maxv:
        maxv = m_buf
    
    if minv > t_list[j]:
        minv = t_list[j]

print('{}'.format(maxv))

Solution (Python):
n = int(input())
R = [int(input()) for _ in range(n)]
maxv = R[1] - R[0]
minv = R[0]

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

print(maxv)

Solution (Python):
n = int(input())
r = [int(input()) for _ in range(n)]

mn = r[0]
ans = - 10 ** 10
for i in r[1:]:
    ans = max(ans, i - mn)
    mn = min(mn, i)
print(ans)

Solution (Python):
n = int(input())
r = [int(input()) for _ in range(n)]
mn = r[0]
mx = -1000000001
for i in range(1, n) :
    mx = max(mx, r[i] - mn)
    mn = min(mn, r[i])
print(mx)

Solution (Python):
n = int(input())
l = [int(input()) for i in range(n)]
ans = -2 * 10 ** 9 
minv = l[0]
for i in range(1, n):
    ans = max(ans, l[i] - minv)
    minv = min(minv, l[i])
print(ans)

Solution (Python):
n=int(input())
a=[]*6
[a.append(int(input())) for x in range(n)]
minimam_num=a[0]
abs_num = -1001001001
for i in range(1,n):
    if minimam_num > a[i-1]:
        minimam_num=a[i-1]
    if abs_num < (a[i]-minimam_num):
        abs_num=(a[i]-minimam_num)
print(abs_num)

Solution (Python):
n = int(input())
r = []

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










minv = r[0]
maxv = r[1]-r[0]
for j in range(1,n):
    maxv = max(maxv,r[j]-minv)
    minv = min(minv,r[j])
print(maxv)

Solution (Python):
n = int(input())

for i in range(n):
    Rt = int(input())
    if i == 0:
        min_Rt = Rt
    elif i == 1:
        max_p = Rt - min_Rt
        min_Rt = min(min_Rt, Rt)
    else:
        max_p = max(max_p, Rt - min_Rt)
        min_Rt = min(min_Rt, Rt)


print(max_p)

Solution (Python):
n = int(input())
l = list(int(input()) for _ in range(n))
ma = -10**9
mi = l[0]
for j in range(1,n):
    ma = max(ma,l[j]-mi)
    mi = min(mi,l[j])
print(ma)

Solution (Python):
n = int(input())
r = []
for i in range(n):
    r.append(int(input()))

rmin = r[0]
dmax = -10**9

for i in range(1, n):
    d = r[i] - rmin
    if (d > dmax):
        dmax = d
    if (r[i]<rmin):
        rmin = r[i]

print(dmax)

Solution (Python):
import sys

input()
a = []
for s in sys.stdin:
    a.append(int(s))

maxv = -2000000000000000
minv = a[0]
for i in range(1, len(a)):
    maxv = max(maxv, a[i] - minv)
    minv = min(minv, a[i])

print(maxv)

Solution (Python):
def maxV(R, n):
    minv = R[0]
    maxv = R[1] - R[0]
    for i in range(1, n):
        maxv = max(maxv, R[i]-minv)
        minv = min(minv, R[i])
    return maxv

n = int(input())
R = [int(input()) for i in range(n)]
print(maxV(R, n))

Solution (Python):
n = int(input())
R = []
ans = -(float('inf'))

for i in range(n):
    r = int(input())
    if i == 0:
        min_r = r
        continue
    else:
        ans = max(ans,r-min_r)
        if r < min_r: min_r = r

print (ans)

Solution (Python):
N = int(input())
minv = int(input())
k = int(input())
maxv = k - minv
minv = min(minv,k)

for i in range(N - 2):
  k = int(input())
  maxv = max(maxv,k - minv)
  minv = min(minv,k)
    
print(maxv)

Solution (Python):
N = int(input())
R = [int(input()) for _ in range(N)]

ans = -float("inf")
mini = R[0]
for i in range(1,N):
    ans = max(R[i]-mini,ans)
    mini = min(R[i],mini)
    
    
print(ans)

Solution (Python):
n = int(input())
p_list = [int(input()) for i in range(n)]
maxval = -20000000000000
minval = p_list[0]
for i in range(n - 1):
  maxval = max(maxval, p_list[i + 1] - minval)
  minval = min(minval, p_list[i + 1])
print(maxval)

Solution (Python):
l = []
n=int(input())
for i in range(n):
    l.append(input())
l = list(map(int,l))
result_max = l[1] - l[0]
value_min = l[0]
for i in range(1,n):
    result_max = max(result_max,l[i]-value_min)
    value_min = min(value_min,l[i])                              
print(result_max)

Solution (Python):
n = int(input())
nums = [int(input()) for _ in range(n)]

temp_min = nums[0]
max_profit = nums[1] - nums[0]

for num in nums[1:]:
    max_profit = max(max_profit, num-temp_min)
    temp_min = min(temp_min, num)

print(max_profit)

Solution (Python):
N = int(input())
L = [int(input()) for _ in range(N)]

tmp_min = 10 ** 11
ans = -10 ** 11
for i in range(N):
    ans = max(L[i] - tmp_min, ans)
    tmp_min = min(L[i], tmp_min)
    
print(ans)

Solution (Python):
min_r = 10 ** 9
max_raise = (10 ** 9 * -1) + 1
n = int(input())
r = int(input())
min_r = min(min_r, r)
for n in range(n - 1):
    r = int(input())
    max_raise = max(max_raise, (r - min_r))
    min_r = min(min_r, r)
print(max_raise)

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
maxv = -10000000000
minv = a[0]
for i in range(1,n):
  maxv = max(maxv,a[i] - minv)
  minv = min(minv,a[i])
print(maxv)

Solution (Python):
n = int(input())

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

ans = -float('inf')
min_r = R[0]

for i in range(1, n):
    if ans < R[i] - min_r:
        ans = R[i] - min_r
    if R[i] < min_r:
        min_r = R[i]

print(ans)

Solution (Python):
n = int(input())
S = []
for _ in range(n):
    S.append(int(input()))
mini = S[0]
ans = -10**9
for i in S[1:]:
    ans = max(ans,i-mini)
    mini = min(i,mini)
print(ans)

Solution (Python):
n = int(input())

price_list = list()

max_price = -20000000000
min_val = 2000000000

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

   if i == 0:
      min_val = price_list[0]
      continue

   min_val = price_list[i-1] if min_val > price_list[i-1] else min_val
   max_price = price_list[i] - min_val if price_list[i] - min_val > max_price else max_price

print(max_price)

Solution (Python):
n = int(input())
R = [0]*n
for i in range(n):
    R[i] = int(input())

sub = R[1] - R[0]
minimum = R[0]

for j in range(1,n):
    sub = max(sub, R[j] - minimum)
    minimum = min(minimum,R[j])
    
print(str(sub))

Solution (Python):
n = int(input())
R = [int(input()) for _ in range(n)]

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

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

print(maxv)

Solution (Python):
n = int(input())
r = [int(input()) for i in range(n)]
minv = r[0]
maxv = -999999999
for i in range(1,n):
    maxv = max(maxv,r[i]-minv)
    minv = min(minv,r[i])
print(maxv)

Solution (Python):



N = int(input())
nums = [0]*N
for i in range(N):
    nums[i] = int(input())


min_v = nums[0]
max_v = nums[1] - nums[0]
for i in range(1, N):
    max_v = max(max_v, nums[i] - min_v)
    min_v = min(min_v, nums[i])


print(max_v)

Solution (Python):
n = int(input())
R = [int(input()) for _ in range(n)]

mx = -1 * (10 ** 9)
mn = R[0]

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

print(mx)

Solution (Python):
N=int(input())
R=[]
for n in range(N):
    R.append(int(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)

Solution (Python):
n = int(input())
r = [int(input()) for i in range(n)]
maxv = -9999999999
minv = r[0]
for i in range(1,n):
    maxv = max(maxv,r[i]-minv)
    minv = min(minv,r[i])
print(maxv)

Solution (Python):
N=int(input())
R=[int(input()) for _ in range(N)]
maxv=-1*10**9
minv=R[0]
for i in range(1, N):
    maxv=max(maxv, R[i]-minv)
    minv=min(minv, R[i])
print(maxv)

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
minv = A[0]
maxd = -1*(10**9)-1
for i in range(1, n):
    maxd = max(maxd, A[i]-minv)
    minv = min(minv, A[i])
print(maxd)

Solution (Python):
"""


mini = l[0] 
maxi = l[len(l)-1]


for i in range(1,len(l)):
    if l[i]<mini:
        mini=l[i]
        if(i == len(l)-1):
            print(-1)
            sys.exit(0)
    
if mini is maxi:
    print(-1)
    sys.exit(0)

for i in range(l.index(mini),len(l)):
    if l[i]>maxi:
        maxi=l[i]
print(maxi-mini)
"""

import sys
n = int(input())

mini = int(input())
t=int(input())
maxi=t-mini
if t<mini:
    mini=t
for i in range(n-2):
    n=int(input())
    if n-mini>maxi:
        maxi=n-mini
    if n<mini:
        mini=n
print(maxi)

Solution (Python):
n = int(input())
arr = [int(input()) for _ in range(n)]
Min, ans = 2e9 + 10, -int(2e9 + 10)
for i in arr:
    ans = max(ans, i - Min)
    Min = min(Min, i)
print(ans)

Solution (Python):
n = int(input())
R = [int(input()) for i in range(n)]

maxv = -20000000000
minv = R[0]

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

print(maxv)

Solution (Python):
n = int(input())
r = [int(input()) for _ in range(n)]
min = r[0]
max = r[1]-r[0]
for i in range(1,n):
    if max < r[i]-min:
        max = r[i]-min
    if min > r[i]:
        min = r[i]
print(max)

Solution (Python):
r = []

n = int(input())
for i in range(n):
    ri = int(input())
    r.append(ri)
    
minv = r[0]
maxv = -10**11

for i in range(1,n):
    maxv = max(maxv,r[i]-minv)
    minv = min(minv,r[i])
        
print(maxv)

Solution (Python):
n = int(input())

mini = float('inf')
max_diff = -float('inf')
for _ in range(n):
    r = int(input())
    if r - mini > max_diff:
        max_diff = r - mini

    if r < mini:
        mini = r

print(max_diff)

Solution (Python):
def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    lower = a[0]
    res = -10000000007
    for i in range(1,n):
        res = max(res,a[i]-lower)
        lower = min(lower,a[i])
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
input = stdin.readline

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

ans = -10 ** 9

mi = R[0]

for i in range(1, n):
    ans = max(ans, R[i] - mi)
    if R[i] < mi:
        mi = R[i]

print(ans)

Solution (Python):
n = int(input())
r = []
for _ in range(n):
    r.append(int(input()))

m = r[0]
ans = - float('inf')
for i in range(1, n):
    ans = max(ans, r[i] - m)
    if r[i] <= m:
        m = r[i]
    
    
    
    
    
print(ans)

Solution (Python):
N = int(input())
l = [int(input()) for i in range(N)]

minv = l[0]
maxv = l[1] - l[0]
for i in range(1, len(l)):
  maxv = max(maxv, l[i] - minv)
  minv = min(minv, l[i])
print(maxv)

Solution (Python):
n = int(input())
max_diff = -10**10

current_min = int(input())

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

Solution (Python):
N=int(input())
R=[int(input()) for i in range(N)]
max_prifit=R[1]-R[0]
minR=R[0]
for i in range(1,N):
    max_prifit=max(max_prifit,R[i]-minR)
    minR=min(minR, R[i])

print(max_prifit)

Solution (Python):
N = int(input())
Rt = []

for _ in range(N):

    
    Rt.append(int(input()))

minR = 10**9
profit = Rt[1]-Rt[0]

for i in range(0,N-1):
    minR = min(minR, Rt[i])
    profit = max(profit, Rt[i+1] - minR)

print(profit)

Solution (Python):
n = int(input())
r = [int(input()) for i in range(n)]

m = r[0]
M = -2000000000

for i in range(1, n):
    M = max(M, r[i]-m)
    m = min(m, r[i])

print(M)

Solution (Python):





n = int(input())
r = []
for i in range(n):
    r.append(int(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)

Solution (Python):
n = int(input())
A = [int(input()) for i in range(n)]

maxv = -1001001001
minv = A[0]
for i in range(1, n):
    maxv = max(maxv, A[i]-minv)
    minv = min(minv, A[i])


print(maxv)

Solution (Python):


n = int(input())
l = [int(input()) for _ in range(n)]
minv = l[0]
maxv = l[1] - l[0]
for x in l[1:]:
    if x - minv > maxv:
        maxv = x - minv
    if x < minv:
        minv = x
print(maxv)

Solution (Python):
n = int(input())
r = []
for i in range(n):
    r.append(int(input()))

maxv = (-10) ** 9
minv = r[0]
for i in range(1, n):
    maxv = max([r[i] - minv, maxv])
    minv = min([r[i], minv])


print(maxv)

Solution (Python):
n = int(input())
minv = int(input())
maxv = -9999999999
for i in range(n-1):
    num = int(input())
    maxv = max(maxv, num - minv)
    minv = min(minv, num)
print(maxv)

Solution (Python):
N = int(input())
R = []

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

mins = [R[0]]
m = R[0]
for i in range(1,N):
    m = min(m,R[i])
    mins.append(m)

ans = -1e9
for i in range(1,N):
    ans = max(ans,R[i]-mins[i-1])

print(ans)

Solution (Python):
n = int(input())
A = [int(input()) for i in range(n)]
maxv = -10**10
minv = A[0]

for i in range(1,n):
	maxv = max(maxv, A[i] - minv)
	minv = min(minv, A[i])

print(maxv)

Solution (Python):
R = []
n = int(input())

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

max_profit = -1000000000
minmum_value = R[0]

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

print(max_profit)

Solution (Python):
N = int(input())
R =  [0]*N

for i in range(N):
    R[i] = int(input())

m = R[0]
ans = -1*10**9

for i in range(1,N):
    if R[i] - m > ans:
        ans = R[i] - m
    if R[i] < m:
        m = R[i]
    
print(ans)

Solution (Python):
n = int(input())
p = [int(input()) for _ in range(n)]
minv, ans = p[0], -float('inf')

for i in range(1, n):
    ans = max(ans, p[i]-minv)
    minv = min(minv, p[i])

print(ans)

Solution (Python):
n = int(input())
r = [int(input()) for _ in range(n)]
minv = r[0]
maxv = r[1] - r[0]
for i in range(1,n):
    if maxv < r[i] -minv:
        maxv = r[i] -minv
    if minv > r[i]:
        minv = r[i]
    
print(maxv)

Solution (Python):
n = int(input())
lst = [int(input()) for i in range(n)]
vmin,vmax = lst.pop(0),-1000000000000
for i in lst:
    vmax = max(vmax,i-vmin)
    vmin = min(vmin,i)
print(vmax)

Solution (Python):
min_r = 100000000000
R = -100000000000

for i in range(int(input())):
    r = int(input())
    
    if i > 0:
        R = max(R, r - min_r)
        
    min_r = min(min_r, r)
    
print(R)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]

maxv = -2*10**9
minv = 10000000000
for i in range(n):
  maxv = max(maxv,a[i]-minv)
  minv = min(a[i],minv)

print(maxv)

Solution (Python):
n=int(input())
r=[int(input()) for i in range(n)]
minv=r[0]
maxv=-2000000000
for i in range(1,n):
    maxv=max(maxv,r[i]-minv)
    minv=min(minv,r[i])
print(maxv)

Solution (Python):
N=int(input())
rt=[int(input()) for x in range(N)]
min=rt[0]

max=rt[1]-rt[0]
for j in range(1,N):
    if max < rt[j] - min: max = rt[j] - min
    if min> rt[j]:min=rt[j]

print(max)

Solution (Python):
n = int(input())
minvalue = int(input())
maxprofit = -2000000000
for i in range(1,n):
    Ri = int(input())
    maxprofit = max(Ri - minvalue, maxprofit)
    minvalue = min(minvalue, Ri)
print(maxprofit)

Solution (Python):
n=int(input())
a=0
table=[]
while a<n:
	s=int(input())
	table.append(s)
	a+=1

maxv=-10**9
minv=table[0]
for i in range(1,n,1):
	if maxv<table[i]-minv:
		maxv=table[i]-minv
	if minv>table[i]:
		minv=table[i]
print(maxv)

Solution (Python):
n = int(input())

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

minv = R[0]
maxv = R[1] - R[0]
for i in range(n-1):
    minv = min(R[i], minv)
    maxv = max(R[i+1] - minv, maxv)

print(maxv)

Solution (Python):
n = int(input())

ans = -10000000000000000000
mn = 1000000000000000000
for i in range(n):
    x = int(input())
    ans = max(ans, x - mn)
    mn = min(mn, x)

print(ans)

Solution (Python):
n, *A = map(int, open(0).read().split())
m = A[0]
M = -float('inf')
for a in A[1:]:
    M = max(M, a-m)
    m = min(m, a)
print(M)

Solution (Python):




num = int(input())

rates = [int(input()) for i in range(num)]

maxv = -100000000000
minv = 100000000000

for i in range(len(rates)):
  maxv = max(maxv, rates[i] - minv)
  minv = min(minv, rates[i])

print(maxv)

Solution (Python):
n = int(input())
r = [int(input()) for _ in range(n)]
ans = -float("inf")
m = r[0]
for i in range(1,n):
    d = r[i]-m
    ans = max(d,ans)
    m = min(m,r[i])
print(ans)

Solution (Python):
n = int(input())
t = int(input())
mint = t
t1 = int(input())
if t1 < t:
    mint = t1
maxt = t1 - t

for i in range(2,n):
    t = int(input())
    if t -mint > maxt:
        maxt = t-mint
    
    if t < mint:
        mint = t

print(maxt)

Solution (Python):
N = int(input())
R = [int(input()) for _ in range(N)]
min_num = R[0]
now_profit = R[1] - R[0]
for i in range(1,N):
    now_profit = max(R[i]-min_num, now_profit)
    if min_num > R[i]:
        min_num = R[i]
print(now_profit)

Solution (Python):
N = int(input())
R = [int(input()) for _ in range(N)]

min_r = 10**10
max_d = -10**10
for i in range(N):
    if i != 0:
        d = R[i] - min_r
        if d > max_d:
            max_d = d
    if R[i] < min_r:
        min_r = R[i]
print(max_d)

Solution (Python):
n = int(raw_input())
r = [int(raw_input()) for _ in range(n)]

mn = r[0]
ans = 1000000000 * (-1)

for i in range(1, len(r), 1):
  ans = max(ans, r[i] - mn)
  mn = min(mn, r[i])

print ans

Solution (Python):
n = int(input())
min_value = int(input())
diff = (-1) * min_value

for i in range(n - 1):
    rt = int(input())
    diff = max(diff, rt - min_value)
    min_value = min(rt, min_value)

print(diff)

Solution (Python):
n = int(input())
ans = -10**10
old = int(input())
for _ in range(n-1):
    num = int(input())
    if num - old > ans:
        ans = num - old
    if num < old:
        old = num
print(ans)

Solution (Python):
N = int(input())
min_v = float("inf")
max_p = -float("inf")
for i in range(N):
    v = int(input())
    max_p = max(max_p,v-min_v)
    min_v = min(min_v,v)
print(max_p)

Solution (Python):
n=int(input())
min_val=10**10
ans=-(10**10)
for i in range(n):
    cu=int(input())
    ans=max(ans,cu-min_val)
    min_val=min(min_val,cu)
print(ans)

Solution (Python):
n = int(input())
minv = 10000000000
max_profit = -1 * minv
for i in range(n):
    r = int(input())
    max_profit = max(max_profit, r - minv)
    minv = min(minv, r)

print(max_profit)

Solution (Python):
n = int(input())
prev = 10**18
ans = -10**18
for i in range(n):
    r = int(input())
    ans = max(ans, r - prev)
    prev = min(prev, r)
print(ans)

Solution (Python):
N=int(input())

l=[int(input()) for x in range(N)]

l_min=l[0]
profit_max=l[1]-l[0]

for i in l[1:]:
    profit_max=max(profit_max,i-l_min)
    l_min=min(i,l_min)

print(profit_max)

Solution (Python):
n = int(input())
ans = -(10**99)
l = []
for _ in range(n):
    x = int(input())
    l.append(x)
mini = l[0]
for i in range(1, n):
    t = l[i] - mini
    if t > ans:
        ans = t

    if mini > l[i]:
        mini = l[i]


print(ans)

Solution (Python):

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


R.reverse()


j = R.index(max(R[0:n-1]))
i = R.index(min(R[j+1:n]))
str_max = R[j] - R[i]


if j+1 >= n-1:
    pass
else:
    
    while 1:
        
        j = R.index(max(R[j+1:n-1])) + j + 1
    
        
        if j+1 >= n-1:
            break
        
        
        i = R.index(min(R[j+1:n]))
        
        
        tmp = R[j] - R[i]
        if str_max < tmp:
            str_max = tmp


j = R.index(max(R[0:n-1]))
while 1:
    if j <= 0:
        break
    
    j = R.index(max(R[0:j]))
    i = R.index(min(R[j+1:n]))
    
    
    tmp = R[j] - R[i]
    if str_max < tmp:
        str_max = tmp

print(str_max)

Solution (Python):
import sys
times = int(input())
minv = int(input())
maxv = -sys.float_info.max
for i in range(1,times):
    r = int(input())
    maxv = max(maxv,r - minv)
    minv = min(minv,r)
print(maxv)

Solution (Python):
import sys


def main():
    array = []
    input_num = int(input())
    for v in range(input_num):
        array.append(int(input()))
    min_value = array[0]
    max_diff = array[1] - array[0]
    array = array[1:]
    for v in array:
        max_diff = max(max_diff, v - min_value)
        min_value = min(min_value, v)
    print(max_diff)


if(__name__ == '__main__'):
    main()

Solution (Python):
t = int(input())
minv = int(input())
maxv = -float('inf')

for i in range(1, t):
  r = int(input())
  maxv = max(maxv, r - minv)
  minv = min(minv, r)

print(maxv)

Solution (Python):
t = int(input())
minv = int(input())
maxv = -float('inf')

for i in range(1, t):
  r = int(input())
  maxv = max(maxv, r - minv)
  minv = min(minv, r)

print(maxv)

Solution (Python):
n = int(input())
R = [int(input()) for i in range(n)]
minv = R[0]
maxv = R[1]-R[0]
for j in range(1,n):
    if maxv < (R[j]-minv):
        maxv = R[j]-minv
    if minv > R[j]:
        minv = R[j]
print(maxv)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
L = [0] * N
L[0] = A[0]
for i in range(1, N):
    L[i] = min(L[i - 1], A[i])
R = [0] * N
R[-1] = A[-1]
for i in range(N - 2, -1, -1):
    R[i] = max(R[i + 1], A[i])
ans = R[-1] - L[0]
for i in range(N - 1):
    ans = max(ans, R[i + 1] - L[i])
print(ans)

Solution (Python):
def main(n,r):
    _dp = [-float('INF')]*n
    _dp[0]=r[1]-r[0]
    _min =r[0]
    for i in range(1,n):
        _min = min(_min, r[i-1])
        _dp[i] = max(_dp[i-1], r[i]-_min)
    print(_dp[-1])

n = int(input())
r = [int(input()) for _ in range(n)]
main(n,r)

Solution (Python):
N = int(input())
l = [int(input()) for _ in range(N)]

_min = l[0]
_max = 0
ans = -float("inf")


dp=[-float("inf")]*(N)

for i in range(1,N):
    pass
    dp[i] = max(dp[i-1]+l[i]-l[i-1],l[i]-l[i-1])
print(max(dp))

Solution (Python):
N=int(input())

base=int(input())
ans=-1000000000
for i in range(1,N):
    now=int(input())
    ans=max(ans,now-base)
    if now<base:
        base=now
    
print(ans)

Solution (Python):
n = int(input())
r = []
for _ in range(n):
    r.append(int(input()))

maxv = -float("inf")
minv = r[0]

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

print(maxv)

Solution (Python):
import sys
import math
input = sys.stdin.readline

def get_max(vec: list) -> int:
    reference = vec[0]
    diffs = -1 * 1e+9
    for x in vec[1:]:
        _diffs = reference - x
        if diffs < _diffs:
            diffs = _diffs
        if reference < x:
            reference = x
    return diffs

if __name__ == "__main__":
    n = int(input())
    res = 0
    vec = []
    for _ in range(n):
        vec.append(int(input()))
    print(get_max(list(reversed(vec))))

Solution (Python):
n = int(input())
R = [int(input()) for i in range(n)]

start = R[0]
max = R[1] - R[0]
for j in range(1, n):
    if (max < R[j] - start):
        max = R[j] - start
    if (R[j] < start):
        start = R[j]

print(max)

Solution (Python):
import math

n=int(input())
t=int(input())
mint=t
t1=int(input())
if t1<t: mint=t1
maxtt=t1-t


for i in range(2,n):
    t=int(input())
 
    if t-mint>maxtt: maxtt=t-mint
    if t<mint: mint=t
    
print(int(maxtt))

Solution (Python):
n = int(input())

min_v = 10**10+1
max_p = -10**10+1
for i in range(n):
    val = int(input())
    p = val - min_v
    if p>max_p:
        max_p = p
    
    if val<min_v:
        min_v = val

print(max_p)

Solution (Python):
n = int(input())
r = [int(input()) for i in range(n)]

maxv = -(10**9)
minv = r[0]
for j in range(1, len(r)):
    maxv = max(maxv, r[j] - minv)
    minv = min(minv, r[j])

print(maxv)

Solution (Python):
import math

def get_input():
    return int(input())

def max_profit(inputs):
  a = inputs[0]
  l = inputs[1:]
  r = 10 ** 10 * -1
  for i in l:
    p = i - a
    if p > r:
      r = p
    if i < a:
      a = i
  
  return r

n = get_input()
inputs = []
for _ in range(n):
  inputs.append(get_input())



print(max_profit(inputs))

Solution (Python):
n = int(input())
R = [int(input())]
min = R[0]
x = -1000000000
for i in range(1,n):
    R.append(int(input()))
    if R[i] - min > x:
        x = R[i] - min
    if R[i] < min:
        min = R[i]
print(x)

Solution (Python):
N = int(input())
num_list = [int(input()) for _ in range(N)]

temp_max_val = -1 * 10**9
temp_min = num_list[0]

for i in range(N-1):
    temp_max_val = max(temp_max_val, num_list[i+1] - temp_min)
    temp_min = min(temp_min, num_list[i+1])
    
    

print(temp_max_val)

Solution (Python):
n = int(input())
r = [int(input()) for _ in range(n)]

def get_max_ret(n, r):
    max_ret = r[1] - r[0]
    min_val = r[0]
    for i in range(1, n):
        ret = r[i] - min_val
        max_ret = max(max_ret, ret)
        min_val = min(r[i], min_val)
    return max_ret
    
max_return = get_max_ret(n, r)
print(max_return)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    a = []
    for i in range(n):
        a.append(int(input().strip()))
    m = INF
    ans = -INF
    for i in range(n):
        ans = max(ans, a[i] - m)
        if m > a[i]:
            m = a[i]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
r = []
for i in range(n):
    r.append(int(input()))

minv = r[0]
result = -float("inf")
for  i in range(1, n, 1):
    result = max(result, r[i] - minv)
    minv = min(minv, r[i])
print(result)

Solution (Python):
n = int(input())
R = [int(input()) for i in range(n)]
m = R[0]
L = [R[1]-m]
for i in range(1,n):
    L = [max(L[0],R[i]-m)]
    m = min(m,R[i])
print(L[0])

Solution (Python):
N, current_min, *R = map(int, open(0).read().split())

ret = -float("inf")
for r in R:
    ret = max(ret, r - current_min)
    current_min = min(current_min, r)
    
print(ret)

Solution (Python):
n = int(input())
m = 0
d = -1000000000
for i in range(n):
    v = int(input())
    if n == i + 1 and d == 0: d = v - m
    if m == 0:
        m = v
        continue
    d = d if d > v - m else v - m
    m = m if m < v else v
print(d)

Solution (Python):
import sys

N=int(input())

min=int(input())
max = None

for r in map(int, sys.stdin):
    if max is None or max < r - min:
        max = r-min
    if min > r:
        min = r

print(max)

Solution (Python):
n = int(input())
R = [int(input()) for i in range(n)]
res = -10e9
for i in range(n):
    if i == 0:
        minv = R[i]
    else:
        if res < R[i] - minv:
            res = R[i] - minv
        if R[i] < minv:
            minv = R[i]
print(res)

Solution (Python):
n = int(input())

t0 = int(input())
t1 = int(input())
minT = min(t0, t1)
answer = t1 - t0

for i in range(2, n):
    target = int(input())
    answer = max(answer, target - minT)
    minT = min(target, minT)

print(answer)

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
minv = a[0]
maxv = -(10**10)

for i in range(1,n):
    maxv = max(maxv, a[i]-minv)
    minv = min(minv, a[i])
print(maxv)

Solution (Python):
def main():
    n = int(input())
    l = list()

    for _ in range(n):
        l.append(int(input()))

    minv = l[0]
    maxv = -1000000000

    for j in range(1, n):
        maxv = max(l[j] - minv, maxv)
        minv = min(minv, l[j])

    print(maxv)

main()