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: Accepted

Solution code:
n = int(input())

mx = [-1]*n
mn = [float('inf')]*n
val = [0]*n
for i in range(n):
    v = int(input())
    mx[i] = mn[i] = v

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

ans = -float('inf')
for i in range(n-1):
    ans = max(ans,mx[i+1]-mn[i])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
index=0
minL=[]
moneyL=[]
while index < n:
    inputN = int(input())
    moneyL.append(inputN)
    if index==0:
        minL.append(inputN)
    else:
        if minL[index-1] < inputN:
            minL.append(minL[index-1])
        else:
            minL.append(inputN)
    index+=1

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

print(maxProfit)

Submission status: Accepted

Solution code:
n=int(input())
min=10**10
max=-10**10
profit=max-min
for i in range(0,n):
    x=int(input())
    if(max < x and i!=0):
        max=x
        if(profit < max-min):
            profit=max-min
    if( x < min):
        min=x
        max=-10**10
print(profit)

Submission status: Accepted

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

def fx(raw):
    min_n = raw[0]
    max_n = raw[1] - raw[0]
    for i in raw[1:]:
        if i - min_n >= max_n:
            max_n = i - min_n
        if i < min_n:
            min_n = i
    return max_n


if __name__ == '__main__':
    print(fx(m))

Submission status: Accepted

Solution code:
R = []

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

maxv = 10**9 * (-1)
minv = R[0]


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

print(maxv)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=-1e11,1e11
for _ in range(int(input())):
    c=int(input())
    a,b=max(a,c-b),min(b,c)
print(a)

Submission status: Accepted

Solution code:
R = [int(input()) for _ in [0]*int(input())]
minv = R[0]
maxv = -1e+10
for j in range(1, len(R)):
    maxv = max(maxv, R[j]-minv)
    minv = min(minv, R[j])
print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
count = 0
list_prob = []
while count < n:
    list_prob.append(int(input()))
    count += 1
maxv = list_prob[1] - list_prob[0]
minv = list_prob[0]
for j in range(1,n):
    maxv = max(maxv, list_prob[j] - minv)
    minv = min(minv, list_prob[j])
print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
rmin = int(input())
r=int(input())
dmax = r-rmin
if rmin>r: rmin=r
for _ in range(n-2):
    r = int(input())
    if dmax<r-rmin: dmax=r-rmin
    if rmin>r: rmin=r

