n = gets.to_i
c = gets.split(" ").map(&:to_i)

d = 0
0.upto(n-1) do |i|
  (n-1).downto(i+1) do |j|
    if c[j] < c[j-1]
      c[j],c[j-1] = c[j-1],c[j]
      d += 1
    end
  end
end

puts c.join(" ")
puts "#{d}"

