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:
import sys

num_list = int(sys.stdin.readline())
lines = sys.stdin.readlines()
nums = map(int, lines)

max_diff = -sys.maxint - 1
min_val = nums[0]
for num in nums :
    diff = num - min_val
    if diff > max_diff :
        max_diff = diff
    if num < min_val :
        min_val = num

print max_diff

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
R = [int(raw_input()) for i in xrange(n)]
mx = mn = R[0]
ans = 0
for i in R[1:]:
    if i < mn:
        mx = mn = i
    mx = max(mx, i)
    ans = max(ans, mx - mn)
print ans

Submission status: Wrong Answer

Solution code:
n = input()
maxv = - 1 * pow(10, 9)
minv = input()
for _ in xrange(1, n - 1):
    Rj = input()
    maxv = max(maxv, Rj - minv)
    minv = min(minv, Rj)

print maxv

Submission status: Wrong Answer

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

result = l[1] - l[0]
for j in l[1:]:
    for i in l[0:j]:
        if j - i > result:
            result = j - i
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
maxv = -2 * 10 ** 9
minv = 2 * 10 ** 9
for i in range(1, n):
    v = int(input())
    maxv = max(maxv, v - minv)
    minv = min(minv, v)
print(maxv)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())

a=int(input())
b=int(input())
min_number=min(a,b)
profit=b-a


for i in range(N-2):
	c=int(input())
	if min_number>c:
		min_number=c
	if profit<c-min_number:
		profit=c-min_number

print(profit)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
R = list()
max = -1000000

for i in range(n):
    R.append(int(raw_input()))
    for j in range(i):
        if max < R[i] - R[j]:
            max = R[i] - R[j]
            
print max

Submission status: Wrong Answer

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

maxv = 0
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: Wrong Answer

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

maxv = 0
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: Wrong Answer

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

maxv = 0
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: Wrong Answer

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])):
  sa = int(x[i]) - min
  if max < sa:
    max = sa
  if min > int(x[i]):
    min = int(x[i])

  

print max

Submission status: Wrong Answer

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

max_ans = -1000
for item in sys.stdin.readlines()[:-1]:
    i = int(item.strip())
    if i - min_ans > max_ans:
        max_ans = i - min_ans
    if i < min_ans:
        min_ans = i

print max_ans

Submission status: Wrong Answer

Solution code:
import sys
len_line = int(sys.stdin.readline().strip())
min_ans = int(sys.stdin.readline().strip())

max_ans = -1000000000000000
for item in sys.stdin.readlines()[:-1]:
    i = int(item.strip())
    if i - min_ans > max_ans:
        max_ans = i - min_ans
    if i < min_ans:
        min_ans = i

print max_ans

Submission status: Wrong Answer

Solution code:
import sys
len_line = int(sys.stdin.readline().strip())
min_ans = int(sys.stdin.readline().strip())

max_ans = float("-inf")
for item in sys.stdin.readlines()[:-1]:
    i = int(item.strip())
    if i - min_ans > max_ans:
        max_ans = i - min_ans
    if i < min_ans:
        min_ans = i

print max_ans

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
R = list()
max = -1000000000
min = 10000000

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

    if max < R[i] - min:
        max = R[i] - min

    if min > R[i]:
        min = R[i]
print max

Submission status: Wrong Answer

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

for i in range(len(price_list)):
    for j in range(i):
        num_list.append(price_list[i] - price_list[j])
print max(num_list)

Submission status: Wrong Answer

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):
        pro = -999999999
        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: Wrong Answer

Solution code:
a=[]
n=int(input())
i=0
while(n>i):
    b=int(input())
    a.append((i,b))
    i+=1

c=sorted(a,key=lambda x:x[1])
i=0
j=n-1
while(c[i][0]>c[j][0]):
    if(c[i+1][1]-c[i][1]>c[j][1]-c[j-1][1] or i==n-1):
        j-=1
    else:
        i+=1

        
        
print(c[j][1]-c[i][1])

Submission status: Wrong Answer

Solution code:
a=[]
n=int(input())
i=0
while(n>i):
    b=int(input())
    a.append((i,b))
    i+=1

c=sorted(a,key=lambda x:x[1])
i=0
j=n-1
while(c[i][0]>=c[j][0]):
    if(j==0):
        i+=1
        continue
    if(i==n-1):
        j-=1
        continue
    if((c[i+1][1]-c[i][1]>c[j][1]-c[j-1][1]) or i==n-1) :
        j-=1            
    else:
        i+=1
        