print(dmax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
minr=10**10
maxr=-10**10
for i in range(n):
    r = int(input())
    maxr = max(maxr,r-minr)
    minr = min(minr, r)
    # print("max:{},min:{}".format(maxr,minr))
print(maxr)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
r = [int(input()) for _ in range(n)]

maxv = -2 * (10 ** 9)
minv = r[0]

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

print(maxv)

Submission status: Accepted

Solution code:
import math
n = int(input())
_min = _max = -1000000000
_min = int(input())
for i in range(1,n):
    tmp = int(input())
    _max = max(_max, tmp - _min)
    _min = min(_min, tmp)
print(_max)

Submission status: Accepted

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

    ans = R[1] - R[0]
    
    current_min = min(R[0], R[1])

    for i in range(2, N):
        ans = max(ans, R[i] - current_min)
        current_min = min(current_min, R[i])

    print(ans)

main()

Submission status: Accepted

Solution code:
N = int(input())
R = []
for _ in range(N):
    R.append(int(input()))
M = - 10 ** 100
m = R[0]
for i in range(1, N):
    M = max(M, R[i] - m)
    m = min(m, R[i])
print(M)

Submission status: Accepted

Solution code:
from sys import stdin

inf = 10**9 + 1

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

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

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

    print(max_d)


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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#46
n=int(input())
l=[int(input()) for _ in range(n)]
ans=l[1]-l[0]
bottom=min(l[0],l[1])

for i in l[2:]:
    ans=max(ans,i-bottom)
    bottom=min(i,bottom)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

price = []

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

max = price[1] - price[0]
min = price[0]

for i in range(1, n):
    if max < price[i] - min:
        max = price[i] - min

    if min > price[i]:
        min = price[i]


print(max)

Submission status: Accepted

Solution code:
n = int(input())
r = []
for i in range(n):
    r.append(int(input()))
min = r[0]
max_prof = -2000000000000
for i in range(1, n):
    if (r[i] - min) > max_prof:
        max_prof = r[i] - min
    if r[i] < min:
        min = r[i]
print(max_prof)

Submission status: Accepted

Solution code:
def main():
    profit, loss = -1e+10, -1e+10
    price, high, low, before = 0, 0, 1e+10, 1e+10
    win = False
    for _ in range(int(input())):
        price = int(input())
        if low > price:
            profit = max(profit, high - low)
            loss = max(loss, price - before)
            high, low, before = price, price, price
        else:
            high = max(high, price)
            before = price
            win = True
    print(max(profit, high - low) if win else loss)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
val = -float("inf")
minR = int(input())

for j in range(1,n):
    R = int(input())
    if R - minR > val:
        val = R - minR
    if R < minR:
        minR = R
        
print(val)

Submission status: Accepted

Solution code:
n=int(input())

max=-10000000000
n1=int(input())
min=n1
for i in range(n-1):
    a=int(input())
    if max<a-min:
        max=a-min
    if a<min:
        min=a
print(max)

Submission status: Accepted

Solution code:
n = 0
dat = []


def input_file():
    global n, dat
    f = open('input', mode='r')
    n = int(f.readline())
    for _ in range(n):
        i = int(f.readline())
        dat.append(i)


def input_cmd():
    global n, dat
    n = int(input())
    for _ in range(n):
        dat.append(int(input()))


input_cmd()
# input_file()

# p = -2e10
# for i in range(n):
#     for j in range(i + 1, n):
#         r = dat[j] - dat[i]
#         if r > p:
#             p = r
minV = dat[0]
maxV = -2e10
for i in range(1, n):
    r = dat[i] - minV
    maxV = r if r > maxV else maxV
    # 从已经遍历过的数据中得到现阶段的最小的价格即可
    minV = dat[i] if dat[i] < minV else minV
print(maxV)

Submission status: Accepted

Solution code:
n = 0
dat = []


def input_file():
    global n, dat
    f = open('input', mode='r')
    n = int(f.readline())
    # min = 2e10
    # max = -1
    # print(min)
    for _ in range(n):
        i = int(f.readline())
        dat.append(i)

    # print(max - min)


def input_cmd():
    global n, dat
    n = int(input())
    for _ in range(n):
        dat.append(int(input()))


input_cmd()
# input_file()

# p = -2e10
# for i in range(n):
#     for j in range(i + 1, n):
#         r = dat[j] - dat[i]
#         if r > p:
#             p = r
minV = dat[0]
maxV = -2e10
for i in range(1, n):
    r = dat[i] - minV
    maxV = r if r > maxV else maxV
    minV = dat[i] if dat[i] < minV else minV
print(maxV)

Submission status: Accepted

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

for _ in range(cnt):
    concurrency_list.append(int(input()))

minv = concurrency_list[0]
maxv = -100000000000
# 1 から (n-1)
for j in range(1, len(concurrency_list)):
    maxv = max(maxv, concurrency_list[j] - minv)
    
    # jをインクリメントしていくなかで最小値を探していく。
    minv = min(minv, concurrency_list[j])
    
    
print(maxv)

Submission status: Accepted

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

maxt = t - mint
if t < mint: mint = t

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

print(maxt)

Submission status: Accepted

Solution code:
import sys
input_lines = [int(i) for i in sys.stdin.readlines()]
n = input_lines[0]
ans = input_lines[2] - input_lines[1]
if n > 2:
    min_num = min(input_lines[1], input_lines[2])
    for i in input_lines[3:]:
        ans = max(ans, i-min_num)
        min_num = min(i, min_num)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

minv = int(input())
maxv = -10 ** 12

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

print(maxv)

Submission status: Accepted

Solution code:
N = int(input())
 
#R[0]
minv = int(input())
maxv = -10**12
 
#R[1..N-1]
for j in range(1, N):
    r = int(input())
    maxv = max(maxv, r - minv)
    minv = min(minv, r)
     
print(maxv)

Submission status: Accepted

Solution code:
n = int(input())
prices = [int(input()) for _ in range(n)]
max_profit = prices[1] - prices[0]
min_price = prices[0]
for price in prices[1:]:
    max_profit = max(max_profit, price - min_price)
    min_price = min(min_price, price)

print(max_profit)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
n = int(input())
minv, maxv = 0, 0
for i in range(n):
    x = int(input())
    if i == 0: minv = x
    elif i == 1: maxv = x - minv 
    if maxv < x - minv: maxv = x - minv
    if minv > x: minv = x
print(maxv)

Submission status: Accepted

Solution code:
import math

n=int(input())
t=int(input())

mnt=t
t1=int(input())
if t1<t:
    mnt=t1
mxt=t1-t


for i in range(2,n):
    t=int(input())

    if t-mnt>mxt:
        mxt=t-mnt
    if t<mnt:
        mnt=t

print(int(mxt))

Submission status: Accepted

Solution code:
n = int(input())
min_ = float("INF")
max_ = float("-INF")
for i in range(n):
  r = int(input())
  max_ = max(max_, r-min_)
  min_ = min(min_, r)
print(max_)

Submission status: Accepted

Solution code:
# Maximum profit
maxv = -10**10
minimum = -10**10
for _ in range(int(input())):
    rt = int(input())
    if minimum == -10**10:
        minimum = rt
        continue
    if rt-minimum > maxv:
        maxv = rt-minimum
    if rt < minimum: minimum = rt
print(maxv)

Submission status: Accepted

Solution code:
n=int(input())
arr=[]
for i in range(n):
    arr.append(int(input()))
maxp=[]
max_=0
min_=20000000000
rooped=0
for j in arr:
    if max_<j:
        max_=j
        
        maxp.append(max_-min_)
    if min_>j:
        min_=j
        max_=0
maxp.sort()
maxp.reverse()
    
print(maxp[0])

Submission status: Runtime Error

Solution code:
n=int(input())

def read_n_lows_input(n):
    Alist=[int(input()) for i in range(n)]
    return Alist

A = read_multi_low_input_with_num(n)

def max_profit(A, n):
    for i in range(0, n):
        for j in range(i+1, n):
            if i == 0 and j == 1:
                maxA = A[j] - A[i]
            if A[j]-A[i] > maxA:
                maxA = A[j]-A[i]
    print(maxA)

max_profit(A, n)

Submission status: Runtime Error

Solution code:
def read_n_lows_input(n):
    Alist=[int(input()) for i in range(n)]
    return Alist

def max_profit(A, n):
    for j in range(1, n):
        for i in range(0, j):
            if i == 0 and j == 1:
                maxA = A[j] - A[i]
            if A[j]-A[i] > maxA:
                maxA = A[j]-A[i]
    print(maxA)

n=int(input())

A = read_multi_low_input_with_num(n)

max_profit(A, n)

Submission status: Runtime Error

Solution code:
def read_n_lows_input(n):
    Alist=[int(input()) for i in range(n)]
    return Alist

def max_profit(A, n):
    minv = A[0]
    for j in range(1, n):
        if j == 1:
            maxv = A[j] - A[j-1]
        if maxv < A[j] - minv:
            maxv = A[j] - minv
        if minv > A[j]:
            minv = A[j]
    print(maxv)

n=int(input())

A = read_multi_low_input_with_num(n)

max_profit(A, n)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

#pp = [max(ls[i:])-x for i, x in enumerate(ls, 1) if i != len(ls)]

p = min(ls) - max(ls)

for i, x in enumerate(ls, 1):
    if i == len(pp):
        break
    if max(ls[i:]) - x > p:
        p = max(ls[i:]) - x

print(p)

Submission status: Runtime Error

Solution code:
import math

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

for i in range(2,n):
    t=int(input())

    if t-mint>maxtt: maxtt=t-mint
    if t<mint: mint=# TEMP: 

print(int(maxtt))

Submission status: Runtime Error

Solution code:
import math

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

r_i = r_t[0]
r_i_index = 0
diff = -math.inf
for _ in range(1, n):
    r_j = max(r_t[r_i_index+1:])

    tmp_diff = r_j - r_i

    if tmp_diff > diff:
        diff = tmp_diff

    for i in range(r_i_index, n):
        tmp_r_i = r_t[i]
        if tmp_r_i < r_i:
            r_i = tmp_r_i
            r_i_index = r_t.index(r_i)
            break

print(diff)

Submission status: Runtime Error

Solution code:
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
)

