N = gets.to_i P = gets.split.map(&:to_i) rounds = Hash.new P.each.with_index(1) do |x, i| rounds[x] = i end ans = 0 i = N sum = (1..N).sum while i >= 1 score = sum - 2 * rounds[i] ans = score if ans < score sum -= rounds[i] i -= 1 end puts ans