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:
N = input()
N = int(N)
l = [int(input()) for i in range(N)]
flg = 1
for i in range(0,len(l)-1):
    for j in range(i+1,len(l)):
        if(ma < l[j]-l[i] or flg ==1):
            ma = l[j] - l[i]
            flg = 0
print(ma)

Submission status: Runtime Error

Solution code:
n = int(input())
rlist = []
for i in range(n):
    r = int(input())
    rlist.append(r)
mlist = []
for i in range(n):
    m = rlist[i] - min(rlist[:i])
    mlist.append(m)
mlist.sort()
print(mlist[-1])

Submission status: Runtime Error

Solution code:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))
    
del a[0]
del a[len(a)-1]
b = []
for line in sys.stdin:
    b.append(int(line))
del b[0]
del b[0]
print(max(b)-min(a))

Submission status: Runtime Error

Solution code:
import sys

a = []
for line in sys.stdin:
    a.append(int(line))
    
del a[0]
del a[len(a)-1]
b = []
for line in sys.stdin:
    b.append(int(line))

del b[0]
del b[0]
print(max(b)-min(a))

Submission status: Runtime Error

Solution code:
import sys

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

del a[0]
del a[len(a)-1]
del b[0]
del b[0]

sub - -100000000
for i in range(len(a)):
    for j in range(len(b)):
        if j >= i:
            if sub <= b[j]-a[i]:
                sub = b[j]-a[i]
print(sub)

Submission status: Runtime Error

Solution code:
import sys

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

del a[0]
del a[len(a)-1]
del b[0]
del b[0]

maxv = -100000000
minv = a[0]
for i in range(len(a)):
    maxv = max(sub,b[i]-minv)
    minv = min(minv,b[i])

print(sub)

Submission status: Runtime Error

Solution code:
n=input()
l=[input() for _ in range(n)]
mi=l.index(min(l))
ma=l.index(max(l))
print max(max(l)-min(l[:ma]),max(l[mi:])-min(l))

Submission status: Runtime Error

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

Submission status: WA: Presentation Error

Solution code:
a=[]
n=int(input())
nn=n
while(nn>0):
    b=int(input())
    a.append(b)
    nn-=1

print()
a.reverse()
sa=a[0]-a[1]
for i in range(1,n):
    sb=a[i-1]-min(a[i:])
    if(sb>sa):
        sa=sb

print(sa)

Submission status: WA: Presentation Error

Solution code:
num = int(input())
minnum = 10 ** 18 + 1
ans = (-10 ** 9 - 1)
for n in range(num):
    newnum = int(input())
    print()
    ans = max(ans,newnum - minnum)
    minnum = min(minnum,newnum)
print(ans)

Submission status: WA: Presentation Error

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