func main() {
        scanner := bufio.NewScanner(os.Stdin)
        scanner.Scan()
        n, _ := strconv.Atoi(scanner.Text()) //競プロでは基本的にエラーを握りつぶす方針で｡
        scanner.Scan()
        pivot, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        first, _ := strconv.Atoi(scanner.Text())
        result := first - pivot
        for i := 2; i < n; i++ {
                ok := scanner.Scan()
                if !ok {
                        break
                }
                current, _ := strconv.Atoi(scanner.Text())
                if current-pivot > result {
                        result = current - pivot
                }
        }
        fmt.Println(result)
}

Submission status: Runtime Error

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

for i in range(n-1):
    x=int(input())
    d=max-m,d)
    m=min(m,x)
print(d)

Submission status: Runtime Error

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

for i in range(n-1):
    x=int(input())
    d=max(x-m,d)
    m=min(m,x)
print(d)

Submission status: Runtime Error

Solution code:
n = int(input())
r = list((map(int, input()) for i in range(n)))
max_abs = 0
for i in range(len(r)):
    for j in range(i, len(r)):
        max_abs = max(max_abs, abs(r[j]-r[i]))
print(max_abs)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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: Runtime Error

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
ti = 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])) and ti > numbers[i]:
      temp = calcMax(i)
      #print("temp: " + str(temp))
      if temp > m:
          m = temp

