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

    if R < R_min:
        R_min = R

print(R_max)

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

Solution (Python):
import sys

num = int(sys.stdin.readline().strip())

r0 = int(sys.stdin.readline().strip())
r1 = int(sys.stdin.readline().strip())

max_dis = r1 - r0
min_num = min(r0, r1)

for i in range(0, num-2):
    r = int(sys.stdin.readline().strip())
    max_dis = max(max_dis, r - min_num)
    min_num = min(min_num, r)

print max_dis

Solution (Python):
import sys
input()
mx = -float('inf')
res = mx
mn = int(input())
for i in map(int,sys.stdin.readlines()):
        if mx < i - mn:
            mx = i - mn
        if 0 > i - mn:
            mn = i
        res = max(mx,res)
print(res)

Solution (Python):
import sys
input()
mx = -float('inf')
res = mx
mn = int(input())
for i in map(int,sys.stdin.readlines()):
        if mx < i - mn:
            mx = i - mn
        if 0 > i - mn:
            mn = i
        res = max(mx,res)
print(res)

Solution (Python):
lines = int(input())
mini = int(input())
maxi = -1000000000
for i in range(1,lines):
    s = int(input())
    maxi = max(maxi,s - mini)
    mini = min(s,mini)
print(maxi)

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

maxv = -20000000000
minv = R[0]

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

print(maxv)

Solution (Python):


"""
?????§?????????
FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????
????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???
(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????

???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???
??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????
?±??????????????????????
"""
import math


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

min = a[0]
cnt = -1000000000
for j in range(1,n):
    x = a[j] - min
    if cnt < x:
        cnt = x

    if min > a[j]:
        min = a[j]
print(cnt)

Solution (Python):


"""
?????§?????????
FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????
????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???
(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????

???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???
??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????
?±??????????????????????
"""
import math


cnt = -1000000000

n = int(input().strip())
min = int(input().strip())

for i in range(1,n):
    a =int(input().strip())
    x = a - min
    if cnt < x:
        cnt = x
    if min > a:
        min = a
print(cnt)

Solution (Python):
cnt = int(input())
dif_max = -1000000000
v_min = 1000000000

for i in range(cnt):
    buf = int(input())
    if i > 0:
        dif_max = dif_max if buf - v_min < dif_max else buf - v_min
    v_min = buf if buf < v_min else v_min
print(dif_max)

Solution (Python):
def main():
    N = int(input())
    R = tuple(int(input()) for _ in range(N))

    min_ = float('inf')
    max_ = -float('inf')
    for i in range(N):
        max_ = max(max_, R[i] - min_)
        min_ = min(min_, R[i])

    print(max_)

main()

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

ans = data[1] - data[0]
x = data[0]

for d in data[1:]:
	ans = max(ans,d-x)
	x = min(d,x)

print(ans)

Solution (Python):
num=int(input())
r_1=int(input())
r_2=int(input())

max_profit=r_2-r_1
if r_1<r_2:
    min_value=r_1
else:
    min_value=r_2

for i in range(2,num):
    x=int(input())
    t=x-min_value
    if max_profit<t:
        max_profit=t
    if x<min_value:
        min_value=x
        
print(max_profit)

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

ma = L[1]-L[0]
mi = L[0]
for x in range(n-1):
    ma = max([ma,L[x+1]-mi])
    mi = min(mi,L[x+1])


print (ma)

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

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

for j,n in enumerate(num[1:]):
    maxv=max(maxv,n-minv)
    minv=min(minv,num[j+1])

print(maxv)

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

Solution (Python):
N = int(input())
R0 = int(input())
R1 = int(input())
max_profit = R1 - R0
min_R = min(R0, R1)

for i in range(N-2):
    R = int(input())
    max_profit = max(max_profit, R - min_R)
    min_R = min(min_R, R)

print(max_profit)

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

max = a[1] - a[0]
min_num = a[0]
for i in a[1:]:
    if i - min_num > max:
        max = i - min_num
    if min_num > i:
        min_num = i
