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:
numberOfInput=int(input())
numberForStock=[]
stockForStock=[]
stockForMin=[]
timeCount=0
max=0
min=10**9
while timeCount<numberOfInput:
    inputNumber=int(input())
    if timeCount==0:
        min=inputNumber
    elif timeCount==1:
        max=inputNumber
    else:
        beforeMax=max
        max=inputNumber
        if not max-min>beforeMax-min:
            max=beforeMax
            stockForStock.append(inputNumber)
        else:
            stockForMin.append(beforeMax)
            stockForMin.extend(stockForStock)
            stockForStock=[]

        if timeCount%5==0 or timeCount==numberOfInput-1:
            beforeMin=min
            stockForMin.sort(reverse=False)
            if not stockForMin==[]:
                min=stockForMin[0]
                if not max-min>max-beforeMin:
                    min=beforeMin
                stockForMin.clear()

    timeCount+=1

print(max-min)

Submission status: Wrong Answer

Solution code:
numberOfInput=int(input())
numberForStock=[]
stockForStock=[]
stockForMin=[]
timeCount=0
max=0
min=10**9
while timeCount<numberOfInput:
    inputNumber=int(input())
    if timeCount==0:
        min=inputNumber
    elif timeCount==1:
        max=inputNumber
    else:
        beforeMax=max
        max=inputNumber

        if max-min>=beforeMax-min:
            stockForMin.append(beforeMax)
            stockForMin.extend(stockForStock)
            stockForStock.clear()
        else :
            max=beforeMax
            stockForStock.append(inputNumber)
  
        if  timeCount%5==0 or timeCount==numberOfInput-1:
            beforeMin=min
            stockForMin.sort(reverse=False)
            if not stockForMin==[]:
                min=stockForMin[0]
                if not max-min>max-beforeMin:
                    min=beforeMin
                    stockForMin.clear()

                
    timeCount+=1
print(max-min)

Submission status: Wrong Answer

Solution code:
numberOfInput=int(input())
numberForStock=[]
stockForStock=[]
stockForMin=[]
timeCount=0
max=0
min=10**9
while timeCount<numberOfInput:
    inputNumber=int(input())
    if timeCount==0:
        min=inputNumber
    elif timeCount==1:
        max=inputNumber
    else:
        beforeMax=max
        max=inputNumber

        if max-min>=beforeMax-min:
            stockForMin.append(beforeMax)
            stockForMin.extend(stockForStock)
            stockForStock.clear()
        else :
            max=beforeMax
            stockForStock.append(inputNumber)
  
        if  timeCount%5==0 or timeCount==numberOfInput-1:
            beforeMin=min
            stockForMin.sort(reverse=False)
            if not stockForMin==[]:
                min=stockForMin[0]
                if max-min<max-beforeMin:
                    min=beforeMin
                    stockForMin.clear()

                
    timeCount+=1
print(max-min)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = [int(input()) for x in range(n)]

cur_max = min(r) - 1
cur_max_idx = -1

max_diff = min(r) - max(r)

for i in range(n) :
    if i == cur_max_idx :
        continue
        
    if i == 0 :
        for j in range(1, n) :
            if r[j] > cur_max :
                cur_max = r[j]
                cur_max_idx = j
                
        max_diff =  max(max_diff, r[cur_max_idx] - r[i])
    elif i < cur_max_idx :
        max_diff = max(max_diff, r[cur_max_idx] - r[i])
    else :
        cur_max_idx = i + 1
        
print(max_diff)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = [int(input()) for x in range(n)]

cur_max = min(r) - 1
cur_max_idx = -1

max_diff = min(r) - max(r)

for i in range(n) :
    if i == cur_max_idx :
        continue
        
    if i == 0 :
        for j in range(1, n) :
            if r[j] >= cur_max :
                cur_max = r[j]
                cur_max_idx = j
                
        max_diff =  max(max_diff, r[cur_max_idx] - r[i])
        # print("DBG2 : ", cur_max_idx, cur_max)
        
    elif i < cur_max_idx :
        # print("DBG : @ ", i, r[cur_max_idx])
        max_diff = max(max_diff, r[cur_max_idx] - r[i])
    else :
        cur_max_idx = i + 1
        