print (m)

Submission status: Runtime Error

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

print (m)

Submission status: Runtime Error

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

    ans = min(r) - max(r)
    for i in reversed(range(1, n)):
        tmpr = r[:i]
        tmp = r[i] - min(tmpr)
        if tmp > ans:
            ans = tmp
    print(ans)


if __name__ == '__main__':
    main(

Submission status: Runtime Error

Solution code:
n = int(input())

t = []

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

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

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

print(val)

Submission status: Runtime Error

Solution code:
a,b = -1e11,1e11
for _ in int(input()):
    data = int(input())
    a,b = max(a,c-b),min(b,c)
print(a)

Submission status: Runtime Error

Solution code:
a,b = -1e11,1e11
for _ in range(int(input())):
    data = int(input())
    a,b = max(a,c-b),min(b,c)
print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

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[1:i_max])
b = max(rt[i_min:]) - rt[i_min]

print a if a > b else b

Submission status: Runtime Error

Solution code:
n = input()
minSeq = input()
maxv = -float("inf")
for i in range(n):
    R = input()
    if R - minSeq > maxv:
        maxv = R - minSeq
    if R < minSeq:
        minSeq = R
print(maxv)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
cat ALDS1_1_d.py
n = int(raw_input())
R = [int(raw_input()) for i in xrange(n)]
mn = R[0]
ans = -1e10
for r in R[1:]:
    ans = max(ans, r - mn)
    mn = min(mn, r)
print ans

Submission status: Runtime Error

Solution code:
import sys

x = []

for line in sys.stdin.readline():
    x.append(int(line))

length = int(x[0])

del x[0]

max = -(10 ** 9)

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

print max

Submission status: Runtime Error

Solution code:
import sys

x = []

max = -10**9

for line in sys.stdin.readline()
  x.append(line)

length = int(x[0])