print max

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


profit = -2**31
N = int(input())
min_so_far = int(input())
for _ in range(N - 1):
    r = int(input())
    profit = max(profit, r - min_so_far)
    min_so_far = min(min_so_far, r)
print(profit)

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

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

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

print(maxv)

Solution (Python):
n = int(input())
R = [int(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)

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

min_R = int(2e5)
ans = int(-2e5)

for i in range(n):
    R = int(raw_input())
    if i == 0:
        min_R = R
    else:
        ans = max(ans, R-min_R)
    if i == 1:
        ans = R - min_R
    if R < min_R:
        min_R = R

print ans

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

ans = int(-1e9)

for i in range(n):
    R = int(raw_input())
    if i == 0:
        min_R = R
    else:
        ans = max(ans, R-min_R)
        min_R = min(min_R, R)

print ans

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

ans = -10**9

for i in range(n):
    R = int(raw_input())
    if i == 0:
        min_R = R
    else:
        ans = max(ans, R-min_R)
        min_R = min(min_R, R)

print ans

Solution (Python):
N = int(input())
P, m = - 10 ** 9, int(input())
for _ in range(1, N):
    n = int(input())
    P = n - m if n - m > P else P
    m = n if m > n else m
print(P)

Solution (Python):
i = 1
n = int(input())
maxR = -10**9
minR = int(input())
while i < n:
    R = int(input())
    maxR = max(maxR, R-minR)
    minR = min(minR, R)
    i += 1
print(maxR)

Solution (Python):
a, b = -1e9, 1e10
for n in range(int(input())):
    c = int(input())
    a, b = max(a, c - b), min(b, c)
print(a)

Solution (Python):



"""
"""


from collections import ChainMap
from collections import Counter
from collections import defaultdict
from collections import deque
from collections import namedtuple
import bisect
import copy
import decimal
import fractions
import functools
import heapq
import itertools
import math
import operator
import pprint
import random
import re
import sys
import time

try:
    import numpy as np
    import scipy as sp
except:
    pass



def is_odd(x):
    return x % 2 == 1

def is_even(x):
    return x % 2 == 0

def cmp(x, y):
    return (x > y) - (x < y)

def sgn(x):
    return cmp(x, 0)

def clamp(x, lo, hi):
    assert lo <= hi
    if x < lo:
        return lo
    elif x > hi:
        return hi
    else:
        return x

def chmax(xmax, x):
    if x > xmax:
        return x, True
    else:
        return xmax, False

def chmin(xmin, x):
    if x < xmin:
        return x, True
    else:
        return xmin, False

sys.setrecursionlimit(100000)



PINF = float("inf")
NINF = float("-inf")
EPS  = 1e-9



def main():
    N = int(input())
    R = [int(input()) for _ in range(N)]

    ansmax = NINF
    rmin = R[0]
    for r in R[1:]:
        ansmax, _ = chmax(ansmax, r-rmin)
        rmin, _   = chmin(rmin, r)

    print(ansmax)

if __name__ == "__main__": main()

Solution (Python):
a = -1e9
b = 2e9
for n in range(int(input())):
    r = int(input())
    a = max(a, r - b)
    b = min(b, r)
print(a)

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

minv = int(input())
maxv = -2000000000
for i in range(1, n):
    d = int(input())
    maxv = max(maxv, d - minv)
    minv = min(minv, d)

print(maxv)

Solution (Python):
n = int(input())
r = [int(input()) for i in range(n)]
v_max = -10**9
r_min = r[0]
for i in range(1,n):
    v_max = max(v_max,r[i] - r_min)
    r_min = min(r_min,r[i])
print(v_max)

Solution (Python):
def listFromInput():
    N=int(input())
    numbers=[]
    for i in range(N):
        numbers.append(int(input()))
    return numbers
R=listFromInput()
min=10000000000
max=-10000000000
for i in range(len(R)):
    if R[i]-min > max:
        max=R[i]-min
    if min > R[i]:
        min=R[i]
print(max)

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

print(maxv)

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

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

m = pl[0]
M = pl[0]
difM = pl[1]-pl[0]

for i, p in enumerate(pl[1:]):
    if p < m: 
        m = p
        continue
    if p - m > difM:
        difM = p - m

print(difM)

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

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

mini = l[0]
maxi = l[1] - l[0]

for num in l[1:]:
    maxi = max(maxi, num  - mini)
    mini = min(mini, num)

print(maxi)

Solution (Python):
import sys
 
n = int(input())
r0 = int(input())
r1 = int(input())
mx = r1 - r0
mn = min(r1, r0)
 
for i in map(int, sys.stdin.readlines()):
    if mx < i - mn:
        mx = i - mn
    if mn > i:
        mn = i
 
print(mx)

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

std = int(input())
val = []
alldiff = []
for i in range(n-1):
    a = int(input())
    alldiff.append(a-std)
    if i == n-2:
        val.append(a-std)
    else:
        if std > a:
            std = a
        else:
            val.append(a-std)

print(max(max(val),max(alldiff)))

Solution (Python):
n = int(input())
a = [int(input()) for i in range(n)]
minr = a[0]
ans = -float('inf')
for i in range(1, n):
    ans = max(a[i]-minr, ans)
    minr = min(a[i], minr)
print(ans)

Solution (Python):
n, Pmax, Rmin  = int(input()), float('-inf'), float('inf')
for i in range(n):
    v = int(input())
    Pmax, Rmin = max(Pmax, v-Rmin), min(Rmin, v)
print(Pmax)

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

Solution (Python):
n = int(input())
a = int(input())
Max = -10 ** 9
Min = a
for i in range(n-1):
    x = int(input())
    if (Max < x - Min):
        Max = x - Min
    if (x < Min):
        Min = x
print(Max)

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

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

maxv = -2000000000
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(raw_input())

deglist = []
for i in range(n):
	deglist.append(int(raw_input()))

min = 10**9
max_profit = -(10**9)
for j in range(1,len(deglist)):
	if min > deglist[j-1]:
		min = deglist[j-1]
	if max_profit < deglist[j] - min:
		max_profit = deglist[j] - min
	

print max_profit

Solution (Python):
import sys
readline = sys.stdin.readline
min_r = 1e10
ans = -1e10
n = int(readline())
for i in range(n):
    r = int(readline())
    if ans < r - min_r:
        ans = r - min_r
    if min_r > r:
        min_r = r
print(ans)

Solution (Python):
import sys
INF = float("inf")
readline = sys.stdin.readline
min_r = INF
ans = -INF
n = int(readline())
for i in range(n):
    r = int(readline())
    if ans < r - min_r:
        ans = r - min_r
    if min_r > r:
        min_r = r
print(ans)

Solution (Python):
import sys
INF = float("inf")
readline = sys.stdin.readline
min_r = INF
ans = -INF
n = int(readline())
for _ in [0] * n:
    r = int(readline())
    if ans < r - min_r:
        ans = r - min_r
    if min_r > r:
        min_r = r
print(ans)

Solution (Python):
import sys
n = int(input())
r0 = int(input())
r1 = int(input())
mx = r1-r0
mn = min(r1, r0)
for i in map(int,sys.stdin.readlines()):
    mx = max(mx, i - mn)
    mn = min(mn, i)
print(mx)

Solution (Python):
n = int(input())
e_min = 1000000000
x        =- 1000000000

for i in range(n):
    e1 = int(input())
    if i>0 and x < e1 - e_min:
        x = e1 - e_min
    e_min = min(e_min,e1)
print(x)

Solution (Python):
n = int(input())
min_n = 2 * 10**9
max_n = -2 * 10**9
for i in range(n):
    x = int(input())
    max_n = max(max_n,x - min_n)
    min_n = min(x,min_n)
print (max_n)

Solution (Python):
def main() :
    n = int(input())
    nums = []
    for i in range(n) :
        x = int(input())
        nums.append(x)

    max = float("-inf")
    min = nums[0]
    for i in range(1,n) :
        if nums[i] - min > max :
            max = nums[i] - min

        if nums[i] < min :
            min = nums[i]

    print(max)



if __name__ == '__main__' :
    main()

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

minNum = nums[0]
maxDiff = False
for i in nums[1:]:
    diff = i - minNum
    if maxDiff == False or diff > maxDiff:
        maxDiff = diff
    if minNum > i:
        minNum = i

print(maxDiff)

Solution (Python):
dif = -1E9
n = int(input())
mn = int(input())
for i in range(n - 1):
    r = int(input())
    if r - mn > dif:
        dif = r - mn
    if r < mn:
        mn = r
print(dif)

Solution (Python):
x = int(input())
l=[]
for i in range(x):
    l.append(int(input()))
MIN = 999999999999999999999999999999999999999
MAX = -9999999999999999999999999999999999999
for i in l:
    if i - MIN > MAX:
        MAX = i - MIN
    if i < MIN:
        MIN = i
print(MAX)

Solution (Python):

"""
Created on Sun Aug 28 21:09:30 2016

@author: you
"""

n = int(input())

b = int(input())
maxv = b
minv = b

price = -1000000000

for i in range(n-1):
    x = int(input())
    flag = (x-b > 0)
    if flag:
        maxv = max(maxv, x)
        price = max(price, maxv-minv)
    else:
        if x < minv:
            minv = x
            maxv = x
        if price < x-b:
            price = x-b
    b = x

print(price)

Solution (Python):

"""
Created on Sun Aug 28 21:09:30 2016

@author: you
"""

n = int(input())

b = int(input())
maxv = b
minv = b

price = -1000000000

for i in range(n-1):
    x = int(input())
    flag = (x-b > 0)
    if flag:
        price = max(price, x-minv)
    else:
        if x < minv:
            minv = x
            maxv = x
        if price < x-b:
            price = x-b
    b = x

print(price)

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



'''
n = 6
t=[4,1,5,7,5,4]
'''


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

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

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

print(maxv)

Solution (Python):
import sys

ERROR_INPUT = 'input is invalid'


def main():
    num = int(input())
    if num < 2 or 200000 < num:
        print(ERROR_INPUT)
        sys.exit(1)

    prices = [check_price(price=int(input())) for _ in range(num)]

    print(calc_max_diff(prices=prices))
    return 0


def check_price(price):
    if price < 1 or price > 10 ** 9:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return price


def calc_max_diff(prices):
    min_price = prices[0]
    max_diff = prices[1] - prices[0]

    for p in prices[1:]:
        if max_diff < p - min_price:
            max_diff = p - min_price
        if p < min_price:
            min_price = p

    return max_diff


if __name__ == '__main__':
    main()

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

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









mx = R[1] - R[0]
mn = min(R[:2])

for r in R[2:]:
    if mx < r-mn:
        mx = r-mn
    elif mn > r:
        mn = r

print(mx)

Solution (Python):

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

maxv = -999999999
minv = r[0]
for i in range(1,n):
    if (r[i] - minv) > maxv:
        maxv = r[i] - minv
    if r[i] < minv:
        minv = r[i]
print(maxv)

Solution (Python):


import sys
import math

class Algo:
  @staticmethod
  def profit(r, n):
    maxv = r[1] - r[0]
    minv = r[0]

    for i in range(1, n):
      if r[i-1] < minv:
        minv = r[i-1]
      if r[i]-minv > maxv:
        maxv = r[i]-minv
    
    print(maxv)

N = int(input())
R = []
for i in range(0,N):
  R.append(int(input()))
Algo.profit(R, N)

Solution (Python):
N = int(input())
data = []
for _ in range(N):
    data.append(int(input()))
maxv = -10**9
mind = data[0]
for i in data[1:]:
    if maxv < i - mind: maxv = i - mind
    if mind > i:mind = i
print(maxv)

Solution (Python):
import sys
 
n = int(input())
r0 = int(input())
r1 = int(input())
mx = r1-r0
mn = min(r1,r0)
 
for i in map(int,sys.stdin.readlines()):
    if mx < i - mn:
        mx = i - mn
        if 0 > i-mn:
            mn = i
    elif mn > i:
        mn = i
 
print(mx)

Solution (Python):
import sys

n = int(input())
r0 = int(input())
r1 = int(input())
mx = r1 - r0
mn = min(r1, r0)

for i in map(int, sys.stdin.readlines()):
    if mx < i - mn:
        mx = i - mn
        if 0 > i - mn:
            mn = i
    elif mn > i:
        mn = i

print(mx)

Solution (Python):
import sys

n = int(input())
mx = -2000000000
mn = int(input())

for i in map(int, sys.stdin.readlines()):
    mx = max(mx, i - mn)
    mn = min(mn, i)

print(mx)

Solution (Python):
R = [int(input()) for _ in range(int(input()))]
ax = -2000000000000
mn = R[0]
for h,i in enumerate(R):
    if h == 0:
        continue
    ax = max([ax, i - mn])
    mn = min([mn, i])
print(ax)

Solution (Python):
N=int(input())
A=[int(input()) for _ in range(N)]
mp=A[1]-A[0]
mn=A[0]
for i in range(1,N):
    if mp < (A[i]-mn):
        mp=A[i]-mn
    if A[i]<mn:
        mn=A[i]
print(mp)

Solution (Python):
N=int(input())
A=[int(input()) for _ in range(N)]
mp=A[1]-A[0]
mn=A[0]
for i in range(1,N):
    if mp < (A[i]-mn):
        mp=A[i]-mn
        if 0>A[i]-mn:
            mn = A[i]
    if A[i]<mn:
        mn=A[i]
print(mp)

Solution (Python):
N=int(input())
A=[int(input()) for _ in range(N)]
mp=A[1]-A[0]
mn=A[0]
for i in range(1,N):
    x=A[i]
    if mp < (x-mn):
        mp=x-mn
        if 0>x-mn:
            mn = x
    if x<mn:
        mn=x
print(mp)

Solution (Python):
i=input
r=range
N=int(i())
A=[int(i()) for _ in r(N)]
mp=A[1]-A[0]
mn=A[0]
for a in r(1,N):
    x=A[a]
    b=x-mn
    if mp<(b):
        mp=b
        if 0>b:mn=x
    if x<mn:mn=x
print(mp)

Solution (Python):
import sys
i=input
n = int(i())
r0 = int(i())
r1 = int(i())
mx = r1-r0
mn = min(r1,r0)
for i in map(int,sys.stdin.readlines()):
    a=i-mn
    if mx<a:
        mx=a
        if 0>a:mn=i
    elif mn>i:mn=i
print(mx)

Solution (Python):
import sys
i=input
n = int(i())
r0 = int(i())
r1 = int(i())
x = r1-r0
y = min(r1,r0)
for i in map(int,sys.stdin.readlines()):
    a=i-y
    if x<a:
        x=a
        if 0>a:y=i
    elif y>i:y=i
print(x)

Solution (Python):
import sys
i=input
n=int(i())
r0=int(i())
r1=int(i())
x=r1-r0
y=min(r1,r0)
for i in map(int,sys.stdin.readlines()):
    a=i-y
    if x<a:
        x=a
        if 0>a:y=i
    elif y>i:y=i
print(x)

Solution (Python):
N =int(input())
R = []
for i in range(N):
        R.append(int(input()))
maxv=-2000000000
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
i=input
n =int(i())
r0=int(i())
r1=int(i())
maxv=r1-r0
minv=min(r1,r0)
for i in map(int,sys.stdin.readlines()):
    maxv=max(maxv,i-minv)
    minv=min(minv,i)
print(maxv)

Solution (Python):
if __name__ == '__main__':
	n = int(input())
	lists = list()

	for i in range(n):
		a = int(input())
		lists.append(a)

	S = None
	while len(lists) > 1:
		mini = min(lists)
		mini_ind = lists.index(mini)
		l = len(lists)

		if mini_ind + 1 == l:
			if S is None or S < lists[mini_ind] - lists[mini_ind - 1]:
				S = lists[mini_ind] - lists[mini_ind - 1]
			lists.pop(mini_ind)
			continue


		maxi = max(lists[mini_ind : l])
		T = maxi - mini

		if S is None or S < T:
			S = T

		lists = lists[0 : mini_ind]
		continue

	print(S)

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

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

Solution (Python):


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

    return maxv

def maximum_profit_2(n, R):
    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])

    return maxv

