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

Solution code:
def main(){
 

    n = input()
    for i in n-1:
        R[i] = input()
 
    max = R[1] - R[0]
    min = R[0]
 
    for i+1 in n-1:
        if R[i]-min>max:
            max = R[i] - min
        if R[i]<min
            min = R[i]
 
    print max
 
    return 0

}

Submission status: Runtime Error

Solution code:
def main(){
 

    n = input()
    for i in n-1:
        R[i] = input()
 
    max = R[1] - R[0]
    min = R[0]
 
    for i+1 in n-1:
        if R[i]-min>max:
            max = R[i] - min
        if R[i]<min:
            min = R[i]
 
    print max
 
    return 0

}

Submission status: Runtime Error

Solution code:
def main(){
 

    n = input()
    for i in n-1:
        R[i] = input()
 
    max = R[1] - R[0]
    min = R[0]
 
    for i+1 in n-1:
        if R[i]-min>max:
            max = R[i] - min
        if R[i]<min:
            min = R[i]
 
    print max

}

Submission status: Runtime Error

Solution code:
def main(){
 

    n = input()
    R = []

    for i in n-1:
        R.append(input())
 
    max = R[1] - R[0]
    min = R[0]
 
    for i+1 in n-1:
        if R[i]-min>max:
            max = R[i] - min
        if R[i]<min:
            min = R[i]
 
    print max

}

Submission status: Runtime Error

Solution code:
def main(){
 

    n = input()
    R = []

    for i in range(n-1):
        R.append(input())
 
    max = R[1] - R[0]
    min = R[0]
 
    for i+1 in range(n-1):
        if R[i]-min>max:
            max = R[i] - min
        if R[i]<min:
            min = R[i]
 
    print max

}

Submission status: Runtime Error

Solution code:
def main(){
 

    n = input()
    R = []

    for i in range(n-1):
        R.append(input())
 
    max = R[1] - R[0]
    min = R[0]
 
    for i in range(n-1):
        if R[i]-min>max:
            max = R[i] - min
        if R[i]<min:
            min = R[i]
 
    print max

}

Submission status: Runtime Error

Solution code:
    n = input()
    R = []

    for i in range(n-1):
        R.append(input())
 
    max = R[1] - R[0]
    min = R[0]
 
    for i+1 in range(n-1):
        if R[i]-min>max:
            max = R[i] - min
        if R[i]<min:
            min = R[i]
 
    print max

Submission status: Runtime Error

Solution code:
    n = input()
    R = []

    for i in range(n):
        R.append(input())
 
    max = R[1] - R[0]
    min = R[0]
 
    for i+1 in range(n):
        if R[i]-min>max:
            max = R[i] - min
        if R[i]<min:
            min = R[i]
 
    print max

Submission status: Runtime Error

Solution code:
    n = input()
    R = []

    for i in range(1,n):
        R.append(input())
 
    max = R[1] - R[0]
    min = R[0]
 
    for i in range(2,n):
        if R[i]-min>max:
            max = R[i] - min
        if R[i]<min:
            min = R[i]
 
    print max

Submission status: Runtime Error

Solution code:
n = input()
R = []

for i in range(1,n):
    R.append(input())
 
max = R[1] - R[0]
min = R[0]
 
for i in range(2,n):
    if R[i]-min>max:
        max = R[i] - min
    if R[i]<min:
        min = R[i]
 
print max

Submission status: Runtime Error

Solution code:
n = input()
R = []

for i in range(1,n):
    R.append(input())
 
max = R[1] - R[0]
min = R[0]
 
for i in range(2,n):
    if R[i]-min>max:
        max = R[i] - min
    if R[i]<min:
        min = R[i]
 
print 1

Submission status: Runtime Error

Solution code:
n = input()
R = []

for i in range(1,n):
    R.append(input())
 
max = R[1] - R[0]
min = R[0]
 
for i in range(2,n):
    if R[i] - min > max:
        max = R[i] - min
    if R[i] < min:
        min = R[i]
 
print max

Submission status: Runtime Error

Solution code:
num = input()
l =[]

for i in range(num):
   l.append(input())

max = l[1] - l[0]
for i in range(num):
   for j in range(num-1):
      if max < l[j] - l[i]
         max = l[j] - l[i]
print max

Submission status: Runtime Error

Solution code:
N=int(raw_input())
max=(-1)*(10**9)
x1=input()
min=x1

for i in range(n-1):
  x=int(raw_input())

  if max < x-min:
    max=x-min
  if min>x:
    min=x
