Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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) &times; 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



Sample input:
6
5
3
1
3
4
3


Sample output:
3

Submission status: Wrong Answer

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

maxR = R[1]
minR = R[0]
maxB = R[1] - R[0]
for i in range(1,n):
 if R[i] < minR:
  minR = R[i] - 1
  maxR = R[i]
 elif minR <= R[i] and R[i] <= maxR:
  continue
 else:
  maxR = R[i]
  if maxR - minR > maxB:
   maxB = maxR - minR

print(str(maxB))

Submission status: Wrong Answer

Solution code:
n = int(input())

minv = int(input())
maxv = int(input()) - minv

for j in range(n-2):
    rt = int(input())
    maxv = max(maxv,rt - minv)
    minv = min(minv,rt)

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())

rt = [input() for i in range(n)]

minv = int(rt[0])
maxv = int(rt[1]) - int(rt[0])

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

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())

rt = [input() for i in range(n)]

minv = int(rt[0])
maxv = int(rt[1]) - int(rt[0])

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

print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = [None] * n
min = 10**9
max = -10**9
for i in range(n):
    r[i] = int(input())

for i in range(n):
    if min > r[i]:
        min = r[i]
        for j in range(i+1,n):
            if max < r[j] - min:
                max = r[j] - min
print(max)

Submission status: Wrong Answer

Solution code:
#coding: utf-8

n = int(input())
R = []

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

max_dif = -200000
min_value = R[0]

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

print(max_dif)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 16 18:45:04 2017

@author: syaga
"""

if __name__ == "__main__":
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    max = a[1] - a[0]
    for i in range(2, len(a)-1):
        for j in range(1, i):
            diff = i - j
            if diff > max:
                max = diff
    print(max)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 16 18:45:04 2017

@author: syaga
"""

if __name__ == "__main__":
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    max = a[1] - a[0]
    for i in range(2, len(a)):
        for j in range(1, i):
            diff = i - j
            if diff > max:
                max = diff
    print(max)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 16 18:45:04 2017