print(c[j][1]-c[i][1])

Submission status: Wrong Answer

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

maxv = -200000000
minv = price_list[0]
for i in range(int(t)):
    maxv = max([maxv, price_list[i] - minv])
    minv = min([minv, price_list[i]])
print maxv

Submission status: Wrong Answer

Solution code:
a=[]
n=int(input())
i=0
while(n>i):
    b=int(input())
    a.append((i,b))
    i+=1

c=sorted(a,key=lambda x:x[1])
i=0
j=n-1
while(c[i][0]>=c[j][0]):
    if(j==0 and i==n-1):
        break
    if(j==0):
        i+=1
        continue
    if(i==n-1):
        j-=1
        continue
    if((c[i+1][1]-c[i][1]>c[j][1]-c[j-1][1]) or i==n-1) :
        j-=1            
    else:
        i+=1
        
print(c[j][1]-c[i][1])

Submission status: Wrong Answer

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) == 0:
       maxpro = max(lst) - pre
   else:
       maxpro = max(lst) - min(sub_lst)
   pre = lst[i]
   lst = lst[i+1:]
   c+= 1
print maxpro

Submission status: Wrong Answer

Solution code:
price_list = []
t = raw_input()
for i in range(int(t)):
    price_list.append(int(input()))
maxv = float("-inf")
minv = price_list[0]
for i in range(1, int(t)):
    maxv = max([maxv, price_list[i] - minv])
    print "maxv:", maxv
    minv = min([minv, price_list[i]])
    print "minv:", minv
print "answer: ", maxv

Submission status: Wrong Answer

Solution code:
a=[]
n=int(input())
i=0
while(n>i):
    b=int(input())
    a.append(b)
    i+=1
score=-1000000
mini = a[0]
for i in a[1:]:
    if(i-mini>score):
        score = i-mini
    if(mini>i):
        mini=i
    

print(score)

Submission status: Wrong Answer

Solution code:
n = int(input())
price = []
max_pro = -999999999

while(n>0):
    x = int(input())
    price.append(x)
    n -= 1
min = price[0]
max_pro = -999999999
for i in range(1,n):
    pro = price[i]-min
    if(max_pro < pro):
        max_pro = pro
    if(min > price[i]):
        min = price[i]
print ("{0}".format(max_pro))

Submission status: Wrong Answer

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

price = []
max_pro = -200000

while(n>0):
    x = int(input())
    price.append(x)
    n -= 1
min = price[0]
for i in range(1,num):
    pro = price[i]-min

    if(max_pro < pro):
        max_pro = pro
    if(min > price[i]):
        min = price[i]
print ("{0}".format(max_pro))

Submission status: Wrong Answer

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

price_list = []

x = input()
x = int(x)

price_list.append(x)

max_profit_candidate = x - 10**9

for i in range(n - 1):
    x = input()
    x = int(x)
    diff = x - min(price_list)
    if diff > max_profit_candidate:
        max_profit_candidate = diff

print(max_profit_candidate)

Submission status: Wrong Answer

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

price_list = []

x = input()
x = int(x)

price_list.append(x)

max_profit_candidate = x - 10**9

for i in range(n - 1):
    x = input()
    x = int(x)
    diff = x - min(price_list)
    if diff > max_profit_candidate:
        max_profit_candidate = diff
    price_list.append(x)

print(max_profit_candidate)

Submission status: Wrong Answer

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

for j in range(1, N - 1):
    for i in range(0, j - 1):
        maxv = max(maxv, R[j] - R[i])

print(maxv)

Submission status: Wrong Answer

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

for j in list(range(1, N - 1)):
    for i in list(range(0, j - 1)):
        maxv = max(maxv, R[j] - R[i])

print(maxv)

Submission status: Wrong Answer

Solution code:
N = int(input())
R = [int(input()) for i in list(range(N))]
maxv = -1000000000
minr = R[0]

for i in list(range(N)):
    maxv = max(maxv, R[i] - minr)
    minr = min(minr, R[i])

print(maxv)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# input
n = int(input())
R = []
for i in range(n):
    R.append(int(input()))

