
count = gets.to_i
arr = []

count.times do
  arr << gets.to_i
end

ans = []

arr.each_with_index do |val, ind|
  ind += 1
  arr.each_with_index do |val2, ind2|
    ind2 = ind + ind2
    break if arr[ind2].nil?
    ans << arr[ind2] - val
  end
end

p ans.max