@author: syaga
"""

if __name__ == "__main__":
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    max = a[1] - a[0]
    for i in range(2, len(a)):
        for j in range(1, i):
            diff = a[i] - a[j]
            if diff > max:
                max = diff
    print(max)

Submission status: Wrong Answer

Solution code:
maxv = -1 * (10 ** 9) - 1
minv = 10 ** 9 + 1

n = int(input())

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

print(maxv)

Submission status: Wrong Answer

Solution code:
max = -(10**8)
n = int(input())
r0 = int(input())
min = r0
for i in range(n-1):
    x = int(input())
    if max < x - min:
        max = x - min
    if x < min:
        min = x
print(max)

Submission status: Wrong Answer

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

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

print(R_max)

Submission status: Wrong Answer

Solution code:
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-1],minv)
print(maxv)

Submission status: Wrong Answer

Solution code:
import sys

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)

Submission status: Wrong Answer

Solution code:
import sys

mx = int(input())
res = -float('inf')
mn = float('inf')
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)

Submission status: Wrong Answer

Solution code:
import sys
input()
mx = int(input())
res = -float('inf')
mn = float('inf')
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)

Submission status: Wrong Answer

Solution code:
N = int(input('R ?????????: '))
R = [int(input('R[%s]: ' % (str(i)))) for i in range(N)]

maxv = -20000000000
minv = R[0]

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

print('?????§??????: ' + str(maxv))

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
 
N = int(input('R ?????????: '))
R = [int(input('R[%s]: ' % (str(i)))) for i in range(N)]

# ?????§??????
maxv = -20000000000
# ????°????
minv = R[0]

for i in range(1, N):
    # TODO: maxv ??¨ R[i] - minv ???????????§?????????
    if R[i] - minv > maxv:
        maxv = R[i] - minv
    # TODO: minv ??¨ R[i] ??????????°??????????
    if minv > R[i]:
        minv = R[i]

print(maxv)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
 
N = int(input('R ?????????: '))
R = [int(input('R[%s]: ' % (str(i)))) for i in range(N)]

# ?????§??????
maxv = -20000000000
# ????°????
minv = R[0]

for i in range(N):
    # TODO: maxv ??¨ R[i] - minv ???????????§?????????
    if R[i] - minv > maxv:
        maxv = R[i] - minv
    # TODO: minv ??¨ R[i] ??????????°??????????
    if minv > R[i]:
        minv = R[i]

print(maxv)

Submission status: Wrong Answer

Solution code:
N = int(input('R ?????????: '))
R = [int(input('R[%s]: ' % (str(i)))) for i in range(N)]
print(R)

# ?????§??????
maxv = -20000000000
# ????°????
minv = R[0]

for i in range(1, N):
    print(R[i])
    # maxv ??¨ r - minv ???????????§?????????
    maxv = max(R[i] - minv, maxv)
    # minv ??¨ r ??????????°??????????
    minv = min(R[i], minv)

print('============================')
print(maxv)

Submission status: Wrong Answer

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

# ?????§??????
maxv = -20000000000
# ????°????
minv = R[0]

for i in range(1, N):
    # maxv ??¨ r - minv ???????????§?????????
    maxv = max(R[i] - minv, maxv)
    # minv ??¨ r ??????????°??????????
    minv = min(R[i], minv)

print(maxv)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [int(input(i)) 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)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????§?????????
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 = 10000000000
cnt = -1000000000
for j in range(1,n):
    if min > a[j]:
        min = a[j]
    x = a[j] - min
    if cnt < x:
        cnt = x
#    print("cnt={0} min={1} Rj={2}".format(cnt,min,a[j]))
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????§?????????
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 = 10000000000
cnt = -1000000000
for j in range(0,n):
    if min > a[j]:
        min = a[j]
    x = a[j] - min
    if cnt < x:
        cnt = x
#    print("cnt={0} min={1} Rj={2}".format(cnt,min,a[j]))
print(cnt)

Submission status: Wrong Answer

Solution code:
v = []
v = str(input()).splitlines()
dif_max = -200000
dif_max = -200000

for i in range(len(v) ):
    v[i] = int(v[i])

for i in range(len(v) - 1):
    for j in range(i + 1, len(v), 1):
        dif = v[j] - v[i]
        dif_max = dif if dif_max < dif else dif_max

print("{}".format(dif_max))

Submission status: Wrong Answer

Solution code:
def Meu(inp):
    v = []
    v = str(inp).splitlines()
    dif_max = -200000

    for i in range(len(v) ):
        v[i] = int(v[i])

    for i in range(len(v) - 1):
        for j in range(i + 1, len(v), 1):
            dif = v[j] - v[i]
            dif_max = dif if dif_max < dif else dif_max
    print("{}".format(dif_max))


Meu("6\n2\n3\n1\n3\n4\n3")

Submission status: Wrong Answer

Solution code:
v = []
v = str(input()).splitlines()
dif_max = -200000

for i in range(len(v)):
    v[i] = int(v[i])

for i in range(len(v) - 1):
    for j in range(i + 1, len(v), 1):
        dif = v[j] - v[i]
        dif_max = dif if dif_max < dif else dif_max
print("{}".format(dif_max))

Submission status: Wrong Answer

Solution code:
inp = ("6\n2\n3\n1\n3\n4\n3")

v = []
v = str(inp).splitlines()
dif_max = -200000

for i in range(len(v)):
    v[i] = int(v[i])

len = v[0]
for i in range(2, len + 1, 1):
    for j in range(i + 1, len + 1, 1):
        dif = v[j] - v[i]
        dif_max = dif if dif_max < dif else dif_max

print("{}".format(dif_max))

Submission status: Wrong Answer

Solution code:
v = str(input()).split()
dif_max = -200000

for i in range(len(v)):
    v[i] = int(v[i])

print(v[i])

Submission status: Wrong Answer

Solution code:
v=[]
v = str(input()).split()
dif_max = -200000

for i in range(len(v)):
    v[i] = int(v[i])

print(v[i])

Submission status: Wrong Answer

Solution code:
cnt = int(input())
v = []

for i in range(cnt):
    v.append(int(input()))

len = len(v)
dif_max = -100000000
for i in range(1, len, 1):
    for j in range(i + 1, len, 1):
        dif = v[j] - v[i]
        dif_max = dif if dif_max < dif else dif_max

print(dif_max)

Submission status: Wrong Answer

Solution code:
cnt = int(input())
v = []

for i in range(cnt):
    v.append(int(input()))

len = len(v)
dif_max = -100000000

for i in range(len):
    for j in range(i + 1, len, 1):
        dif = v[j] - v[i]
        dif_max = dif if dif_max < dif else dif_max

print(dif_max)

Submission status: Wrong Answer

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

for i in range(cnt):
    buf = int(input())
    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)

Submission status: Wrong Answer

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

for i in range(cnt):
    buf = int(input())
    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)

Submission status: Wrong Answer

Solution code:
num=int(input())
init=int(input())
min_v=init
max_v=-200000
for i in range(num-1):
    price=int(input())
    profit=price - min_v
    if profit>max_v:
        max_v=profit
    if price<min_v:
        min_v=price
print(max_v)

Submission status: Wrong Answer

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

    diff = []
    for i in range(N - 1):
        diff.append(R[i+1] - R[i])

    max_ = -float('inf')
    gain = 0
    for i in diff:
        if i < 0:
            max_ = max(max_, gain)
            gain = 0
        else:
            gain += i

    print(max_)

main()

Submission status: Wrong Answer

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

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

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

print(maxv)

Submission status: Wrong Answer

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

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

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

print(maxv)

Submission status: Wrong Answer

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

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

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

print(maxv)

Submission status: Wrong Answer

Solution code:
N=int(input())
sub=1-1000000000
for i in range(N):
    if i==0:
        a=int(input())
        continue
    b=int(input())
    if b-a>sub:
        sub=b-a
    a=b
print(sub)

Submission status: Wrong Answer

Solution code:
sub=1-1000000000
n=int(input())
for i in range(n):
    if i==0:
        a=int(input())
        continue
    b=int(input())
    if sub<b-a:
        sub=b-a
    a=b
print(sub)

Submission status: Wrong Answer

Solution code:
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:
    minv= min(minv,j)
    maxv= max(maxv,j-minv)

print(maxv)

Submission status: Wrong Answer

Solution code:
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 R < min_R:
        min_R = R

print ans

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

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)
        min_R = min(min_R, R)

print ans

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

ans = int(-2e6)

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

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

ans = int(-2e8)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

l = []
for i, p in enumerate(pl[:-1]):
    l.append(max(pl[i+1:])-p)

m = max(l)
if m > 0: print(m)
else: print(-1)

Submission status: Wrong Answer

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

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

l = []
for i, p in enumerate(pl[:-1]):
    l.append(max(pl[i+1:])-p)

m = max(l)
if m >= 0: print(m)
else: print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

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

print(maxi)

Submission status: Wrong Answer

Solution code:
n= int(input())

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

print(max(val))

Submission status: Wrong Answer

Solution code:
n, Rmin, R2 = [int(input()) for i in  range(3)]
Pmax = R2 - Rmin
for i in range(n-2):
    v = int(input())
    Pmax, Rmin = max(Pmax, v-Rmin), min(Rmin, v)
print(Pmax)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
elem = 0
a = []
sub = []
for i in range(n):
	elem = int(input().strip())
	a.append(elem)
for i in range(1,len(a)):
	elem = a[i] - a[i-1]
	if elem not in sub:
		sub.append(elem)
print(max(sub))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = int(input())
Max = -999999
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)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = int(input())
Max = -999999
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)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = int(input())
Max = -9999999
Min = a
for i in range(1, n):
    x = int(input())
    if (Max < x - Min):
        Max = x - Min
    if (x < Min):
        Min = x
print(Max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = int(input())
Max = -9999999
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)

Submission status: Wrong Answer

Solution code:
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:
    max = min
print(max)

Submission status: Wrong Answer

Solution code:
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:
    max = r
print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = int(input())
Max = -200000
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)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = []
for i in range(N):
    R.append(int(input()))
maxval , minval = R[1] - R[0] , min(R[0] , R[1] )

for i in range(1,N):
    if maxval < R[i] - minval :
        maxval = R[i] - minval
        if minval > R[i] :
            minval = R[i]
    elif minval > R[i]:
        minval = R[i]
print(maxval)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
min_r = 1e9
ans = -1e9
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)

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[]
m=-10**2
for i in range(n):
    r.append(int(input()))
for i in range(n):
    for j in range(i+1,n):
         d=r[j]-r[i]
         if d > m:
             m=d
print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[]
for i in range(n):
    r.append(int(input()))
m=sorted(r, reverse=True)
for i in range(n):
    p=m[i]
    l=sorted(r[:r.index(m[i])+1])
    if len(l) > 0:
        break
print(p-l[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[]
for i in range(n):
    r.append(int(input()))
#m=sorted(r, reverse=True)
p=max(r[1:])
s=sorted(r, reverse=True)
q=min(s[s.index(p)+1:])
a=p-q
q=min(r[:len(r)-1])
#print(q)
p=max(r[r.index(q)+1:])
#print(p)
b=p-q
#print(b)
print(max(a,b))

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[]
for i in range(n):
    r.append(int(input()))
#m=sorted(r, reverse=True)
p=max(r[1:])
#print(p)
s=list(reversed(r))
#print(s)
q=min(s[s.index(p)+1:])
a=p-q
q=min(r[:len(r)-1])
#print(q)
p=max(r[r.index(q)+1:])
#print(p)
b=p-q
#print(b)
print(max(a,b))

Submission status: Wrong Answer

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

for i in range(n):
    e1 = int(input())

    if x < e1 - e_min:
        x = e1 - e_min
    e_min = min(e_min,e1)
print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
min_n = 0
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
n = int(input())
mini = 200001
maxd = 0
for i in range(n):
    t = int(input())
    if t < mini:
        mini = t
    if maxd < t - mini:
        maxd = t - mini

print(maxd)

Submission status: Wrong Answer

Solution code:
x = int(input())
l=[]
for i in range(x):
    l.append(int(input()))
print(max(l[l.index(min(l)):])-min(l))

Submission status: Wrong Answer

Solution code:
x = int(input())
l=[]
for i in range(x):
    l.append(int(input()))
print(max(l[l.index(min(l))-1:])-min(l))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 28 21:09:30 2016

@author: you
"""

