def bubblesort(n,l):
  flag=True
  m=0
  c=0
  for j in range(n):
    for i in range(n-1,m,-1):
      if int(l[i])<int(l[i-1]):
        l[i],l[i-1]=l[i-1],l[i]
        
        c+=1
    m+=1
  print(" ".join(l))
  print(c)
n=int(input())
l=list(input().split())
bubblesort(n,l) def bubblesort(n,l):
  flag=True
  m=0
  c=0
  for j in range(n):
    for i in range(n-1,m,-1):
      if int(l[i])<int(l[i-1]):
        l[i],l[i-1]=l[i-1],l[i]
        
        c+=1
    m+=1
  print(" ".join(l))
  print(c) bubblesort flag=True flag True m=0 m 0 c=0 c 0 for j in range(n):
    for i in range(n-1,m,-1):
      if int(l[i])<int(l[i-1]):
        l[i],l[i-1]=l[i-1],l[i]
        
        c+=1
    m+=1
   j range(n) range n for i in range(n-1,m,-1):
      if int(l[i])<int(l[i-1]):
        l[i],l[i-1]=l[i-1],l[i]
        
        c+=1
     i range(n-1,m,-1) range n-1 n 1 m -1 if int(l[i])<int(l[i-1]):
        l[i],l[i-1]=l[i-1],l[i]
        
        c+=1
     int(l[i])<int(l[i-1]) int(l[i]) int l[i] l i int(l[i-1]) int l[i-1] l i-1 i 1 l[i],l[i-1]=l[i-1],l[i] l[i] l i l[i-1] l i-1 i 1 l[i-1] l i-1 i 1 l[i] l i c+=1 c 1 m+=1 m 1 print(" ".join(l)) print " ".join(l) " ".join " " join l print(c) print c n n l l n=int(input()) n int(input()) int input() input l=list(input().split()) l list(input().split()) list input().split() ().split () input split bubblesort(n,l) bubblesort n l l=list(input().split()) list(input().split()) l n=int(input()) int(input()) n def bubblesort(n,l):
  flag=True
  m=0
  c=0
  for j in range(n):
    for i in range(n-1,m,-1):
      if int(l[i])<int(l[i-1]):
        l[i],l[i-1]=l[i-1],l[i]
        
        c+=1
    m+=1
  print(" ".join(l))
  print(c) def bubblesort(n,l):
  flag=True
  m=0
  c=0
  for j in range(n):
    for i in range(n-1,m,-1):
      if int(l[i])<int(l[i-1]):
        l[i],l[i-1]=l[i-1],l[i]
        
        c+=1
    m+=1
  print(" ".join(l))
  print(c) bubblesort
def bubblesort(n,l):
  flag=True
  m=0
  c=0
  for j in range(n):
    for i in range(n-1,m,-1):
      if int(l[i])<int(l[i-1]):
        l[i],l[i-1]=l[i-1],l[i]
        
        c+=1
    m+=1
  print(" ".join(l))
  print(c)
n=int(input())
l=list(input().split())
bubblesort(n,l)