if __name__ == '__main__':

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

    ans = maximum_profit_2(n ,R)
    print(ans)

Solution (Python):
n = int(input())
minv = int(input())
maxv = -10000000000

for _ in range(1, n):
    r = int(input())
    if maxv < r - minv:
        maxv = r - minv
    if minv > r:
        minv = r

print(maxv)

Solution (Python):
count = 0

number = int(input())

inarr = number * [0]

for i in range(number):
    inarr[i] = int(input())

res = inarr[number - 1] - inarr[number - 2]
maxsell = inarr[number - 1]

for i in range(number - 2, -1, -1):
    tmpres = maxsell - inarr[i]
    if res < tmpres:
        res = tmpres
    if maxsell < inarr[i]:
        maxsell = inarr[i]

print(res)

Solution (Python):
n = int(input())
min_r = int(input())
max_r = -1e10
for _ in range(n - 1):
    r = int(input())
    max_r = max(max_r, r - min_r)
    min_r = min(min_r, r)
print(max_r)

Solution (Python):
import sys
readline = sys.stdin.readline
n = int(input())
min_r = int(input())
max_r = -1e10
for _ in range(n - 1):
    r = int(readline())
    max_r = max(max_r, r - min_r)
    min_r = min(min_r, r)
print(max_r)

Solution (Python):
import sys
readline = sys.stdin.readline
n = int(input())
min_r = int(input())
max_r = -1e10
for _ in range(n - 1):
    r = int(readline())
    if max_r < r - min_r:
        max_r = r - min_r
    if min_r > r:
        min_r = r
