n = gets.chomp.to_i
array = gets.chomp.split.map(&:to_i)
count = 0
number_array = Array.new(n, 0)

array.each do |item|
  count += number_array[item-1]
  (1..item).each do |item2|
    number_array[item2-1] += 1
  end
end

puts count