print max

Submission status: Runtime Error

Solution code:
n = int(raw_input())
minv =  R[0]
maxv = (-1)*10**9

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

Submission status: Runtime Error

Solution code:
n = int(raw_input())
minv =  R[0]
maxv = (-1)*10**9

  for j in range(0, n-1):
    if minv >= R[j]:
       minv = R[j]
    if maxv <= R[i+1] - minv:
       maxv = R[i+1] - minv

Submission status: Runtime Error

Solution code:
n = int(raw_input())
minv =  R[0]
maxv = (-1)*10**9

  for j in range(2, n-1):
    if minv >= R[j]:
       minv = R[j]
    if maxv <= R[i+1] - minv:
       maxv = R[i+1] - minv

Submission status: Runtime Error

Solution code:
n = int(raw_input())
minv =  10**9
maxv = (-1)*10**9

  for j in range(0, n-1):
    if minv >= R[j]:
       minv = R[j]
    if maxv <= R[i+1] - minv:
       maxv = R[i+1] - minv

Submission status: Runtime Error

Solution code:
n = int(raw_input())
minv =  10**9
maxv = (-1)*10**9

  for j in range(0, n-1):
    if minv >= R[j]:
       minv = R[j]
    if maxv <= R[i+1] - minv:
       maxv = R[i+1] - minv
print max

Submission status: Runtime Error

Solution code:
n = int(raw_input())
minv =  10**9
maxv = (-1)*10**9

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

Submission status: Runtime Error

Solution code:
n = int(raw_input())
minv =  10**9
maxv = (-1)*10**9

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

Submission status: Runtime Error

Solution code:
n = int(raw_input())
minv =  10**9
R[0] = 0
maxv = (-1)*10**9

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

Submission status: Runtime Error

Solution code:
n = int(raw_input())
minv =  10**9
R[0] = 0
maxv = (-1)*10**9

for j in range(n-1):
    if minv >= R[j]:
       minv = R[j]
    if maxv <= R[j+1] - minv:
       maxv = R[j+1] - minv
print maxv

Submission status: Runtime Error

Solution code:
n = input()
a0 = input()
a1 = input()
maxv = a1 - a0
minv = a0

for j in range(n-1):
  v = input()
  maxv = max(maxv, v-minv)
  minv = min(v, minv)

print maxv

Submission status: Runtime Error

Solution code:
n = input()
a0 = input()
a1 = input()
maxv = a1 - a0
minv = a0

for j in range(1:n-1):
  v = input()
  maxv = max(maxv, v-minv)
  minv = min(v, minv)

print maxv

Submission status: Runtime Error

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

for j in range(1:n-1):
  v = input()
  maxv = max(maxv, v-minv)
  minv = min(v, minv)

print maxv

Submission status: Runtime Error

Solution code:
import math

n = input()
maxv = -1 * 10**9
minv = input()

for j in range(1:n-1):
  v = input()
  maxv = max(maxv, v-minv)
  minv = min(v, minv)

print maxv

Submission status: Runtime Error

Solution code:
import math

n = input()
maxv = -1 * 10**9
minv = input()

for j in range(1:n-1):
  v = input()
  maxv = max(maxv, v-minv)
  minv = min(v, minv)

print '{0}'.format(maxv)

Submission status: Runtime Error

Solution code:
import math

n = input()
maxv = -1 * 10**9
minv = input()

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

print '{0}'.format(maxv)

Submission status: Runtime Error

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

for j in range(n-1):
  v = input()
  if maxv < v - minv:
    maxv = v - minv
  if minv > v
    minv = v

print maxv

Submission status: Runtime Error

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

for j in range(1,n-1):
  v = input()
  if maxv < v - minv:
    maxv = v - minv
  if minv > v
    minv = v

print maxv

Submission status: Runtime Error

Solution code:
num      = raw_input()
max      = 1 - 1000000000
length   = len(num)

for i in range (length):
    for j in range (i + 1, n):
        if (max > (num[i] - num[j])):
            max = num[i] - num[j]

print max

Submission status: Runtime Error

Solution code:
def main():
    
    N = input()
    a = [input() for y in range(N)]
    a_max = -10**9
    for i in xrange(1,len(a)):
        if (max(a[(i+1):]) - a[i]) >= a_max:
            a_max = max(a[(i+1):]) - a[i]
    return a_max

main()

Submission status: Runtime Error