print(max_r)

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

Solution (Python):
b,s=-1e10,1e10
for _ in range(int(input())):
 r=int(input())
 b,s=max(b,r-s),min(s,r)
print(b)

Solution (Python):
b,s=-1e10,1e10
for _ in range(int(input())):
 r=int(input())
 b,s=max(b,r-s),min(s,r)
print(b)

Solution (Python):
b,s=-1e10,1e10
for _ in range(int(input())):
 r=int(input())
 b,s=max(b,r-s),min(s,r)
print(b)

Solution (Python):
b,s=-1e10,1e10
for _ in range(int(input())):
 r=int(input())
 b,s=max(b,r-s),min(s,r)
print(b)

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

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

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

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

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

Solution (Python):
import sys
b,s=-1e10,1e10
input()
for r in map(int,sys.stdin.readlines()):
 b,s=(b,r-s)[b<r-s],(s,r)[s>r]
print(b)

Solution (Python):
import sys
b,s=-1e10,1e10
input()
for r in map(int,sys.stdin.readlines()):
 b,s=(b,r-s)[b<r-s],(s,r)[s>r]
print(b)

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

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

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

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

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

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

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

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

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

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

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

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

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


for v in range(n):
    num = int(input())
    nums.append(num)

ma = -1000000000
mi = nums[0]
for p in range(1,len(nums)):
    a = nums[p]
    if a-mi > ma:
        ma = a-mi
    if a < mi:
        mi = a
    
        

    
        