# calc
maximum = -10**6
for i in range(n):
    for j in range(i+1, n):
        if R[j] - R[i] > maximum:
            maximum = R[j] - R[i]

# output
print(maximum)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§??????

# input & calc
n = int(input())
max_diff = -10**9
minv = 10**9
for i in range(n):
    r = int(input())
    max_diff = max(max_diff, r - minv)
    minv = min(minv, r)

# output
print(max_diff)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# ?§£??¬??????????????????????????¨????????¨??¬??¬????????§??????

# input & calc
n = int(input())
max_diff = -10**9
minv = 10**9+1
for i in range(n):
    r = int(input())
    max_diff = max(max_diff, r - minv)
    minv = min(minv, r)

# output
print(max_diff)

Submission status: Wrong Answer

Solution code:
def main():
	n=input()
	List_1=[]
	max=-200000
	for i in range(n):
		List_1.append(input())
		for j in range(i-1,-1,-1):
				if max<List_1[i]-List_1[j]:
					max=List_1[i]-List_1[j]
	print(max)

if __name__=='__main__':
	main()

Submission status: Wrong Answer

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
  # print "i = " + str(i)
  max_num = max(num_list[i:])
  tmp = max_num - num_list[i]
  if tmp > ans:
    ans = tmp

print ans

Submission status: Wrong Answer

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

ans = max(num_list[1:]) - num_list[0]
chk = num_list[0]

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

print ans

Submission status: Wrong Answer

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

ans = max(num_list[1:]) - num_list[0]
chk = num_list[0]

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

print ans

Submission status: Wrong Answer

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

ans = max(num_list[1:]) - num_list[0]
chk = num_list[0]
print "ans=%d, chk=%d" % (ans, chk)

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

print ans

Submission status: Wrong Answer

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

minv = num_list[0]
maxv = -1000000000

for i in xrange(1, n - 1):
  tmp = num_list[i] - minv
  maxv = tmp if tmp > maxv else maxv
  minv = num_list[i] if minv > num_list[i] else minv

print maxv

Submission status: Wrong Answer

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

min_v = 100000000000000
max_profit = -1
for i in range(n):
    if r[i] < min_v:
        min_v = r[i]
    elif max_profit < r[i] - min_v:
        max_profit = r[i]-min_v

print max_profit

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(input_line)
maxv = input_line[1] - input_line[0]
minv = input_line[0]
for j in range(1, N):
    maxv = max(maxv, input_line[j] - minv)
    minv = min(minv, input_line[j])
print(maxv)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n = input()
R = []
for i in range(0, n-1):
   R.append(int(raw_input()))

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

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

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
DifMax = -99

R = [int(raw_input())]
for i in range(1, n):
  R.append(int(raw_input()))
  for j in range(0, i):
      if R[i] - R[j] > DifMax:
        DifMax = R[i] - R[j]

print(max)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
DifMax = -99

R = [int(raw_input())]
for i in range(1, n):
  RMin = min(R)
  R.append(int(raw_input()))
  if DifMax < R[i] - RMin:
    DifMax = R[i] - RMin

print(max)

Submission status: Wrong Answer

Solution code:
max = 0
i = 0
j = 0
k = 0
n_max = 3

price = [3, 4, 5]
    
for i in range(n_max):
    for j in range(k, n_max):
        if max <= price[j] - price[i]:
            max = price[j] - price[i]
print max

Submission status: Wrong Answer

Solution code:
max = 0
i = 0
j = 0
k = 0

n_max = int(raw_input())

print max

Submission status: Wrong Answer

Solution code:
max = 0
i = 0
j = 0
k = 0
n_max = 0

n_max = int(raw_input())

print n_max

Submission status: Wrong Answer

Solution code:
max = 0
i = 0
j = 0
k = 0
n_max = 0

n_max = int(raw_input())
price = [1,2,3,4,5,6]
for i in range(6):
    if max <= price[5] - price[i]:
        print max

Submission status: Wrong Answer

Solution code:
max = 0
i = 0
j = 0
k = 0
n_max = 0

n_max = int(raw_input())
price = [1,2,3,4,5,6]
for i in range(6):
    for j in range(6):
        if max <= price[j] - price[i]:
            print max

Submission status: Wrong Answer

Solution code:
max = 0
i = 0
j = 0
k = 0
n_max = 0

n_max = int(raw_input())
price = [0]*n_max
for i in range(n_max):
    price[i] = int(raw_input())