Solution code:
    N = input()
    a = [input() for y in range(N)]
    a_max = -10**9
    for i in xrange(1,len(a)-1):
        if (max(a[(i+1):]) - a[i]) >= a_max:
            a_max = max(a[(i+1):]) - a[i]
    print a_max

Submission status: Runtime Error

Solution code:
raw_data = raw_input()

data = raw_data.split('\n')

n = data.pop(0)

max_v = 1000000000
min_v = -1000000000
for i, r in enumerate(data):
    max_v = max(max_v, r - min_v)
    min_v = min(min_v, r)

print(max_v)

Submission status: Runtime Error

Solution code:
max_v = 1000000000
min_v = -1000000000

with open('in1.txt', 'r') as f:
    raw_data = f.readline()
    n = raw_data

    for r in f:
        max_v = max(max_v, r - min_v)
        min_v = min(min_v, r)
    
print(max_v)

Submission status: Runtime Error

Solution code:
max_v = 1000000000
min_v = -1000000000

n = input()
data = []
for i in range(N):
    data.append(input())

for r in data:
    max_v = max(max_v, r - min_v)                                               
    min_v = min(min_v, r)
    
print(max_v)

Submission status: Runtime Error

Solution code:
a=input()
b=[]
for i in range(0,a+1):
    b.append()
c=-400001
for i in range(a):
    for ii in range(i,a):
        if b[ii]-b[i]>c:c=b[ii]-b[i]
print(str(c))

Submission status: Runtime Error

Solution code:
a=int(input())
b=[]
for i in range(a+1):
    b.append(int(input()))
c=-400001
for i in range(a):
    for ii in range(i,a):
        if b[ii]-b[i]>c:c=b[ii]-b[i]
print(str(c))

Submission status: Runtime Error

Solution code:
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
S = tuple(A)
Smax = ((S[i]-min(S[:i])) for i in range(1, N) if S[i] > S[i-1])
print(max(Smax))

Submission status: Runtime Error

Solution code:
n = input()
R = [input() for i in xrange(n)]

Rmin = n
maxdif = R[1] - R[0]

while Rmin > 0:
    tRmin = R.index(min(R[0:Rmin]))
    Rmax = R.index(max(R[tRmin:Rmin]))
    if tRmin == Rmax:
        if tRmin == n:
            tRmin-=1
        elif tRmin < n:
            Rmax = tRmin + 1
    Rmin = tRmin
    if (R[Rmax] - R[Rmin]) > maxdif:
        maxdif = R[Rmax] - R[Rmin]

print maxdif

Submission status: Runtime Error

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

maxv = -99999999
minimum = values[0]

for i in range(1, N):
    if values[i] - minimum > maxv:
        maxv = values[i] - minimum
    if values[i] < minimum:
        minimum = values[i]

print(maxv)

Submission status: Runtime Error

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 0 < mx < i - mn:
        mx = i - mn
    elif 0 > i-mn > max:
        mx = i - mn
        mn = i
    elif mn > i:
        mn = i

print(mx)

Submission status: Runtime Error

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

min_i = N-2
max_i = N-1

for i in range(N-1)[::-1]:
    for j in range(i+1, N):
        if r[j] - r[i] > r[max_i] - r[min_i]:
            max_i = j
            min_i = i


print(tmp)

Submission status: Runtime Error

Solution code:
N = input()
a = []
for i in range(N):
    a.append(input())
max_profit = a[1] - a[0]
for i in range(2,N):
	if a[i] - a[i-1] > max_profit
		max_profit = a[i] - a[i-1]
print(max_profit)

Submission status: Runtime Error

Solution code:
N = input()
a = []
for i in range(N):
    a.append(input())
max_profit = a[1] - a[0]
for i in range(2,N):
	if a[i] - a[i-1] > max_profit
		max_profit = a[i] - a[i-1]
print(str(max_profit))

Submission status: Runtime Error