print(ma)

Solution (Python):
count = int(input());
data = [];
for i in range(count):
    data.append(int(input()));

def max_profit(data):
    profit = -10 ** 18;
    prev = 10 ** 18;
    for n in data:
        profit = max(profit, n - prev);
        prev = min(prev, n);
    return profit;

print(max_profit(data));

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

before = int(input())
current = int(input())
diffMax = current - before
current = min(current, before)
for i in range(n - 2):
  number = int(input())
  diff = number - current
  diffMax = max(diff, diffMax)
  current = min(current, number)
print(diffMax)

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

for i in range(N):
    tmp = int(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)

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

value1 = int(input())
value2 = int(input())
maxDiff = value2 - value1
minValue = min(value1, value2)
for i in range(n - 2):
  value = int(input())
  diff = value - minValue
  maxDiff = max(diff, maxDiff)
  minValue = min(value, minValue)
print(maxDiff)

Solution (Python):
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

answer = numbers[2] - numbers[1]
tmp_min = numbers[1]
for target in range(2, len(numbers)):
	answer =  max(numbers[target] - tmp_min ,answer)
	tmp_min = min(numbers[target] , tmp_min)

print(answer)

Solution (Python):
n=int(input())
r=[int(input()) for i in range(n)]
num=-10**9-1
v_min=-num