for i in range(n_max):
    for j in range(i, n_max):
        if max <= (price[j] - price[i]):
            max = price[j] - price[i]
print max

Submission status: Wrong Answer

Solution code:
max = -19998
i = 0
j = 0
k = 0
n_max = 0

n_max = int(raw_input())
price = [0]*n_max
for i in range(n_max):
    price[i] = int(raw_input())
for i in range(n_max):
    for j in range(i, n_max):
        if max <= (price[j] - price[i]):
            max = price[j] - price[i]
print max

Submission status: Wrong Answer

Solution code:
max = -19998
i = 0
j = 0
n_max = 0

n_max = int(raw_input())
price = [0]*n_max
for i in range(n_max):
    price[i] = int(raw_input())
for i in range(n_max):
    for j in range(i+1, n_max):
        if max <= (price[j] - price[i]):
            max = price[j] - price[i]
print max

Submission status: Wrong Answer

Solution code:
n = int(input())

min_price = 1e9 + 1
max_diff = -2e9 - 1

for _ in range(n):
    p = int(input())
    max_diff = max(p - min_price, max_diff)
    min_price = min(p, min_price)

print(max_diff)

Submission status: Wrong Answer

Solution code:
dif_max = 1-10**9
i = 0
j = 0
k = 0
l = 0
max = 1
min = 10^9
n_max = 0

n_max = int(raw_input())
price = [0]*n_max
for l in range(n_max):
    price[l] = int(raw_input())
for i in range(n_max):
    for j in range(0, i+1):
        if min >= price[j]:
            min = price[j]
    for k in range(i+1, n_max):
        if max <= price[k]:
            max = price[k]
    if dif_max <= max-min and i != n_max-1:
        dif_max = max-min
    max = 1
    min = 10^9
print dif_max

Submission status: Wrong Answer

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

max = R[1] - R[0]
for i in range(N - 1):
    for j in range(i):
        dif = R[i+1] - R[j]
        if dif > max:
            max = dif

print max

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
max = 0
min = 0
R = []
for i in range(N):
    R.append(int(raw_input()))

min = R[0]
max = R[1]
dif = R[1] - R[0]
for i in range(N - 1):
    if R[i+1] > max:
        max = R[i+1]
        dif = max - min
    if R[i] < min:
        min = R[i]
        dif = max - min

print dif

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
max = 0
min = 0
R = []
for i in range(N):
    R.append(int(raw_input()))

min = R[0]
max = R[1]
dif = R[1] - R[0]
for i in range(N - 1):
    if R[i+1] > max:
        max = R[i+1]
        dif = max - min
    if R[i] < min:
        min = R[i]
        if dif > R[i+1] - min:
            dif = R[i+1] - min

print dif

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
max = 0
min = 0
R = []
for i in range(N):
    R.append(int(raw_input()))

min = R[0]
max = R[1]
dif = R[1] - R[0]
for i in range(N - 1):
    if R[i+1] > max:
        max = R[i+1]
        dif = max - min
    if R[i] < min:
        min = R[i]
        if R[i+1] - min > dif:
            dif = R[i+1] - min

print dif

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
min = int(raw_input())
max = int(raw_input())
dif = max - min
for i in range(N - 2):
    R = int(raw_input())
    if R - min > dif:
        dif = R - min
    if R < min:
        min = R

print dif

Submission status: Wrong Answer

Solution code:
dif_max = 1-10**9
max = 0
min = 0
temp = 0
n_max = 0
n_max = int(raw_input())
frag = [0]*n_max
min_frag = 0
max_frag = 0
count = 0

price = [0]*n_max
for i in range(0, n_max):
  price[i] = int(raw_input())
    
for i in range(0, n_max-1):
  if price[i] <= price[i+1]:
    frag[i] = 1
    count += 1
  else:
    frag[i] = 0
for i in range(0, n_max-1):
  if count != 0:
    if frag[i] == 1 and min_frag == 0:
      min = price[i]
      min_frag = 1
    elif (frag[i] == 0 and min_frag != 0) or i == n_max-2:
      max = price[i]
      max_frag = 1
    if dif_max <= max - min and max_frag == 1 and min_frag == 1:
      dif_max = max - min
      min_frag = 0
      max_frag = 0
print dif_max

Submission status: Wrong Answer

