class BinaryIndexTree def initialize(size, init: 0) @values = Array.new(size, init) @size = size end # @param idx [Integer] # @param x [Numeric] def add(idx, x) raise 'Out of range reference' if @size <= idx idx += 1 while idx <= @size @values[idx - 1] += x idx += idx & -idx end end def sum(l, r) _sum(r) - _sum(l) end private def _sum(idx) res = 0 while idx > 0 res += @values[idx - 1] idx -= idx & -idx end res end end N = gets.to_i A = gets.split.map(&:to_i) M = A.max bit = BinaryIndexTree.new(M + 2) ans = 0 A.each do |a| if bit.sum(a + 1, M + 1) > 0 ans += 1 end bit.add(a, 1) end puts ans