class Msort
  attr_reader :arr, :count, :tcount

  def initialize(arr)
    @arr = arr
    @count = 0
    @tcount = 0
  end

  def exec(array=arr)
    if array.length == 1
      array
    else
      mid = array.length / 2 - 1
      merge(exec(array[0..mid]), exec(array[mid+1..-1]))
    end
  end

  def merge(left, right)
    tl = left.shift
    tr = right.shift
    result = []
    loop do
      break if [tl, tr].all?(&:nil?)
      @count += 1
      if tl.nil?
        result << tr
        tr = right.shift
        next
      end
      if tr.nil?
        result << tl
        tl = left.shift
        next
      end
      if tl <= tr
        result << tl
        tl = left.shift
      else
        @tcount += left.length + 1
        result << tr
        tr = right.shift
      end
    end
    result
  end
end

n = gets.to_i
arr = gets.split.map(&:to_i)
m = Msort.new(arr)
m.exec
puts m.tcount