x.remove(x[0])

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

print max

Submission status: Runtime Error

Solution code:
import sys

x = []

for line in raw_input():
    x.append(int(line))

length = int(x[0])

del x[0]

max = -(10 ** 9)

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

print max

Submission status: Runtime Error

Solution code:
import sys

x = []

max = -10**9

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

length = int(x[0])

x.remove(x[0])

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

print max

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

n = lines[0]
lst = lines[1:]

i = 0
for ri in lst:
    if i is 0:
        maxpro = lst[1] - lst[0]
    for rj in lst[i+1:]:
        sub = rj - ri
        if maxpro < sub:
            maxpro = sub
    i += 1

print maxpro

Submission status: Runtime Error

Solution code:
import sys
my_list = []
max_list = []
len_line = int(sys.stdin.readline().strip())

for item in sys.stdin.readlines()[:-1]:
    my_list.append(int(item.strip()))

for i in range(1, len_line):
    max_list.append(my_list[i] - min(my_list[:i]))

print max(max_list)

Submission status: Runtime Error

Solution code:
import sys
my_list = []
max_list = []
len_line = int(sys.stdin.readline().strip())

for item in sys.stdin.read()[:-1]:
    my_list.append(int(item.strip()))

for i in range(1, len_line):
    max_list.append(my_list[i] - min(my_list[:i]))

print max(max_list)

Submission status: Runtime Error

Solution code:
num = raw_input()
num_list = []
for i in range(int(num)):
        a = raw_input()
        num_list.append(int(a))

minv = num_list[0]

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

print maxv

Submission status: Runtime Error

Solution code:
import sys

x = []

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

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

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

  

print max

Submission status: Runtime Error

Solution code:
import sys

x = []

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

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

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

  

print max

Submission status: Runtime Error

Solution code:
num = raw_input()

for i in range(int(num)):
    a = raw_input()
    num_list.append(int(a))

min_ans = num_list[0]
max_ans = float("-inf")
for item in num_list[1:]:
    if i - min_ans > max_ans:
        max_ans = i - min_ans
    if i < min_ans:
        min_ans = i

print max_ans

Submission status: Runtime Error

Solution code:
n = int(input())
num = n - 1
price = []
date = 0
max_pro = -999999999

while(n>0):
    x = int(input())
    dataset = [date,x]
    price.append(dataset)
    n -= 1
    date += 1

price.sort(key=lambda price: price[1])

for i in range(0,num):
    j = num
    while(j > i):
        if(price[i][0]<price[j][0]):
            pro = price[j][1] - price[i][1]
            break
        j -= 1
    if (max_pro < pro):
        max_pro = pro
print ("{0}".format(max_pro))

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

n = lines[0]
lst = map(lambda x:int(x), lines[1:])

c = 0
while True:
   if len(lst) ==0:
        break
   i = lst.index(max(lst))
   sub_lst = lst[:i]
   if len(sub_lst) ==0 and c == 0:
       pass
   elif len(sub_lst) -pre
   else:
       maxpro = max(lst) - min(sub_lst)
   pre = lst[i]
   lst = lst[i1:]
   c+= 1
  print maxpro

Submission status: Runtime Error

Solution code:
import sys
lines = sys.stdin.readlines()

n = lines[0]
lst = map(lambda x:int(x), lines[1:])

c = 0
while True:
   if len(lst) ==0:
        break
   i = lst.index(max(lst))
   sub_lst = lst[:i]
   if len(sub_lst) ==0 and c == 0:
       pass
   elif len(sub_lst) -pre:
   else:
       maxpro = max(lst) - min(sub_lst)
   pre = lst[i]
   lst = lst[i1:]
   c+= 1
  print maxpro

Submission status: Runtime Error

Solution code:
n = int(raw_input())
num_list = [int(raw_input()) for i in xrange(n)]
#print num_list

ans = 1 - pow(10, 9)
chk = num_list[0]

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

print ans

Submission status: Runtime Error

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

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

print (maxv)

