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: Time Limit Exceeded

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]:
    if r[i] < r[i+1] or r[max_i] - r[min_i] < 0:
        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(r[max_i] - r[min_i])

Submission status: Time Limit Exceeded

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

min = r[N-2]
max = r[N-1]

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

print(max - min)

Submission status: Time Limit Exceeded

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]:
    if (r[i] - r[i+1]) * r[max_i] - r[min_i] < 0:
        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(r[max_i] - r[min_i])

Submission status: Time Limit Exceeded

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]:
    if r[i] < r[i+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
    if r[max_i] - r[min_i] < 0:
        if r[i+1] - r[i] > r[max_i] - r[min_i]:
            max_i = i+1
            min_i = i

                
print(r[max_i] - r[min_i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = [int(input()) for i in range(n)]
ans = -10000000000

for j in range(n-1, 0, -1):
    for i in range(j-1,-1, -1):
        ans = max(ans, (nums[j] - nums[i]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = [int(input()) for i in range(n)]
ans = -10000000000

for i in range(1, n):
    temp_max = nums[i:n+1]
    temp_min = nums[0:i]
    ans = max(ans, max(temp_max) - min(temp_min))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
_temp = []
my_max = []

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

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: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
a=input()
r=[]
for i in range(a):
    k=input()
    r.append(k)
minn=-10**9
for i in range(len(r)):
    for j in range(i+1,len(r)):
        k=r[j]-r[i]
        if k>minn:
            minn=k
print minn

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
nums = []

for i in range(N):
    nums.append(int(raw_input()))

m = -100000000000000000

for i in range(len(nums)):
    for j in range(0, i):
        if m < nums[i] - nums[j]:
            m = nums[i] - nums[j]

print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
nums = []

for i in range(N):
    nums.append(int(raw_input()))

m = -1000000000000000000000000
for i in range(1, len(nums)):
    value = nums[i] - min(nums[:i])
    if m <= value:
        m = value

print(m)

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

profit = nums[1] - nums[0]
for a in range(N):
     for b in range(a):
          if (nums[a] - nums[b]) > profit:
               profit = nums[a] - nums[b]

print profit

Submission status: Time Limit Exceeded

Solution code:
N = input()
R = [int(raw_input()) for _ in xrange(N)]
ans = float('-inf')
for i in xrange(N):
    for j in xrange(i+1, N):
        ans = max(ans, R[j]-R[i])
print ans

Submission status: Time Limit Exceeded

Solution code:


def solve():
    n = int(raw_input())
    R = []

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

    #for i in xrange(n):
    #    print R[i]

    max_profit = -1000000000
    for i in xrange(n):
        for j in xrange(i + 1, n):
            if R[j] - R[i] > max_profit:
                max_profit = R[j] - R[i]


    print max_profit


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import sys

def solve():
    n = int(raw_input())
    R = []

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

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    for i in xrange(n):
        for j in xrange(i + 1, n):
            if R[j] - R[i] > max_profit:
                max_profit = R[j] - R[i]


    print max_profit


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
line = [int(input()) for i in range(n)]
max_n = None
for i in range(n-1):
    diff = max(line[i+1:])-line[i]
    if max_n==None or max_n<diff: max_n = diff
print(max_n)

Submission status: Time Limit Exceeded

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

diff = -float('inf')
for i in range(n):
  for j in range(i + 1, n):
    diff = max(diff, p[j] - p[i])

print(diff)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
num_list = [int(input()) for x in range(num)]
max_difference = float("-inf")

for i in range(num):
    for j in range(i+1, num):
        difference = num_list[j] - num_list[i]
        if max_difference < difference:
            max_difference = difference

print(max_difference)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding : utf-8 -*-

def maximum_profit(price_list):
    max = price_list[1] - price_list[0]
    for x in range(len(price_list)-1):
        for y in range(x+1, len(price_list)):
            if max < price_list[y] - price_list[x]:
                max = price_list[y] - price_list[x]
    return max

input_num = int(input())
price_list = list()
for i in range(input_num):
    input_price = int(input())
    price_list.append(input_price)
print(maximum_profit(price_list))

Submission status: Time Limit Exceeded

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

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

print(candidate[0])

Submission status: Time Limit Exceeded

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

candidate = [-10**10]
for i, v in enumerate(stack):
    for j in stack[:i]:
        candidate.append(v - j)
    candidate = [max(candidate)]

print(candidate[0])

Submission status: Time Limit Exceeded

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

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

print(candidate[0])

Submission status: Time Limit Exceeded

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

candidate = [-float('inf')]
for i in range(1, len(stack) // 2 + 1):
    for r1, r2 in zip(stack[::1], stack[i::1]):
        candidate.append(r2 - r1)
    for r1, r2 in zip(stack[::1], stack[len(stack) - i::1]):
        candidate.append(r2 - r1)
    candidate = [max(candidate)]

print(candidate[0])

Submission status: Time Limit Exceeded

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

candidate = [-float('inf')]
for i in range(1, len(stack) // 2 + 1):
    for r1, r2 in zip(stack[::1], stack[i::1]):
        if r2 - r1 > candidate[0]:
            candidate.append(r2 - r1)
    for r1, r2 in zip(stack[::1], stack[len(stack) - i::1]):
        if r2 - r1 > candidate[0]:
            candidate.append(r2 - r1)
    candidate = [max(candidate)]

print(candidate[0])

Submission status: Time Limit Exceeded

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

candidate = [-float('inf')]
for i in range(1, length // 2 + 1):
    for r1, r2 in zip(stack[::1], stack[i::1]):
        if r2 - r1 > candidate[0]:
            candidate.append(r2 - r1)
    if i - length != i:
        for r1, r2 in zip(stack[::1], stack[length - i::1]):
            if r2 - r1 > candidate[0]:
                candidate.append(r2 - r1)
    candidate = [max(candidate)]

print(candidate[0])

Submission status: Time Limit Exceeded

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

max_value = (-1)*(10 ** 9)
for j in range(1,len(r)):
    for i in range(0,j):
        max_value = max(max_value, r[j]-r[i])
print(max_value)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-


def maximum_profit(profits):
    max_v = profits[1] - profits[0]

    for j in range(1, len(profits)):
        for i in range(0, j):
            max_v = max(profits[j] - profits[i], max_v)

    print(max_v)


def to_int(v):
    return int(v)


if __name__ == '__main__':
    l = to_int(input())
    profits = [to_int(input()) for i in range(l)]

    maximum_profit(profits)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
R = [0]*n

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

maximum_profit = -10**9
for i in range(1, n):
    profit = max(R[i:n]) - min(R[0:i])
    maximum_profit = profit if profit > maximum_profit else maximum_profit

print(maximum_profit)

Submission status: Time Limit Exceeded

Solution code:
R = [(int(input()), i) for i in range(int(input()))]
print(max([max(y-x for y, j in R[i+1:]) for x, i in R[:-1]]))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
m = None
for j,r_j in enumerate(rv):
    for r_i in r[:-(j+1)]:
        t = r_j - r_i
        if m == None or t > m:
            m = t
print(m)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
m = None
for j,r_j in enumerate(rv):
    r_i = min(r[:-(j+1)])
    t = r_j - r_i
    if m == None or t > m:
        m = t
print(m)

Submission status: Time Limit Exceeded

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(profit)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

R = []

for i in range(0,n):
    R.insert(i,int(input()))

MAX = R[1] - R[0]
for r in range(2,n):
    if(MAX < R[r] - min(R[:r])):
        MAX = R[r] - min(R[:r])
print(MAX)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

R = []

for i in range(0,n):
    R.insert(i,int(input()))

MAX = R[1] - R[0]
for r in range(2,n):
    o = R[r] - min(R[:r])
    if(MAX < o):
        MAX = o
print(MAX)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

RMax = 0
R = []


for i in range(N):
	r = int(input())
	if i == 1:
		RMax = r - R[0]
	if i > 0:
		rmi = min(R)
		rdif = (r - rmi)
		if rdif >= RMax:
			RMax = rdif
	R.append(r)

print(RMax)

Submission status: Time Limit Exceeded

Solution code:
#coding: UTF-8
N=int(input())
p=[int(input()) for i in range(0,N)]
out=p[1]-p[0]
for i in range(0,N-1):
    buy=p[i]
    sell=p[i+1]
    for j in range(i+2,N):
        if p[j]>sell:
            sell=p[j]
    if sell-buy>out:
        out=sell-buy
print(out)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
num = int(raw_input())
numbers = []
counter = 0
while counter < num:
    numbers.append(int(raw_input()))
    counter += 1

maximum = None

for index, num in enumerate(numbers[:-1]):
    max_diff = max(numbers[index+1:]) - num
    if max_diff > maximum:
        maximum = max_diff

print maximum

Submission status: Time Limit Exceeded

Solution code:
data_num = int(input())
price = list([0 for i in range(data_num)])
cnt = 0
deff_price = -999999999
for i in range(data_num):
    price[i] = int(input())

for i in range(data_num):
    for j in range(i+1,data_num):
        if price[j]-price[i]>deff_price:
            deff_price = price[j]-price[i]

print(str(deff_price))

Submission status: Time Limit Exceeded

Solution code:
data_num = int(input())
price = list([0 for i in range(data_num)])
cnt = 0
deff_price = -999999999
tmp_price = 0
for i in range(data_num):
    price[i] = int(input())

for i in range(data_num-1):
    tmp_price = max(price[i+1:])-price[i]
    if tmp_price>deff_price:
            deff_price = tmp_price

print(str(deff_price))

Submission status: Time Limit Exceeded

Solution code:
data_num = int(input())
price = list([int(input()) for i in range(data_num)])
cnt = 0
deff_price = -999999999
tmp_price = 0

for i in range(data_num-1):
    tmp_price = max(price[i+1:])-price[i]
    if tmp_price>deff_price:
            deff_price = tmp_price

print(str(deff_price))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !
prof = 0
d = int(input())
li =[int(input()) for i in range(d)]
max =li[1]-li[0]

while len(li)>1:
    for i in range(len(li)):
        if li[i]-li[0]>max and i!=0:
            max= li[i]-li[0]
    li=li[1:]
    
print(max)

Submission status: Time Limit Exceeded

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

res = nums[1] - nums[0]
for i in range(line):
    for j in range(i+1, line):
        dif = nums[j] - nums[i]
        res = dif if dif > res else res

print(res)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
 
inf = 10**9 + 1

def solve():
    n = int(stdin.readline())
    R = [int(stdin.readline()) for i in range(n)]

    ans = max_profit2(n, R)

    print(ans)

def max_profit(n, R):
    max_d = -inf
    min_v = R[0]

    for i in range(1, n):
        max_d = max(max_d, R[i] - min_v)
        min_v = min(min_v, R[i])

    return max_d

def max_profit2(n, R):
    max_dif = -inf

    for left in range(n):
        for j in range(left + 1, n):
            max_dif = max(max_dif, R[j] - R[left])

    return max_dif
    
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: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math


N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))

max_diff = lst[1] - lst[0]

for i in range(N):
    for j in range(i + 1, N):
        diff = lst[j] - lst[i]
        if diff > max_diff:
            max_diff = diff

print(max_diff)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
r = [int(input()) for i in range(n)]
x = max([max([r[j]-r[i] for j in range(i+1, n)]) for i in range(n-1)])
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
R = [0 for _ in range(n)]
for i in range(n):
    R[i] = int(input())

m = -float('inf')
for i in range(n-1):
    for j in range(i+1, n):
        if R[j]-R[i] > m:
            m = R[j]-R[i]

print(m)

Submission status: Time Limit Exceeded

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

R.append(int(input()))
for i in range(1, n):
    r = int(input())
    P.append(r-min(R))
    R.append(r)

P.sort()
print(P[-1])

Submission status: Time Limit Exceeded

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

p = float('-inf')
R.append(int(input()))
for i in range(1, n):
    r = int(input())
    if r-min(R) > p:
        p = r-min(R)
    R.append(r)

print(p)

Submission status: Time Limit Exceeded

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

p = float('-inf')
R.append(int(input()))
for i in range(1, n):
    r = int(input())
    m = min(R)
    if r-m > p:
        p = r-m
    R.append(r)

print(p)

Submission status: Time Limit Exceeded

Solution code:
#-*- coding:utf-8 -*-

def main():
    n , data = input_data()
    vMax = float('-inf')

    i = 1
    for i, Ri in enumerate(data):
        for Rj in data[i+1:]:
            n = Rj - Ri
            if vMax < n:
                vMax = n
    print(vMax)

def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#-*- coding:utf-8 -*-

def main():
    n , data = input_data()
    vMax = float('-inf')

    i = 1
    minIndex = min(enumerate(data) , key = lambda x:x[1])[0]
    for i, Ri in enumerate(data):
        if data[i+1:]:
            n = max(data[i+1:]) - Ri
            if vMax < n:
                vMax = n

        if i == minIndex: # Ri???????°???????????????¨????????????????¨??????????
            break

    print(vMax)

def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#-*- coding:utf-8 -*-

def main():
    n , data = input_data()
    vMax = float('-inf')

    i = 1
    minIndex = min(enumerate(data) , key = lambda x:x[1])[0]
    maxIndex = max(enumerate(data) , key = lambda x:x[1])[0]
    for i, Ri in enumerate(data):
        if data[i+1:]:
            if maxIndex < i + 1:
                maxIndex, Rj= max(enumerate(data[i+1:]) , key = lambda x:x[1])
                maxIndex += i + 1
            else:
                Rj = data[maxIndex]

            n = Rj - Ri
            if vMax < n:
                vMax = n

        if i == minIndex: # Ri???????°???????????????¨????????????????¨??????????
            break

    print(vMax)

def input_data():
    n = int(input())
    lst = [int(input()) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
Rt = [input() for i in range(n)]
benef = int(Rt[1]) - int(Rt[0])

for i in range(n):
    for j in range(i+1,n):
      rate = int(Rt[j])-int(Rt[i])
      if rate > benef:
       benef = rate

print(benef)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
r = [None] * n
min = 10**10
max = -10**10
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: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 16 18:45:04 2017

@author: syaga
"""

if __name__ == "__main__":
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    max = a[1] - a[0]
    for i in range(1, len(a)):
        for j in range(0, i):
            diff = a[i] - a[j]
            if diff > max:
                max = diff
    print(max)

Submission status: Time Limit Exceeded

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

R_max = -10**9
for i in range(n-1):
    for j in range(i+1, n):
        if R[j] - R[i] > R_max:
            R_max = R[j] - R[i] 
print(R_max)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num = [0 for i in range(n)]
for i in range(n):
    num[i] = int(input())
m = -float('inf')
res = m
for i in range(n):
    for j in range(i+1,n):
        if m < num[j] - num[i]:
            m = num[j] - num[i]
        res = max(m,res)
print(res)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????§?????????
FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????
????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???
(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????

???????????¨????????????????????? t ?????????????????? Rt (t=0,1,2,,,n???1)???
??\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i ??¨??????) ????????§??????
?±??????????????????????
"""
import math

# ?????????
n = int(input().strip())
a = []
for i in range(n):
    a.append(int(input().strip()))
cnt = -1000000000
for j in range(1,n):
    for i in range(0,j):
        x = a[j] - a[i]
        if cnt < x:
            cnt = x
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(cnt):
    v.append(int(input()))

len = len(v)
dif_max = -1000000000

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

print(dif_max)

Submission status: Time Limit Exceeded

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

m = L[1]-L[0]

for x in range(n-1):

    for i in range(x,n-1):

        if m <= L[i+1]-L[x]:
            m = L[i+1]-L[x]
        else:
            pass

print (m)

Submission status: Time Limit Exceeded

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

m = L[1]-L[0]

for x in range(n-1):

    for i in range(x,n-1):
        m = max([m,L[i+1]-L[x]])

print (m)

Submission status: Time Limit Exceeded

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

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

print max

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
z=[]
for i in range(n):
    z+=[int(input())]
a=0
zz=[]
zzz=[]
while True:
    if a==len(z):
        break
    j=a+1
    for i in z[j:]:
        
        zz+=[i-z[a]]
        
    zzz+=[max(zz)]
    a+=1
print(max(zzz))

Submission status: Time Limit Exceeded

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

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

l = []
for i, p in enumerate(pl[:-1]):
    l.append(max(pl[i+1:])-p)

m = max(l)
print(m)

Submission status: Time Limit Exceeded

Solution code:
ans = -float('inf')
n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        ans = max(a[j]-a[i], ans)
print(ans)

Submission status: Time Limit Exceeded

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(max(sub))

Submission status: Time Limit Exceeded

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))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
R = []
for i in range(N):
    R.append(int(input()))
ans = R[1] - R[0]
for i in range(N):
    for j in range(i+1,N):
        delta =  R[j] - R[i]
        ans  = max(ans,delta)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
R = []
for i in range(N):
    R.append(int(input()))
ans = R[1] - R[0]
for i in range(N-1):
    S = R[i+1:]
    delta = max(S) - R[i]
    ans = max(ans , delta)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
r=[]
m=-10**9
for i in range(n):
    r.append(int(input()))
for i in range(n):
    for j in range(i+1,n):
         d=r[j]-r[i]
         if d > m:
             m=d
print(m)

Submission status: Time Limit Exceeded

Solution code:
def main() :
    n = int(input())
    nums = []
    for i in range(n) :
        x = int(input())
        nums.append(x)

    max = float("-inf")
    for i in range(n) :
        for j in range(i):
            if (nums[i] - nums[j]) > max :
                max = nums[i] - nums[j]

    print(max)



if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
l=[]
for i in range(x):
    l.append(int(input()))
max_ = -99999999999999999999999
for i, v1 in enumerate(l):
    for j, v2 in enumerate(l):
        if j > i:
            if v2-v1 > max_:
                max_ = v2-v1
print(max_)

Submission status: Time Limit Exceeded

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



'''
n = 6
t=[4,1,5,7,5,4]
'''



maxv = t[1] - t[0]
for j in range(1,n):
    for i in range(j):
        maxv = max([maxv,t[j] - t[i]])
print(maxv)

Submission status: Time Limit Exceeded

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

mprof = R[1] - R[0]
for i in range(1, len(R)):
    for k in range(i):
        if mprof < (R[i] - R[k]):
            mprof = (R[i] - R[k])

print(mprof)

Submission status: Time Limit Exceeded

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

candidate = -1000000000 
for i in range(N):
    for j in range(i+1, N):
        if List[j]-List[i] > candidate:
            candidate = List[j]-List[i]

print(candidate)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
r=[int(input())for _ in range(n)]
print(max([max(r[i+1:])-r[i]for i in range(n-1)]))

Submission status: Time Limit Exceeded

Solution code:
import sys
n=int(input())
r=list(map(int,sys.stdin.read().split()))
print(max([max(r[i+1:])-r[i]for i in range(n-1)]))

Submission status: Time Limit Exceeded

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

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

# Naive Algorithm
max_gap = R[1] - R[0]
for i in range(n):
    for j in range(i+1, n):
        if R[j]-R[i] > max_gap:
            max_gap = R[j]-R[i]

print(max_gap)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
	n = int(input())
	lists = list()

	for i in range(n):
		a = int(input())
		lists.append(a)
	
	m = None

	for i in range(n - 1):
		for j in range(i + 1, n):
			m = lists[j] - lists[i] if m is None or m < lists[j] - lists[i] else m
	print(m)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
	n = int(input())
	lists = list()

	for i in range(n):
		a = int(input())
		lists.append(a)
	
	m = None

	for i in range(n - 1):
		j = max(lists[i + 1:n])
		m = j - lists[i] if m is None or m < j - lists[i] else m
	print(m)

Submission status: Time Limit Exceeded

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

a=-999999999
for i in range(n):
	for j in range(i+1,n):
		if a<Rt[j]-Rt[i]:
			a=Rt[j]-Rt[i]
		
print(a)

Submission status: Time Limit Exceeded

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

a=-999999999
for i in range(1,n):
	for j in range(i):
		if a<Rt[i]-Rt[j]:
			a=Rt[i]-Rt[j]
		
print(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = 0
R = list()
while s < N :
    M = int(input())
    R.insert(s, M)
    s = s + 1

answer = R[1] - R[0]
i = 0

while i < len(R) :
    k = i + 1
    while k < len(R) :
        if R[k] - R[i] > answer :
            answer = R[k] -R[i]
        k = k + 1
    i = i + 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list = []

for i in range(N):
    tmp = int(input())
    list.append(tmp)

maxDiff = - 10 ** 9
for i in range(N):
    for j in range(i+1, N):
        tmpDiff = list[j] - list[i]
        if tmpDiff > maxDiff:
            maxDiff = tmpDiff
print(maxDiff)

Submission status: Time Limit Exceeded

Solution code:
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

max = numbers[2] - numbers[1]


for i in range(1, len(numbers) - 1):
	for j in range(i + 1, len(numbers)):
		if numbers[j] - numbers[i] > max :
			max = numbers[j] - numbers[i]
print(max)

Submission status: Time Limit Exceeded

Solution code:
import sys
numbers = []
for line in sys.stdin:
	numbers.append(int(line))

answer = numbers[2] - numbers[1]

count = 1
while count < len(numbers) - 1:
	target = max(numbers[count + 1 : ])
	if target -  numbers[count] > answer :
		answer = target -  numbers[count]
	count += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
# coding: UTF-8
n = int(raw_input())
value_list = []
for i in range(n):
    value_list.append(int(raw_input()))
    if i == 1:
        diff =value_list[1] - value_list[0]
    for j in range(i):
        diff2 = value_list[i] - value_list[j]
        if diff < diff2:
            diff = diff2
print diff