gets
seq = gets.split.map(&:to_i)

count = 0

(seq.size - 1).times do |i|
	(seq.size - 1).downto(i + 1) do |j|
		if seq[j] < seq[j - 1]
			seq[j - 1], seq[j] = seq[j], seq[j - 1]
			count += 1
		end
	end
end

puts seq.join(' ')
p count