for i in range(n-1):
    v_min=min(v_min,r[i])
    num=max(r[i+1]-v_min,num)


print(num)

Solution (Python):
def maxp(rs):
    maxv = rs[1] - rs[0]
    minv = rs[0]

    for j in range(1, len(rs)):
        if rs[j] - minv > maxv:
            maxv = rs[j] - minv
        if rs[j] < minv:
            minv = rs[j]

    return maxv

if __name__ == '__main__':

    n = int(input())
    rs = []
    for _ in range(n):
        rs.append(int(input()))

    print(maxp(rs))

Solution (Python):
minv = 10000000000
maxv = -10000000000
n = input()
for _ in range(int(n)):
    m = int(input())
    maxv = max(maxv, m - minv)
    minv = min(minv, m)
print (maxv)

Solution (Python):
num = int(input())
m = 2147483647
ans = -2147483647
for i in range(num):
    new = int(input())
    ans = max([new - m, ans])
    m = min(m, new)
print(ans)

Solution (Python):
n, rate_min = int(input()), int(input())
for i in range(1, n):
    rate_t = int(input())
    prof = rate_t - rate_min
    if i==1:
        max_prof = prof
    elif max_prof < prof:
        max_prof = prof
    if rate_t < rate_min:
        rate_min = rate_t
