class Array
  def merge_sort
    $cnt = 0
    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
          ret << l.shift
        else
          $cnt += l.size
          ret << r.shift
        end
      end
      ret
    end
    if size > 1
      mid = size / 2
      merge.(self[0...mid].merge_sort, self[mid...size].merge_sort)
    else
      self
    end
  end
end

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