class Array
  @@cnt = 0

  def cnt
    c = @@cnt
    @@cnt = 0
    c
  end

  def merge_sort
    if size != 1
      mid = size / 2
      l = self[0...mid].merge_sort
      r = self[mid...size].merge_sort
      merge(l, r)
    end
    self
  end

  private def merge l, r
    i = 0
    b = dup
    size.times do
      case
      when l.empty?
        @@cnt += b.index(r.first) - i
        self[i] = r.shift
      when r.empty?
        self[i] = l.shift
      when r.first < l.first
        @@cnt += b.index(r.first) - i
        self[i] = r.shift
      else
        self[i] = l.shift
      end
      i += 1
    end
    self
  end
end

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