print(max_prof)

Solution (Python):
length = int(input())
minv = int(input())
maxv = -2000000000
for j in range(1, length):
    hoge = int(input())
    maxv = max(maxv, hoge-minv)
    minv = min(minv, hoge)
print (maxv)

Solution (Python):

n = int(raw_input())
value_list = []
diff_indx1 = 0
diff_indx2 = 0
diff = None
for i in range(n):
    value_list.append(int(raw_input()))
    if i == 1:
        diff = value_list[1] - value_list[0]
        diff_indx1 = 1
    if value_list[i] >= value_list[diff_indx1]:
        diff2 = value_list[i] - value_list[diff_indx2]
        
        if diff <= diff2:
            diff = diff2
            diff_indx1 = i
            diff_indx2 = diff_indx2
            
    if value_list[diff_indx2] > value_list[i]:
        diff_indx2 = i
        diff_indx1 = i
        
print diff

Solution (Python):
init = None
diff = None
for p in range(int(input())):
    v = int(input())
    if init is None:
        init = v
        continue
    if diff is None:
        diff = v - init
    if v - init > diff:
        diff = v - init
    if init > v:
        init = v

print(diff)

Solution (Python):


N = int(input())
datas = [int(input()) for _ in range(N)]

now_max = max(datas[1:])
max_index = datas.index(now_max)
diff = now_max - datas[0]

for i in range(1,N-1):
    if i == max_index:
        d = datas[i+1:]
        now_max = max(d)
        max_index = d.index(now_max)+i+1
    new_diff = now_max - datas[i]
    if diff < new_diff:
        diff = new_diff

print(diff)

Solution (Python):
n = int(input())
min, diff = int(input()), - 10**9
for _ in range(n - 1):
    r = int(input())
    if r - min > diff:
        diff = r - min
    if r < min:
        min = r
print(diff)