Solution code:
n = input()
n_max = -10**9
n_min = input()

for i in range(0, n-1):
 R = input()
 if R <= n_min:
  n_min = R
 if n_max <= R - n_min:
  n_max = R - n_min
 
print n_max

Submission status: Wrong Answer

Solution code:
n = input()
n_max = -10**9
n_min = input()

for i in range(0, n-1):
 R = input()
 if R < n_min:
  n_min = R
 if n_max < R - n_min:
  n_max = R - n_min
 
print n_max

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
minv = 10**9
maxv = -1*10**9
  
for j in range(n-1):
  nums = int(raw_input())  
  diff = nums - minv
  if maxv < diff:
    maxv = diff
  if nums < minv:
    minv = nums
  
print maxv

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
max = -10^9
min = 10^9
for i in range(n-1):
 x = int(raw_input())
 if max<x:
  max=x
 if min>x:
  min=x
ans=max-min
print ans

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
max = -10^9
min = 10^9
for i in range(n-1):
 x = int(raw_input())
 if max<x:
  max=x
  if min>x:
   min=x
   ans=max-min
print ans

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
max = -10^9
min = 10^9
for i in range(n-1):
 x = int(raw_input())
 if max<x:
  max=x
 if min>x:
  min=x
 ans =max-min
print ans

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
max = -10^9
min = 10^9
ans = -10^9
for i in range(n-1):
 x = int(raw_input())
 if max<x:
  max=x
 if min>x:
  min=x
 if ans < (max-min):
  ans =max-min
print ans

Submission status: Wrong Answer

Solution code:
n =int(raw_input())
max= -10^9
min= 10^9

for i in range(0,n-1):
 x=int(raw_input())
 if min>x:
  min=x
 if max<(x -min):
  max=x-min
print max

Submission status: Wrong Answer

Solution code:
n =int(raw_input())
max= -10^9
min= 10^9

for i in range(0,n-1):
 x=int(raw_input())
 if max<(x -min):
  max=x-min
 if min>x:
  min=x

print max

Submission status: Wrong Answer

Solution code:
n =int(raw_input())
max= -10^9
min= 10^9

for i in range(0,n):
 x=int(raw_input())
 if max<(x -min):
  max=x-min
 if min>x:
  min=x

print max

Submission status: Wrong Answer

Solution code:
n =int(raw_input())
max= -10^9
min= 10^9

for i in range(0,n):
 x=int(raw_input())
 if min>x:
  min=x
 if max<(x -min):
  max=x-min
print max

Submission status: Wrong Answer

Solution code:
n =int(raw_input())
max= -10^9
x1=int(raw_input())
for i in range(n-1):
 x=int(raw_input())
 if min>x:
  min=x
 if max<(x -min):
  max=x-min
print max

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
max = -10^9
x1 = input() 
min = x1

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
DifMax = -99

R = [int(input())]
for i in range(1, n):
  RMin = min(R)
  R.append(int(input()))
  if DifMax < R[i] - RMin:
    DifMax = R[i] - RMin

print(DifMax)

Submission status: Wrong Answer

Solution code:
n = int( raw_input() )

max = 0
ans = -10 ** 10


for i in xrange(n):
  x = int( raw_input() )
  if max - x > ans:
    ans = max - x
  if x > max:
    max = x

print ans

Submission status: Wrong Answer

Solution code:
#http://qiita.com/lethe2211/items/6cbade2bc547649bc040
n = input()

R = []
for i in range(n):
    R.append(input())
gain_list = []
for i in range(n):
    gain_list.append(0)

start_point = 0
peak = 0

while (start_point < n):
    for i in range(start_point, n):
         diff = R[i] - R[start_point]
         if (diff >= gain_list[start_point]):
             gain_list[start_point] = diff
             peak = i
    for i in range(start_point, peak):
        gain_list[i] = R[peak] - R[i]
    start_point = peak + 1
print max(gain_list)

Submission status: Wrong Answer

Solution code:
#http://qiita.com/lethe2211/items/6cbade2bc547649bc040
n = input()

R = []
for i in range(n):
    R.append(input())
gain_list = []
for i in range(n):
    gain_list.append(-1)

start_point = 0
peak = 0

while (start_point < n):
    for i in range(start_point, n):
         diff = R[i] - R[start_point]
         if (diff >= gain_list[start_point]):
             gain_list[start_point] = diff
             peak = i
    for i in range(start_point, peak):
        gain_list[i] = R[peak] - R[i]
    start_point = peak + 1
