#coding: utf-8
#ALDS1_2A

def pnt(s):
 for i in xrange(len(s)):
  print s[i],
 print

n=int(raw_input())
a=map(int,raw_input().split())

sw=0
flag=True
while flag:
 flag=False
 for j in xrange(n-1,0,-1):
  if a[j]<a[j-1]:
   a[j],a[j-1]=a[j-1],a[j]
   flag=True
   sw+=1

pnt(a)
print sw def pnt(s):
 for i in xrange(len(s)):
  print s[i],
 print pnt for i in xrange(len(s)):
  print s[i],
  i xrange(len(s)) xrange len(s) len s print s[i] s i print s s n=int(raw_input()) n int(raw_input()) int raw_input() raw_input a=map(int,raw_input().split()) a map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split sw=0 sw 0 flag=True flag True while flag:
 flag=False
 for j in xrange(n-1,0,-1):
  if a[j]<a[j-1]:
   a[j],a[j-1]=a[j-1],a[j]
   flag=True
   sw+=1 flag flag=False flag False for j in xrange(n-1,0,-1):
  if a[j]<a[j-1]:
   a[j],a[j-1]=a[j-1],a[j]
   flag=True
   sw+=1 j xrange(n-1,0,-1) xrange n-1 n 1 0 -1 if a[j]<a[j-1]:
   a[j],a[j-1]=a[j-1],a[j]
   flag=True
   sw+=1 a[j]<a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j],a[j-1]=a[j-1],a[j] a[j] a j a[j-1] a j-1 j 1 a[j-1] a j-1 j 1 a[j] a j flag=True flag True sw+=1 sw 1 pnt(a) pnt a print def pnt(s):
 for i in xrange(len(s)):
  print s[i],
 print def pnt(s):
 for i in xrange(len(s)):
  print s[i],
 print pnt sw+=1 1 sw n=int(raw_input()) int(raw_input()) n flag=False False flag flag=True True flag sw=0 0 sw flag=True True flag a=map(int,raw_input().split()) map(int,raw_input().split()) a
#coding: utf-8
#ALDS1_2A

def pnt(s):
 for i in xrange(len(s)):
  print s[i],
 print

n=int(raw_input())
a=map(int,raw_input().split())

sw=0
flag=True
while flag:
 flag=False
 for j in xrange(n-1,0,-1):
  if a[j]<a[j-1]:
   a[j],a[j-1]=a[j-1],a[j]
   flag=True
   sw+=1

pnt(a)
print sw