def binary_search(b,i)
	left = 0
	right = b.length-1
	while left <= right
		mid = ((left + right) / 2).to_i
		
		if b[mid] < i
			left = mid + 1
		elsif b[mid] > i
			right = mid - 1
		end

		if mid == 0 && b[mid] > i
			return 0
		elsif mid == b.length-1 && b[mid] < i
			return b.length
		elsif b[mid] < i && b[mid+1] > i
			return mid + 1
		end
	end
end

def insert_sort(a)
	b = Array.new

	a.each_with_index { |i,idx|
		if idx == 0
			b[0] = i
		elsif idx == 1
			if b[0] < i
				b[1] = i
			else
				$cnt += 1
				b[0,0] = i
			end
		else
			j = binary_search(b,i)
			$cnt += b.length - j
			b[j,0] = i
		end
	}
end

n = gets.to_i
a = gets.split(" ").map(&:to_i)
$cnt = 0

insert_sort(a)

puts $cnt