n = int(input())


maxv = 0
minv = 10000000
price = 0

for i in range(n):
    x = int(input())
    if x < minv:
        minv = x
    if x > maxv:
        maxv = x
    if price < maxv - minv:
        price = maxv - minv

print(price)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 28 21:09:30 2016

@author: you
"""

n = int(input())


maxv = int(input())
minv = maxv
price = 0

for i in range(n-1):
    x = int(input())
    if x < minv:
        minv = x
    if x > maxv:
        maxv = x
    if price < maxv - minv:
        price = maxv - minv

print(price)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 28 21:09:30 2016

@author: you
"""

n = int(input())

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

price = -10000000

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)

Submission status: Wrong Answer

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

print(max(t) - min(t))

Submission status: Wrong Answer

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

candidate = min(List)  
for i in range(N):
    for j in range(i+1, N):
        if List[j]-List[i] > candidate:
            candidate = List[j]-List[i]

print(candidate)

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[int(input())for _ in range(n)]
print(max([max(r[i+1:])-r[i]for i in range(min(r),n-1)]))

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[int(input())for _ in range(n)]
s=r[:];s.remove(min(r))
print(s,r)
print(max([max(r[i+1:])-r[i]for i in range(r.index(min(s)),n-1)]))

Submission status: Wrong Answer