Solution code:
N = int(input())
a = []
for i in range(N):
    a.append(int(input())
max_profit = a[1] - a[0]
for i in range(2,N):
	if a[i] - a[i-1] > max_profit:
		max_profit = a[i] - a[i-1]
print(str(max_profit))

Submission status: Runtime Error

Solution code:
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
max_profit = a[1] - a[0]
min_val = min(a[1],a[0])
for i in range(2,N):
	if a[i] < min_val:
		min_val = a[i]
	else if a[i] - min_val > max_profit:
		max_profit = a[i] - min_val
print(str(max_profit))

Submission status: Runtime Error

Solution code:
n = int(input())
ps = [int(input()) for _ in range(n)]
maxpro = 0
for i, p in enumerate(ps[:-1]):
  pro = max(ps[i + 1:]) - p
  maxpro = max(pro, maxpro)
print maxpro

Submission status: Runtime Error

Solution code:
_temp = []
with open('_input_alds1', 'r') as f:
    for line in f.readlines():
        _temp.append(int(line.rstrip()))

_temp = _temp[1:]
my_max = []

for i, val in enumerate(_temp[:-1]):
    my = max(_temp[i + 1:]) - val
    if i == 0:
        my_max.append(my)
    else:
        if my > max(my_max):
            my_max.append(my)

print(max(my_max))

Submission status: Runtime Error

Solution code:
from _collections import deque

_temp = deque([])
my_max = []

size = int(input().rstrip())
for i in range(size):
    try:
        _temp.append(int(input()))
    except EOFError:
        continue

for val in _temp:
    v = _temp.popleft()
    my = max(_temp) - v
    if i == 0:
        my_max.append(my)
    else:
        if my > max(my_max):
            my_max.append(my)

print(max(my_max))

Submission status: Runtime Error

Solution code:
from _collections import deque

_temp = deque([])
my_max = []

size = int(input().rstrip())
for i in range(size):
    try:
        _temp.append(int(input()))
    except EOFError:
        continue


for val in list(_temp)[:-1]:
    v = _temp.popleft()
    my = max(_temp) - v

    if len(my_max) == 0:
        my_max.append(my)
    else:
        if my > max(my_max):
            my_max.append(my)

print(max(my_max))

Submission status: Runtime Error

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

interest = [m[1]-m[0]]
for i in range(n):
    for j in range(i+1,n):
        if interest[-1] < m[j]-m[i]
        interest.append(m[j]-m[i])
print(interest[-1])

Submission status: Runtime Error

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

interest = [m[1]-m[0]]
for i in range(n):
    for j in range(i+1,n):
        if interest[-1] < m[j]-m[i]:
        interest.append(m[j]-m[i])
print(interest[-1])

Submission status: Runtime Error

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

interest = [m[1]-m[0]]
for i in range(n):
    M = max(m[i+1:])
    if interest[-1] <M-m[i]:
        interest.append(M-m[i])
print(interest[-1])

Submission status: Runtime Error

Solution code:
import sys

a = []
for line in sys.stdin:
 a.append(int(line))
max=a[0]
min=a[1]

for b in a
 if a[b] <= min:
  min=a[b]
 if a[b] >= max:
  max=a[b]

print(max-min)

Submission status: Runtime Error

Solution code:
import sys

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

min=a[0]
max=-1*10**9

for b in a:
 if a[b+1]-min >= max:
  max=a[b]-min
 if a[b+1] <= min:
  min=a[b]

print(max)

Submission status: Runtime Error

Solution code:
n = int(raw_input())

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

ans = 1 - 10**9
for i in range(n):
    R[i] = int(raw_input())
    if i == 0:
        min_R = R[0]
        continue
    if min_R < R[i]:
        if ans < R[i]-min_R:
            ans = R[i] - min_R
    elif min_R > R[i]:
        if ans < R[i]-min_R:
            ans = R[i] - min_R
        min_R = R[i]
    else:
        if ans < 0
        ans = 0
        
print ans

Submission status: Runtime Error

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

candidate = []
for i, v in enumerate(stack):
    for j in [el for el in stack[:i] if v > el]:
        candidate.append(v - j)
        candidate = [max(candidate)]

print(candidate[0])

Submission status: Runtime Error

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

for i in range(len(stack) - 1):
    for r1, r2 in zip(stack[::1], stack[i::1]):
        candidate.append(r2 - r3)
    candidate = [max(candidate)]

print(candidate[0])

Submission status: Runtime Error

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

for i in range(len(stack) - 1):
    for r1, r2 in zip(stack[::1], stack[i::1]):
        candidate.append(r2 - r1)
    candidate = [max(candidate)]

print(candidate[0])

Submission status: Runtime Error

Solution code:
import sys

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

for r in map(int,sys.stdin.readlines()):
  if maxv < r-minv < 0:
    maxv = r-minv
    minv = r
  elif maxv < r-minv:
    maxv = r-minv
  elif m < 0:
    minv = r

print(maxv)

Submission status: Runtime Error

Solution code:
import sys
 
n = int(input())
minv = int(input())
maxv = -1000000000
 
for r in map(int,sys.stdin.readlines()):
  m = r-minv
  if maxv < m: maxv = m
    if m < 0: minv = r
  elif m < 0: minv = r
 
print(maxv)

Submission status: Runtime Error

Solution code:
import sys
input()
a,b=-1e11,1e11
for i in map(int,sys.stdin.readlines()):
  a=max(a,i-b)
  b=min(i,b)
print(mar)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

num = int(input())
input_line = sys.stdin.readlines()
inputnum = [int(x.strip()) for x in input_line]

diff = []
for j in range(num):
    for i in range(j):
        diff.append(inputnum[j] - inputnum[i])
print(max(*diff))

Submission status: Runtime Error

Solution code:

for i in R[1:]:
    max_p = -10^ 9
    min_p = 10 ^ 9
    max_p = max(i - min_p, max_p)
    min_p = min(min_p, i)
    return max_p

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

l = np.zeros(n)
for i in range(n):
    l[i] = int(input())

x = [l[j] - l[i] for j in range(1, n) for i in range(j)]

print(int(max(x)))

Submission status: Runtime Error

Solution code:
n = int(input())

r_min = int(input())
r_t = int(input())
g_max = r_t - r_min
r_ min = min(r_min, r_t)

for _ in range(n-2):
    r_t = int(input())
    g_max  = max(g_max, r_t - r_min)
    r_min = min(r_min,r_t)
print(g_max)

Submission status: Runtime Error

Solution code:
n = int(input())
r_min = int(input())
r_t = int(input())
g_max = r_t - r_min
r_ min = min(r_min, r_t)

for _ in range(n-2):
    r_t = int(input())
    g_max  = max(g_max, r_t - r_min)
    r_min = min(r_min, r_t)
print(g_max)

Submission status: Runtime Error

Solution code:
n = int(input())
r_min = int(input())
r_t = int(input())
g_max = r_t - r_min
r_ min = min(r_min, r_t)

for _ in range(n-2):
    r_t = int(input())
    g_max  = max(g_max, r_t - r_min)
    r_min = min(r_min, r_t)

print(g_max)

Submission status: Runtime Error

Solution code:
import sys

def get_maximum_profit:
    element_number = int(input())
    v0 = int(input())
    v1 = int(input())

    min_v = v0
    max_profit = v1-v0

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

if __name__ == '__main__':
    get_maximum_profit()

Submission status: Runtime Error

Solution code:
n=int(input())
fir=int(input())
sec=int(input())
max=sec
if(fir>sec):
    min=sec
elif(fir<=sec):
    min=fir
max_dif=sec-fir
for i in range(n-2):
    x=int(input())
    if x>max_num:
        max_num = x
        if max_dif < x-min:
            max_dif = x-min
    if x<min:
        min = x
        max_num=1
print(max_dif)

Submission status: Runtime Error

Solution code:
n=int(input())
fir=int(input())
sec=int(input())
max=sec
if(fir>sec):
    min=sec
elif(fir<=sec):
    min=fir
max_dif=sec-fir
if n>2:
    for i in range(n-2):
        x=int(input())
        if x>max_num:
            max_num = x
            if max_dif < x-min:
                max_dif = x-min
        if x<min:
            min = x
            max_num=1
print(max_dif)

Submission status: Runtime Error

Solution code:
n=int(input())
fir=int(input())
sec=int(input())
max_=sec
if(fir>sec):
    min_=sec
elif(fir<=sec):
    min_=fir
max_dif=sec-fir
if n>2:
    for i in range(n-2):
        x=int(input())
        if x>max_num:
            max_num = x
            if max_dif < x-min_:
                max_dif = x-min_
        if x<min_:
            min_ = x
            max_num=1
print(max_dif)

Submission status: Runtime Error

Solution code:
n=int(input())
fir=int(input())
sec=int(input())
max_=sec
if(fir>sec):
    min_=sec
elif(fir<=sec):
    min_=fir
max_dif=sec-fir
if n>2:
    for i in range(n-3):
        x=int(input())
        if x>max_num:
            max_num = x
            if max_dif < x-min_:
                max_dif = x-min_
        if x<min_:
            min_ = x
            max_num=1
print(max_dif)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
r = [None] * n
min = math.inf
max = -math.inf
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: Runtime Error

Solution code:
n = int(input())
l = [int(input()) for i in range(n)][::-1]
maximum = l[0] - min(l[1:])
if maximum > 0:
    x = [i for i in l if l[0] <= i]
for j in range(len(x)-1):
    if maximum < l[j] - min(l[j+1:]):
        maximum = l[j] - min(l[j+1:])
input(maximum)

Submission status: Runtime Error

Solution code:
n = int(input())
l = [int(input()) for i in range(n)][::-1]
maximum = l[0] - min(l[1:])
x = l
if maximum > 0:
    x = [i for i in l if l[0] <= i]
for j in range(len(x)-1):
    if maximum < l[j] - min(l[j+1:]):
        maximum = l[j] - min(l[j+1:])
input(maximum)

Submission status: Runtime Error

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
l = l[::-1]
maximum = l[0] - min(l[1:])
x = l
if maximum > 0:
    x = [i for i in l if l[0] <= i]
for j in range(len(x)-1):
    if maximum < l[j] - min(l[j+1:]):
        maximum = l[j] - min(l[j+1:])
input(maximum)

Submission status: Runtime Error

Solution code:
day = int(input('Please enter the number of day '))

buy = []
for i in range(day):
    buy.append(int(input('Please enter the buying price of Day '+str(i+1)+' ')))

sell = []
for i in range(day):
    sell.append(int(input('Please enter the selling price of Day '+str(i+1)+' ')))

max_table=[]
for i in range(day):
    table=[]
    for j in range(day):
        if i <= j:
         pro = sell[j]-buy[i]
         table.append(pro)
         max_table.append(max(table))

print(max(max_table))

Submission status: Runtime Error

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

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

    r = max(nums[1:]) - nums[0]

    for i in range(1, n-1):
        ri = nums[i]

        if ri == rj:
            rj = max(nums[i+1:])

        r = max(r, rj-ri)

    print(r)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

maxv = -inf
minv = inf

n = int(input())

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

print(maxv)

Submission status: Runtime Error

Solution code:
maxv = -inf
minv = inf

n = int(input())

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

print(maxv)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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(1,v[0],1):
    for j in range(i+1, v[0], 1):
        dif = v[j] - v[i]
        dif_max = dif if dif_max < dif else dif_max
print("{}".format(dif_max))

Submission status: Runtime Error

Solution code:
v = []
v = str(input()).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: Runtime Error

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

Solution code:
v = []
v = str(input()).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: Runtime Error

Solution code:
v = []
v = str(input()).split()
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: Runtime Error

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

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

print("{}".format(v[3]))

Submission status: Runtime Error

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

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

l = v[0]

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

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

Submission status: Runtime Error

Solution code:
v = str(input()).split()
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: Runtime Error

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

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

len = v[0]
for i in range(2, 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("{}".format(dif_max))

Submission status: Runtime Error

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

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

print(v[2])

Submission status: Runtime Error

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

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

print(v[2])

Submission status: Runtime Error

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

print(v[2])

Submission status: Runtime Error

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

print(v[2])

Submission status: Runtime Error

Solution code:
v = []
v = input().split()

print(v[2])

Submission status: Runtime Error

Solution code:
v = str(inp).split()
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(dif_max)

Submission status: Runtime Error

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

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

print(v[1])

Submission status: Runtime Error

Solution code:
v = input().split()
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(dif_max)

Submission status: Runtime Error

Solution code:
num=int(input())
r_1=int(input())
r_2=int(input())
max_profit=r_2 - r_1
min_value=min(r_1,r_2)

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

Submission status: Runtime Error

Solution code:
num=int(input())
r_1=int(input())
r_2=int(input())
max_profit=r_2 - r_1
if r_1<r_2:
    min_value=r_1
else:
    min_value=r_2

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, a = map(int, input().split())
Max = -1000000
Min = a
for i in range(n):
    x = input()
    if (Max < (x-Min)):
        Max = x-Min
    if (x < Min):
        Min = x
print(Max)

Submission status: Runtime Error

Solution code:
n, a = map(int, input().split())
Max = -1000000
Min = a
for i in range(n):
    x = int(input())
    if (Max < (x-Min)):
        Max = x-Min
    if (x < Min):
        Min = x
print(Max)

Submission status: Runtime Error

Solution code:
n, a = map(int, input().split())
Max = -10000000
Min = a
for i in range(n):
    x = int(input())
    if (Max < (x-Min)):
        Max = x-Min
    if (x < Min):
        Min = x
print(Max)

Submission status: Runtime Error

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

Submission status: Runtime Error

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