print(max_diff)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    numlist = []
    for _ in range(n):
        numlist.append(int(input()))

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# とても時間がかかる

def main():
    n = int(input())
    numlist = []
    for _ in range(n):
        numlist.append(int(input()))

    maxprofit = numlist[1] - numlist[0]
    for i in range(n-1):
        maxprofit = max(numlist[i+1:n]) - min(numlist[0:i+1])
    print(maxprofit)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# とても時間がかかる

def main():
    n = int(input())
    numlist = []
    for _ in range(n):
        numlist.append(int(input()))

    maxprofit = numlist[1] - numlist[0]
    for i in range(n-1):
        maxprofit = max(numlist[i:n]) - min(numlist[0:i+1])
    print(maxprofit)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    t0 = int(input())
    t1 = int(input())
    tmpmin = t0
    tmpmax = t1 - t0

    for _ in range(n-2):
        t = int(input())
        if tmpmax < t - tmpmin:
            tmpmax = t - tmpmin 
        if t < tmpmin:
            tmpmax = t

    print(tmpmax)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# とても時間がかかる

def main():
    n = int(input())
    t0 = int(input())
    t1 = int(input())
    tmpmin = t0
    tmpmax = t1 - t0

    for _ in range(2,n):
        t = int(input())
        if t - tmpmin > tmpmax:
            tmpmax = t - tmpmin 
        if t < tmpmin:
            tmpmin = t

    print(tmpmax)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
R=[0 for i in range(n)]
max=0
for i in range(n):
    R[i]=int(input())
for i in range(n-1):
    for j in range(i,n):
        x=R[j]-R[i]
        if max<x:
            max=x
print(max)

Submission status: Wrong Answer

Solution code:
n=int(input())
R=[0 for i in range(n)]
max=-100
for i in range(n):
    R[i]=int(input())
for i in range(n-1):
    for j in range(i,n):
        x=R[j]-R[i]
        if max<x:
            max=x
print(max)

Submission status: Wrong Answer

Solution code:
n=int(input())
R=[0 for i in range(n)]
max=-100
for i in range(n):
    R[i]=int(input())
for i in range(n-1):
    for j in range(i+1,n):
        x=R[j]-R[i]
        if max<x:
            max=x
print(max)

Submission status: Wrong Answer

Solution code:
n=int(input())
R=[0 for i in range(n)]
max=-1000000
for i in range(n):
    R[i]=int(input())
for i in range(n-1):
    for j in range(i+1,n):
        x=R[j]-R[i]
        if max<x:
            max=x
print(max)

Submission status: Wrong Answer

Solution code:
inputs = []
while True:
    try:
        inputs.append(int(input()))
    except(EOFError):
        break

inputs.pop(0)

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

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

print(maxv)

Submission status: Wrong Answer

Solution code:
inputs = []
while True:
    try:
        inputs.append(int(input()))
    except(EOFError):
        break

inputs.pop(0)

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

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

print(maxv)

Submission status: Wrong Answer

Solution code:
inputs = []
while True:
    try:
        inputs.append(int(input()))
    except(EOFError):
        break

inputs.pop(0)

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

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

print(maxv)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [int(input()) for _ in range(N)]
maxv = -200000000
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:
n=int(input())
R=[int(input()) for i in range(n)]
mini=10**9
maxi=0
for r in R:
    if r<mini:
        mini=r
    if r-mini>maxi:
        maxi=r-mini
print(maxi)

Submission status: Wrong Answer

Solution code:
n=int(input())
R=[int(input()) for i in range(n)]
mini=10**9
maxi=-10**9
for r in R:
    maxi=max([maxi,r-mini])
    mini=min([mini,r])
print(maxi)

