class Array
  def merge_sort
    merge = -> l, r do
      ret = []
      for i in 0...size do
        case
        when l.empty?
          $cnt += l.size
          ret << r.shift
        when r.empty?
          ret << l.shift
        when l.first > r.first
          $cnt += l.size
          ret << r.shift
        else
          ret << l.shift
        end
      end
      ret
    end
    if size != 1
      mid = size / 2
      l = self[0...mid].merge_sort
      r = self[mid...size].merge_sort
      merge.(l, r)
    else
      self
    end
  end
end


$cnt = 0
gets
gets.split(' ').map(&:to_i).merge_sort
puts $cnt
