#=== Buble Sort
datas = $stdin.read.split("\n")
n = datas[0].to_i
datas = datas[1].split(' ')
datas.map! do |x|
  x.to_i
end
flag = true
cnt = 0
while flag
  flag = false
  for j in 2..n
    if datas[- j] > datas[- j + 1]
      datas[- j],datas[- j + 1] = datas[- j + 1],datas[- j]
      flag = true
      cnt += 1
    end
  end
end
puts datas.join(' ')
puts cnt