Submission status: Wrong Answer

Solution code:
n=int(input())
R=[int(input()) for i in range(n)]
mini=10**9+1
maxi=-10**9-1
for r in R:
    maxi=max([maxi,r-mini])
    mini=min([mini,r])
print(maxi)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

profit = price_list[1] - price_list[0]
purchase_price = price_list[0]

for price in price_list[2:]:
    if profit < price - purchase_price:
        profit = price - purchase_price
    if price < purchase_price:
        purchase_price = price

print(profit)

Submission status: Wrong Answer

Solution code:
N = int(input())

purchase_price = int(input())
profit = int(input()) - purchase_price
for _ in range(N-2):
    price = int(input())
    profit = max(profit, (price-purchase_price))
    purchase_price = min(price, purchase_price)

print(profit)

Submission status: Wrong Answer

Solution code:
N = int(input())

purchase_price = int(input())
profit = -200000
for _ in range(N-1):
    price = int(input())
    profit = max(profit, (price-purchase_price))
    purchase_price = min(price, purchase_price)

print(profit)

Submission status: Wrong Answer

Solution code:
n=int(raw_input().strip())
lst=[]
minval=0x3f3f3f3f
ans=-0x3f3f3f3f
for i in xrange(n):
    val=int(raw_input().strip())
    if(i>1):
        #print val,minval
        ans=max(ans,val-minval)
    minval = min(minval, val)
print ans

Submission status: Wrong Answer

Solution code:
n = int(input())
lo = 10 ** 9
diff = -10 ** 9
for _ in range(n):
    r = int(input())
    diff = max(diff, r - lo)
    lo = min(lo, r)
print(diff)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = [int(input()) for i in range(n)]
minv = L[0]
maxv = 0
for i in range(n):
    maxv = max(maxv, L[i]-minv)
    minv = min(minv, L[i])
if maxv > 0:
    print(maxv)
else:
    print(-minv)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = [int(input()) for i in range(n)]
minv = L[0]
maxv = 0
for i in range(n):
    maxv = max(maxv, L[i]-minv)
    minv = min(minv, L[i])
if maxv >= 0:
    print(maxv)
else:
    print(-minv)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
maxv=a[1]-a[0]
minv=a[0]
for j in range(n):
    maxv=max(maxv,a[j]-minv)
    minv=min(minv,a[j])
print(maxv)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = [int(input()) for _ in range(n)]

min_val = min(ls)
min_index = ls.index(min_val)

if min_index == len(ls)-1:
    print(min_val - min(ls[:min_index]))

elif max(ls[min_index+1:]) >= min_val:
    print(max(ls[min_index:]) - min_val)

else:
    print(min_val - min(ls[:min_index]))

Submission status: Wrong Answer

Solution code:
N=int(input())
R=[int(input()) for i in range(N)]
S=[0 for i in range(N)]
S[0]=R[0]
for i in range(1,N):
    S[i]=min(S[i-1],R[i])
print(max([R[i]-S[i] for i in range(N)]))

Submission status: Wrong Answer

Solution code:
x = int(input())

b = int(input())
min = b
max = b
for i in range(0, x-1):
    a = int (input())
    if min > a:
       max = min
       min = a
    if max < a:
       max = a


print(max-min)

Submission status: Wrong Answer

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

    min_ = 10 ** 9
    diff_max = - min_
    for i in range(n):
        x = int(input())
        tmp_diff = x - min_
        if x < min_:
            min_ = x
        if diff_max < tmp_diff:
            diff_max = tmp_diff
    print(diff_max)
    return


main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(int(input()))
max_s = -10**9
for i in range(n-1):
    for j in range(n):
        if j+i+1 == n-1:
            break
        R = s[j+i+1] - s[i]
        if max_s < R:
            max_s = R

print(max_s)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(int(input()))
max_s = -10**9
min_s = s[0]
for i in range(1, n-1):
    max_s = max(max_s, s[i] - min_s)
    min_s = min(min_s, s[i])

