
def search_maximum_profit(rs):
    """
        rs: ??´??°?????????
        search max[s | s = rs[j] - rs[i] (j > i)]
        return: s
    """
    l = len(rs)
    if l <= 1:
        return None
    elif l == 2:
        return rs[1] - rs[0]
    else:
        left_profit = search_maximum_profit(rs[:l // 2])
        right_profit = search_maximum_profit(rs[l // 2:])
        left_min = min(rs[:l // 2])
        right_max = max(rs[l // 2:])
        profits = []
        if left_profit != None:
            profits.append(left_profit)
        if right_profit != None:
            profits.append(right_profit)
        profits.append(right_max - left_min)
        return max(profits)

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

print(search_maximum_profit(rs)) def search_maximum_profit(rs):
    """
        rs: ??´??°?????????
        search max[s | s = rs[j] - rs[i] (j > i)]
        return: s
    """
    l = len(rs)
    if l <= 1:
        return None
    elif l == 2:
        return rs[1] - rs[0]
    else:
        left_profit = search_maximum_profit(rs[:l // 2])
        right_profit = search_maximum_profit(rs[l // 2:])
        left_min = min(rs[:l // 2])
        right_max = max(rs[l // 2:])
        profits = []
        if left_profit != None:
            profits.append(left_profit)
        if right_profit != None:
            profits.append(right_profit)
        profits.append(right_max - left_min)
        return max(profits) search_maximum_profit """
        rs: ??´??°?????????
        search max[s | s = rs[j] - rs[i] (j > i)]
        return: s
    """ l = len(rs) l len(rs) len rs if l <= 1:
        return None
    elif l == 2:
        return rs[1] - rs[0]
    else:
        left_profit = search_maximum_profit(rs[:l // 2])
        right_profit = search_maximum_profit(rs[l // 2:])
        left_min = min(rs[:l // 2])
        right_max = max(rs[l // 2:])
        profits = []
        if left_profit != None:
            profits.append(left_profit)
        if right_profit != None:
            profits.append(right_profit)
        profits.append(right_max - left_min)
        return max(profits) l <= 1 l 1 return None None elif l == 2:
        return rs[1] - rs[0]
     l == 2 l 2 return rs[1] - rs[0] rs[1] - rs[0] rs[1] rs 1 rs[0] rs 0 left_profit = search_maximum_profit(rs[:l // 2]) left_profit search_maximum_profit(rs[:l // 2]) search_maximum_profit rs[:l // 2] rs :l // 2 l // 2 l 2 right_profit = search_maximum_profit(rs[l // 2:]) right_profit search_maximum_profit(rs[l // 2:]) search_maximum_profit rs[l // 2:] rs l // 2: l // 2 l 2 left_min = min(rs[:l // 2]) left_min min(rs[:l // 2]) min rs[:l // 2] rs :l // 2 l // 2 l 2 right_max = max(rs[l // 2:]) right_max max(rs[l // 2:]) max rs[l // 2:] rs l // 2: l // 2 l 2 profits = [] profits [] if left_profit != None:
            profits.append(left_profit)
         left_profit != None left_profit None profits.append(left_profit) profits.append profits append left_profit if right_profit != None:
            profits.append(right_profit)
         right_profit != None right_profit None profits.append(right_profit) profits.append profits append right_profit profits.append(right_max - left_min) profits.append profits append right_max - left_min right_max left_min return max(profits) max(profits) max profits rs rs n = int(input()) n int(input()) int input() input rs = [] rs [] for i in range(n):
    rs.append(int(input())) i range(n) range n rs.append(int(input())) rs.append rs append int(input()) int input() input print(search_maximum_profit(rs)) print search_maximum_profit(rs) search_maximum_profit rs def search_maximum_profit(rs):
    """
        rs: ??´??°?????????
        search max[s | s = rs[j] - rs[i] (j > i)]
        return: s
    """
    l = len(rs)
    if l <= 1:
        return None
    elif l == 2:
        return rs[1] - rs[0]
    else:
        left_profit = search_maximum_profit(rs[:l // 2])
        right_profit = search_maximum_profit(rs[l // 2:])
        left_min = min(rs[:l // 2])
        right_max = max(rs[l // 2:])
        profits = []
        if left_profit != None:
            profits.append(left_profit)
        if right_profit != None:
            profits.append(right_profit)
        profits.append(right_max - left_min)
        return max(profits) def search_maximum_profit(rs):
    """
        rs: ??´??°?????????
        search max[s | s = rs[j] - rs[i] (j > i)]
        return: s
    """
    l = len(rs)
    if l <= 1:
        return None
    elif l == 2:
        return rs[1] - rs[0]
    else:
        left_profit = search_maximum_profit(rs[:l // 2])
        right_profit = search_maximum_profit(rs[l // 2:])
        left_min = min(rs[:l // 2])
        right_max = max(rs[l // 2:])
        profits = []
        if left_profit != None:
            profits.append(left_profit)
        if right_profit != None:
            profits.append(right_profit)
        profits.append(right_max - left_min)
        return max(profits) search_maximum_profit n = int(input()) int(input()) n rs = [] [] rs

def search_maximum_profit(rs):
    """
        rs: ??´??°?????????
        search max[s | s = rs[j] - rs[i] (j > i)]
        return: s
    """
    l = len(rs)
    if l <= 1:
        return None
    elif l == 2:
        return rs[1] - rs[0]
    else:
        left_profit = search_maximum_profit(rs[:l // 2])
        right_profit = search_maximum_profit(rs[l // 2:])
        left_min = min(rs[:l // 2])
        right_max = max(rs[l // 2:])
        profits = []
        if left_profit != None:
            profits.append(left_profit)
        if right_profit != None:
            profits.append(right_profit)
        profits.append(right_max - left_min)
        return max(profits)

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

print(search_maximum_profit(rs))