print max(gain_list)

Submission status: Wrong Answer

Solution code:
num = raw_input()
max = 1 - 1000000000
for i in range (len (num)):
    for j in range (len (num)-1):
        if (max > (num[i] - num[j])):
            max = num[i] - num[j]
print max

Submission status: Wrong Answer

Solution code:
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0
for i in xrange(n):
 m[i] = input()


for i in xrange(n-1):
 max[i] = m[i+1] 
 kijun[i] = m[i]
 for j in xrange(i+1,n): 
  if max[i] < m[j]:
      max[i] = m[j]
 rieki[i] = max[i] - kijun[i]
 print rieki[i]
max_rieki = rieki[0]
for i in xrange(1,n):
  if rieki[i] > max_rieki:
   max_rieki = rieki[i]

print max_rieki

Submission status: Wrong Answer

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

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

print max

Submission status: Wrong Answer

Solution code:
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0
for i in xrange(n):
 m[i] = input()
 
 
for i in xrange(n-1):
 max[i] = m[i+1] 
 kijun[i] = m[i]
 for j in xrange(i+1,n): 
  if max[i] < m[j]:
      max[i] = m[j]
 rieki[i] = max[i] - kijun[i]
 print rieki[i]
max_rieki = rieki[0]
for i in xrange(1,n):
  if rieki[i] > max_rieki:
   max_rieki = rieki[i]
 
print max_rieki

Submission status: Wrong Answer

Solution code:
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0
for i in xrange(n):
 m[i] = input()
 
 
for i in xrange(n-1):
 max[i] = m[i+1] 
 kijun[i] = m[i]
 for j in xrange(i+1,n): 
  if max[i] < m[j]:
      max[i] = m[j]
 rieki[i] = max[i] - kijun[i]
max_rieki = rieki[0]
for i in xrange(1,n):
  if rieki[i] > max_rieki:
   max_rieki = rieki[i]
 
print max_rieki

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = input()

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

Submission status: Wrong Answer

Solution code:
n = input()

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

Submission status: Wrong Answer

Solution code:
n = input()

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

Submission status: Wrong Answer

Solution code:
n = input()

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

Submission status: Wrong Answer

Solution code:
n = input()

R = [input() for i in range(n)]
  
max = R[2] - R[1]
min = R[1]
  
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: Wrong Answer

Solution code:
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0



for i in xrange(n):
 m[i] = input()

min_rieki = m[0]
for j in xrange(1,n-1): 
  if max_rieki < m[j] - min_rieki:
     max_rieki = m[j] - min_rieki
  if min_rieki > m[j]:
     min_rieki = m[j]

print max_rieki

Submission status: Wrong Answer

Solution code:
n = input()
m = [0] * n
max_rieki = -100000000



for i in xrange(n):
 m[i] = input()

min_rieki = m[0]
for i in xrange(1,n): 
  if max_rieki < m[i] - min_rieki:
     max_rieki = m[i] - min_rieki
  if min_rieki > m[i]:
     min_rieki = m[i]

  print max_rieki

Submission status: Wrong Answer

Solution code:
n = input()
m = [0] * n
max_rieki = -100000000



for i in xrange(n):
 m[i] = input()

min_rieki = m[0]
for i in xrange(1,n): 
  if max_rieki < m[i] - min_rieki:
     max_rieki = m[i] - min_rieki
  if min_rieki > m[i]:
     min_rieki = m[i]

print max_rieki

Submission status: Wrong Answer

Solution code:
n = input()
m = [0] * n
max_rieki = -1000000000



for i in xrange(n):
 m[i] = input()

min_rieki = m[0]
for i in xrange(1,n): 
  if max_rieki < m[i] - min_rieki:
     max_rieki = m[i] - min_rieki
  if min_rieki > m[i]:
     min_rieki = m[i]

  print max_rieki

Submission status: Wrong Answer

Solution code:
n = input()

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

Submission status: Wrong Answer

Solution code:
n = input()
a = [input() for i in range(n)]
i = 0
j = 1
max = a[j] - a[i]

while n-1 > i:
  j = i+1
  while n > j:
    if max < a[j] - a[i]:
      max = a[j] - a[j]
    j += 1
  i += 1

print max