print(max_s)

Submission status: Wrong Answer

Solution code:
n = int(input())
max_profit = -1000000000
min_value = 1000000000
for i in range(n):
    num = int(input())
    max_profit = max(max_profit, num-min_value)
    min_value = min(i, min_value)
print(max_profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
ns = []
max_profit = -1000000000
min_value = 1000000000
for i in range(n):
    num = int(input())
    max_profit = max(max_profit, num-min_value)
    min_value = min(i, min_value)
print(max_profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
ns = []
max_profit = -1000000000
min_value = 1000000000
for i in range(n):
    num = int(input())
    max_profit = max(max_profit, num-min_value)
    min_value = min(num, min_value)
print(max_profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = [int(input()) for _ in range(n)]

small = 200000
big = 0
for i in range(len(ls)-1):
    if ls[i] < small:
        small = ls[i]
        big = ls[i+1]
    if ls[i+1] > big:
        big = ls[i+1]
    print(f'big: {big}, small:{small}')

print(big-small)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = [int(input()) for _ in range(n)]

small = 200000
big = 0
for i in range(len(ls)-1):
    if ls[i] < small:
        small = ls[i]
        big = ls[i+1]
    if ls[i+1] > big:
        big = ls[i+1]

print(big-small)

Submission status: Wrong Answer

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

r_i = min(r_t)
r_i_index = r_t.index(r_i)

if r_i_index + 1 >= n:
    r_i = min(r_t[:-1])
    r_i_index = r_t.index(r_i)

r_j = max(r_t[r_i_index+1:])

print(r_j - r_i)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
R = [int(input().strip()) for _ in range(N)]

maxv = -math.inf
minv = R[0]
for i in range(1, N-1):

    tmp_maxv = R[i] - minv # 差額をセットする
    # 現在の最大差額と差額の大きい方を最大差額にする
    if maxv < tmp_maxv:
        maxv = tmp_maxv

    # 現在値が最小なら、最小値を更新する
    if R[i] < minv:
        minv = R[i]

print(maxv)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

min_v = int(input())
max_v = int(input()) - min_v

for _n in range(2, N):
    r = int(input())
    if max_v < r - min_v:
        max_v = r - min_v
    if min_v > r:
        min_v = r
print(max_v)

Submission status: Wrong Answer

Solution code:
s = int(input())
maxv = 0
minv = 10000000000000000

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

print(maxv)

Submission status: Wrong Answer

Solution code:
s = int(input())
maxv = 0
minv = 10000000000000000

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

if maxv != 0:
    print(maxv)
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
n = int(input())

minr = float('inf')
maxd = -float('inf')
for _ in range(n):
    r = int(input())
    minr = min(minr, r)
    maxd = max(maxd, r - minr)

print(maxd)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-
a = list(map(int, input().split()))

num = len(a) - 1
minv = a[0]
maxv = -2000000000

for i in range(num):
    if minv > a[i]:
        minv = a[i]
    if a[i] - minv > maxv:
        maxv = a[i] - minv

print(maxv)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-
a = list(map(int, input().split()))

num = len(a) - 1
minv = a[0]
maxv = -2000000000

for i in range(num):
    if a[i] - minv > maxv:
        maxv = a[i] - minv
    if minv > a[i]:
        minv = a[i]

print(maxv)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-
a = list(map(int, input().split()))

num = len(a) - 1
minv = a[0]
maxv1 = -2000000000
maxv2 = maxv1

for i in range(num):
    maxv1 = max(maxv1, a[i] - minv)
    if not(maxv1 == maxv2):
        minv = min(minv, a[i])
        amxv1 = maxv2

print(maxv1)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-
import sys
a = []
for l in range(len(sys.stdin.readlines())):
    a.append(int(l))

num = len(a)
minv = a[0]
maxv1 = -2000000000
maxv2 = maxv1

for i in range(num):
    maxv1 = max(maxv1, a[i] - minv)
    if not(maxv1 == maxv2):
        minv = min(minv, a[i])
        amxv1 = maxv2

print(maxv1)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-
import sys
lines = sys.stdin.readlines()
a = [int(i) for i in lines]

num = len(a)
minv = a[0]
maxv = -2000000000

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

print(maxv)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-
import sys
lines = sys.stdin.readlines()
a = [int(i) for i in lines]

num = len(a)
minv = a[0]
maxv = -2000000000

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

print(maxv)

Submission status: Wrong Answer

Solution code:
print(input())

Submission status: Wrong Answer

Solution code:
n=int(input())
minv=int(input())
maxv=-float('inf')
for _ in range(n-1):
  tmp=int(input())
  minv=min(minv,tmp)
  maxv=max(maxv,tmp-minv)
print(maxv)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = -100000000
for i in range(len(rl)-1):
  rmax = max(rl[:i+2])
  rmin = min(rl[:i+1])
  ans = max(ans, rmax-rmin)
print(ans)

Submission status: Wrong Answer

Solution code:
 
def calcMax(i): 
  now = numbers[i]  
 
  future_max = max(numbers[i+1:]) 
  #print(numbers[i+1:]) 
  t = numbers[i+1:] 
  #print((max(t))) 
  return future_max - now 
 
n = int(input()) 
 
numbers = [] 
for i in range(n): 
  numbers.append(int(input())) 
 
m = -200010 
for i in range(len(numbers) - 1): 
    temp = calcMax(i) 
    #print("temp: " + str(temp)) 
    if temp > m: 
        m = temp 
 
print (m)

Submission status: Wrong Answer

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

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

n = int(input())

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

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

print (m)

Submission status: Wrong Answer

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

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

n = int(input())

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

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

print (m)

Submission status: Wrong Answer

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

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

n = int(input())

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

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

print (m)

Submission status: Wrong Answer

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

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

n = int(input())

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

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

print (m)

Submission status: Wrong Answer

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

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

n = int(input())

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

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

print (m)

Submission status: Wrong Answer

Solution code:
N = int(input())
maxv = -2000000
minv = int(input())
for i in range(N-1):
    _ = int(input())
    maxv = max(maxv,_-minv)
    minv = min(minv,_)
print(maxv)

Submission status: Wrong Answer

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

dp = [-(10**8)]*N
dp[0] = A[1]-A[0]
for i in range(1,N-1):
    dp[i] = max(A[i+1]-A[i]+dp[i-1], A[i+1]-A[i])

print(max(dp))

Submission status: Wrong Answer

Solution code:
n = int(input())

t = []

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

buy = t[0]
sell = min(t[1:])
val = sell - buy

for i in range(n-1):
    if t[i] >= buy:
        continue
    m = max(t[i+1:])
    if m - t[i] > val:
        buy = t[i]
        sell = m

print(sell - buy)

Submission status: Wrong Answer

Solution code:
n = int(input())

t = []

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

buy = t[0]
sell = max(t[1:])
val = sell - buy

for i in range(n-1):
    if t[i] >= buy:
        continue
    m = max(t[i+1:])
    if m - t[i] > val:
        buy = t[i]
        sell = m

print(sell - buy)

Submission status: Wrong Answer

Solution code:
n = int(input())

t = []

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

buy = t[0]
sell = max(t[1:])
val = sell - buy

for i in range(n-1):
    if i == 0 or t[i] >= t[i - 1]:
        continue
    m = max(t[i+1:])
    val2 = m - t[i]
    if val2 > val:
        buy = t[i]
        sell = m
        val = val2

print(val2)

Submission status: Wrong Answer

Solution code:
n = int(input())

t = []

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

buy = t[0]
sell = max(t[1:])
val = sell - buy

for i in range(n-1):
    m = max(t[i+1:])
    val2 = m - t[i]
    if val2 > val:
        buy = t[i]
        sell = m
        val = val2

print(val2)

Submission status: Wrong Answer

Solution code:
n = int(input())

t = []

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

buy = t[0]
prev_sell = max(t[1:])
val = prev_sell - buy

for i in range(n-1):
    if i == 0 or t[i - 1] < t[i]:
        continue
    if t[i] >= prev_sell:
        prev_sell = max(t[i+1:])
    val2 = prev_sell - t[i]
    if val2 > val:
        val = val2

print(val)

Submission status: Wrong Answer

Solution code:
n = int(input())

t = []

for i in range(1, n):
    t.append(int(input()))

buy = t[0]
val = t[1] - buy
5

for i in range(n-1):
    if t[i] - buy > val:
        val = t[i] - buy
    if t[i] < buy:
        buy = t[i]

print(val)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = []
for i in range(n):
    r.append(int(input()))
diff = max(r) - min(r)
print(diff)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())

min,dif = 200000, -200000

for i in range(N):
    a = int(input())
    if (a - min) > dif:
        dif = a - min
    if a < min:
        min = a
print(dif)

Submission status: Wrong Answer

Solution code:
#ALDS1_1_D

N = int(input())

min,dif = 1000000000, -1000000000

for i in range(N):
    a = int(input())
    if (a - min) > dif:
        dif = a - min
    if a < min:
        min = a
print(dif)

Submission status: Wrong Answer

Solution code:
n = input();
r = [0] * n
i = 0
while i < n:
	r[i] = input();
	i += 1
r = sorted(r)
print r[-1] - r[0]

Submission status: Wrong Answer

Solution code:
n = int(input())
i, j = int(input()), 0
m = 0
a = 0
for i in range(n - 1):
    j = int(input())
    if j - i < 0:
        i = j
        j = 0
    elif j - i > a:
        a = j - i

print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
i, j = int(input()), 0
nmin = i
a = 0
for h in range(n - 1):
    j = int(input())
    if j < nmin:
        nmin = j
        continue

    if j - nmin > a:
        a = j - nmin

print(a)

Submission status: Wrong Answer

Solution code:
def main():
    n = input()
    d = 0
    m = 200000

    for i in range(n):
        r = input()
        if (m > r):
            m = r
            continue
        if (d < r - m):
            d = r - m
    print(d)

main()

Submission status: Wrong Answer

Solution code:
N = input()
R = [input() for i in range(N)]
MAX = 0
for i in range(0,N):
	for j in range(i,N):
		MAX = max(MAX,R[j]-R[i])
print MAX

Submission status: Wrong Answer

Solution code:
N = input()
MIN = -1
r = input()
for i in range(N-1):
	R = input()
	MIN = max(MIN,(R-r))
	r = min(r,R)
print MIN

Submission status: Wrong Answer

Solution code:
N = input()
MIN = -99999999
r = input()
for i in range(N-1):
	R = input()
	MIN = max(MIN,(R-r))
	r = min(r,R)
print MIN

Submission status: Wrong Answer

Solution code:
N = input()
d = -99999999
R = input()
for i in range(N-1):
	r = input()
	d = max(d,(r-R))
	R = min(R,r)
print d

Submission status: Wrong Answer

Solution code:
p = 0
n = int(input())
a = int(input())
for _ in range(n-1):
	b = int(input())
	if p<abs(a-b):
		p = a-b
	a = b
print(p)

Submission status: Wrong Answer

Solution code:
p = 0
n = int(input())
a = int(input())
for _ in range(n-1):
	b = int(input())
	if p<abs(a-b):
		p = abs(a-b)
	a = b
print(p)

Submission status: Wrong Answer

Solution code:
p = 0
n = int(input())
l = int(input())
for _ in range(n-1):
	t = int(input())
	if t<l:
		l = t
	else:
		h=t
		if p<h-l:
			p=h-l
print(p)

Submission status: Wrong Answer

Solution code:
p = 0
h = 0
n = int(input())
l = int(input())
for _ in range(n-1):
	t = int(input())
	if t<l:
		l = t
	else:
		h=t
		if p<h-l:
			p=h-l
if h==0:
	print("-1")
else:
	print(p)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = int(input())
h = int(input())
p = h-l
for _ in range(n-2):
	t = int(input())
	if t<l:
		l=t
	else:
		h=t
		if p<h-l:
			p=h-l
else:
	print(p)

Submission status: Wrong Answer

Solution code:
l = 1*10**9
p = -1*10**9
n = int(input())
for _ in range(n):
	x = int(input())
	p = max(x-l,p)
	l = min(x,l)
print(p)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

rt = [int(raw_input()) for x in xrange(n)]

i_max = rt.index(max(rt))
i_min = rt.index(min(rt))

a = rt[i_max] - min(rt[:i_max]) if len(rt[:i_max]) else 0
b = max(rt[i_min:]) - rt[i_min] if len(rt[i_min:]) else 0

print a if a > b else b

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

_min, dif = 10000000, 0
for x in xrange(n):
    a = int(raw_input())
    if a -_min > dif:
        dif = a - _min
    if a < _min:
        _min = a
print dif

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

_min, dif = 10000000, -1000000
for x in xrange(n):
    a = int(raw_input())
    if a -_min > dif:
        dif = a - _min
    if a < _min:
        _min = a
print dif

Submission status: Wrong Answer

Solution code:
n = int(raw_input())

_min, dif = 10**9, -10**9
for x in xrange(n):
    a = int(raw_input())
    if a -_min > dif:
        dif = a - _min
    if a < _min:
        _min = a
print dif

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
R = []
for i in range(0, N):
	R.append(int(raw_input()))
R.reverse()
max_num = 0

for i in R[:N - 1]:
	for j in R[1:]:		
		if max_num <(i - j):
			max_num = i - j

print max_num

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
R = []
for i in range(0, N):
	R.append(int(raw_input()))
R.reverse()
max_num = 0

for x, i in enumerate(R[:N - 1]):
	for j in R[x + 1:]:		
		if max_num <(i - j):
			max_num = i - j

print max_num

Submission status: Wrong Answer

Solution code:
N = int(input())
R = int(input())

pre_max = pre_min = now_max = now_min = R

for _ in range(N - 1):
    R = int(input())
    if R < now_min:
        if  pre_max - pre_min < now_max - now_min:
            pre_max, pre_min = now_max, now_min
        now_max = now_min = R
    elif R > now_max:
        now_max = R
        if R > pre_max:
            pre_max = R

print(max(pre_max - pre_min, now_max - now_min))

Submission status: Wrong Answer

Solution code:
R = []
while True:
	try:
		R.append(input())
	except EOFError:
		break
maxSeq = R[-1]
maxv = -float("inf")
for i in range(len(R)-2, -1, -1):
	if (maxSeq - R[i]) > maxv:
		maxv = maxSeq - R[i]
	if R[i] > maxSeq:
		maxSeq = R[i]
print(maxv)

Submission status: Wrong Answer

Solution code:
R = []
while True:
	try:
		R.append(input())
	except EOFError:
		break
minSeq = R[0]
maxv = -float("inf")
for v in R[1:]:
	if v - minSeq > maxv:
		maxv = v - minSeq
	if v < minSeq:
		minSeq = v
print(maxv)

Submission status: Wrong Answer

Solution code:
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break    
    
    ls = []
    for i in range(n):
        ls.append(int(raw_input()))
    
    maxvalue = -9999999999999999999999
    for k in range(len(ls)):
        for j in range(1,k):
            if ls[k]-ls[k-j] > maxvalue:
                maxvalue = ls[k]-ls[k-j]
    print maxvalue

Submission status: Wrong Answer

Solution code:
n = int(input())
R = [int(input()) for _ in range(n)]
bottom = R[0]
ans = R[1] - bottom
for i in range(2, n):
    ans = max(ans, R[i] - bottom)
    if R[i] < bottom:
        bottom = R[i]
print(ans)