Solution code:
n=int(input())
r=[int(input())for _ in range(n)]
s=r[:];s.remove(min(r))
print(max([max(r[i+1:])-r[i]for i in range(r.index(min(s)),n-1)]))

Submission status: Wrong Answer

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

m = r[0]
for j in range(n):
    n = max(n, r[j]-m)
    m = min(i, r[j])
print(m)

Submission status: Wrong Answer

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

m = r[0]
for j in range(n):
    n = max(n, r[j]-m)
    m = min(i, r[j])
print(m)

Submission status: Wrong Answer

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

m = r[0]
v = 0
for j in range(n):
    v = max(v, r[j]-m)
    m = min(m, r[j])
print(v)

Submission status: Wrong Answer

Solution code:
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 = 1

print(mx)

Submission status: Wrong Answer

Solution code:
import sys

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

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

print(mx)

Submission status: Wrong Answer

Solution code:
R = [int(input()) for _ in range(int(input()))]
ax = -200000
mn = R[0]
for i in R:
    ax = max([ax, i - mn])
    mn = min([mn, i])
print(ax)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
# A=list(map(int,input().split()))
A=[int(input()) for _ in range(N)]
mp=A[1]-A[0]
mn=min(A[0],A[1])
for i in range(N):
    if mp < (A[i]-mn):
        mp=A[i]-mn
    if A[i]<mn:
        mn=A[i]