Submission status: Runtime Error

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

l = 0
r = 1
while r + 1 < N:
    if A[l] > A[r]:
        l = r
    elif A[r] > A[r + 1]:
        max_v = max(max_v, A[r] - A[l])
        if A[l] > A[r + 1]:
            l = r + 1
            r = l
    r += 1
max_v = max(max_v, A[r] - A[l])
print(max_v)

Submission status: Runtime Error

Solution code:
N = raw_input()

while line = sys.stdin.readlines():

Submission status: Runtime Error

Solution code:
N = raw_input()

while line = sys.stdin.readlines():

Submission status: Runtime Error

Solution code:
n = input()

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

max = 0

for i in range(n):
  for j in range(i):
    d = R[i] - R[j]
    if max < d:
      max = d

print max

Submission status: Runtime Error

Solution code:
n = raw_input()
max = 0
min = 0
for x in range(n):
  x = raw_input()
  if x > max:
    max = x
  if x < min:
    min = x

print max-min

Submission status: Runtime Error

Solution code:
n = raw_input()
x = 0
y = 0
a = raw_input()
for 1 in n-1:
   c = raw_imput()
   if a < c:
      a = c
   else:
      y = a - c
   if y > x:
      x = y
print x

Submission status: Runtime Error

Solution code:
n = input()
maxi = 0
mini = 0

for i in range(n):
  tmp = input n
  maxi = max(maxi, tmp)
  mini = min(mini, tmp)

print maxi

Submission status: Runtime Error

Solution code:
word = raw_input()
for i in range(len(word)):
    if word[i] == '\n':
        n = word[:i - 1]
        word = word[i:]
        break
n = int(n)

max = 0
min = 0
num = range(n)
for i in range(n):
    for j in range(7):
        if word[j] == '\n':
            num[i] = word[:j - 1]
            num[i] = int(num[i])
            word = word[j:]
            break

dif = range(n - 1)
min = 0
for i in range(n):
    for j in range(i):
        if num[j] < min:
            min = num[j]
    dif[i] = num[i] - min
    if dif[i] > max:
        max = dif[i]

print max

Submission status: Runtime Error

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

min = list[0]
max = list[0]
dif = []
for i in range(n):
    for j in range(i - 1):
        if list[j] < min:
            min = list[j]
    dif[i] = list[i] - min
    if dif[i] > max:
        max = dif[i]

print max

Submission status: Runtime Error

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

min = list[0]
max = list[0]
dif = []
for i in range(n):
    for j in range(i - 1):
        if list[j] < min:
            min = list[j]
            dif.append(list[i] - min)
    if dif[i] > max:
        max = dif[i]

print max

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = input()
if n>= 2 and n <= 200000
   for i in range(0, n-1):
      R = map(int, raw_input().split())
   minv = R[0]
   maxv = R[1] - R[0]
   for j in range(1, n-1):
      maxv = max(maxv, R[j] - minv) 
      minv = min(minv, R[j])
print maxv - minv

Submission status: Runtime Error

Solution code:
n = input()
if n>= 2 and n <= 200000
   for i in range(0, n-1):
      R[i] = map(int, raw_input().split())
   minv = R[0]
   maxv = R[1] - R[0]
   for j in range(1, n-1):
      maxv = max(maxv, R[j] - minv) 
      minv = min(minv, R[j])
print maxv - minv

Submission status: Runtime Error

Solution code:
n = input()
if n>= 2 and n <= 200000
   R = map(int, raw_input().split())
   minv = R[0]
   maxv = R[1] - R[0]
   for j in range(1, n-1):
      maxv = max(maxv, R[j] - minv) 
      minv = min(minv, R[j])
print maxv - minv

Submission status: Runtime Error

Solution code:
n = input()
if n >= 2 and n <= 200000
   R = map(int, raw_input().split())
   minv = R[0]
   maxv = R[1] - R[0]
   for j in range(1, n-1):
      maxv = max(maxv, R[j] - minv) 
      minv = min(minv, R[j])
print maxv - minv