print(mp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
i=input
n = int(i())
r0 = int(i())
r1 = int(i())
x = r1-r0
y = min(r1,r0)
for i in map(int,i()):
    a=i-y
    if x<a:
        x=a
        if 0>a:y=i
    elif y>i:y=i
print(x)

Submission status: Wrong Answer

Solution code:
N =int(input())
R = []
for i in range(N):
        R.append(int(input()))
maxv=-200000*110
minv=R[0]
for i in range(1,N):
    maxv=max(maxv,R[i]-minv)
    minv=min(minv,R[i])
print(maxv)

Submission status: Wrong Answer

Solution code:
import sys

l = []
for input in sys.stdin:
    l.append(int(input))
i = -1
for data in range(1,len(l)):
    if(data < len(l)-1 and l[data+1] > l[data]):
        if(l[data+1] - l[data] > i):
            i = data
print i

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
	n = int(input())
	max_num = 0
	min_num = 0
	for i in range(n):
		R = int(input())

		if not(min_num):
			min_num = R
			max_num = R
			continue

		if max_num < R:
			max_num = R

		elif min_num > R:
			min_num = R
	print(max_num - min_num)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
	n = int(input())
	M = None
	R = int(input())
	S = 0
	tr = R

	for i in range(n - 1):
		a = int(input())
		if tr - a >= 0:
			continue
		else:
			M = tr - a if M is None or M < tr - a else M
			tr = a
	print(M)

Submission status: Wrong Answer

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

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

	for i in range(n - 1):
		for j in range(i + 1, n):
			m = lists[j] - lists[i] if m is None or m > lists[j] - lists[i] else m
	print(m)

Submission status: Wrong Answer

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

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

	for i in range(n - 1):
		j = max(lists[i:n])
		m = j - lists[i] if m is None or m < j - lists[i] else m
	print(m)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
	n = int(input())

	M = int(input())
	m = M
	M_c = 0
	m_c = 0
	m_2 = 0
	count = 0

	for i in range(n - 1):
		count += 1
		a = int(input())
		if M <= a:
			M = a
			M_c = count
		elif m >= a:
			m, m_2 = a, m
			m_c = count if m > a else m_c

	if m_c < M_c:
		print(M - m)
	else:
		print(m_2 - m)

Submission status: Wrong Answer

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

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

	m = None
	S = 0

	for i in range(1, n - 1):
		tr = lists[i + 1] - lists[i]
		if tr >= 0 and i < n - 2:
			S += tr
			continue
		else:
			if m is None or m < S:
				m = S

			tr = lists[i]
	print(m)

Submission status: Wrong Answer

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

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

	S = None
	while lists:
		mini = min(lists)
		mini_ind = lists.index(mini)
		maxi = max(lists[mini_ind : len(lists)])

		T = maxi - mini
		if S is None or S < T:
			S = T
			lists = lists[0 : mini_ind]
			continue
		else:
			break

	print(S)

Submission status: Wrong Answer

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

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

	S = None
	while lists:
		mini = min(lists)
		mini_ind = lists.index(mini)
		maxi = max(lists[mini_ind : len(lists)])

		T = maxi - mini
		if S is None or S < T:
			S = T
		lists = lists[0 : mini_ind]
		continue

	print(S)