import sys

def bubbleSort(x_list, y):
  a = 0
  flag = 1
  while flag:
    flag = 0
    for i in range(1, y):
      j = y - i
      if x_list[j] < x_list[j - 1]:
        x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j]
        flag = 1
        a += 1
  return a

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()
x_list = x.split(" ")

for i in range(y):
  x_list[i] = int(x_list[i])

a = bubbleSort(x_list, y)

for k in range(0, y):
  print x_list[k],
print
print a import sys sys def bubbleSort(x_list, y):
  a = 0
  flag = 1
  while flag:
    flag = 0
    for i in range(1, y):
      j = y - i
      if x_list[j] < x_list[j - 1]:
        x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j]
        flag = 1
        a += 1
  return a bubbleSort a = 0 a 0 flag = 1 flag 1 while flag:
    flag = 0
    for i in range(1, y):
      j = y - i
      if x_list[j] < x_list[j - 1]:
        x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j]
        flag = 1
        a += 1
   flag flag = 0 flag 0 for i in range(1, y):
      j = y - i
      if x_list[j] < x_list[j - 1]:
        x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j]
        flag = 1
        a += 1
   i range(1, y) range 1 y j = y - i j y - i y i if x_list[j] < x_list[j - 1]:
        x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j]
        flag = 1
        a += 1
   x_list[j] < x_list[j - 1] x_list[j] x_list j x_list[j - 1] x_list j - 1 j 1 x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j] x_list[j] x_list j x_list[j - 1] x_list j - 1 j 1 x_list[j - 1] x_list j - 1 j 1 x_list[j] x_list j flag = 1 flag 1 a += 1 a 1 return a a x_list x_list y y y = sys.stdin.readline() y sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline y = int(y) y int(y) int y x = sys.stdin.readline() x sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline x_list = x.split(" ") x_list x.split(" ") x.split x split " " for i in range(y):
  x_list[i] = int(x_list[i]) i range(y) range y x_list[i] = int(x_list[i]) x_list[i] x_list i int(x_list[i]) int x_list[i] x_list i a = bubbleSort(x_list, y) a bubbleSort(x_list, y) bubbleSort x_list y for k in range(0, y):
  print x_list[k], k range(0, y) range 0 y print x_list[k] x_list k print print y = int(y) int(y) y a = bubbleSort(x_list, y) bubbleSort(x_list, y) a def bubbleSort(x_list, y):
  a = 0
  flag = 1
  while flag:
    flag = 0
    for i in range(1, y):
      j = y - i
      if x_list[j] < x_list[j - 1]:
        x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j]
        flag = 1
        a += 1
  return a def bubbleSort(x_list, y):
  a = 0
  flag = 1
  while flag:
    flag = 0
    for i in range(1, y):
      j = y - i
      if x_list[j] < x_list[j - 1]:
        x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j]
        flag = 1
        a += 1
  return a bubbleSort x_list = x.split(" ") x.split(" ") x_list y = sys.stdin.readline() sys.stdin.readline() y x = sys.stdin.readline() sys.stdin.readline() x
import sys

def bubbleSort(x_list, y):
  a = 0
  flag = 1
  while flag:
    flag = 0
    for i in range(1, y):
      j = y - i
      if x_list[j] < x_list[j - 1]:
        x_list[j], x_list[j - 1] = x_list[j - 1], x_list[j]
        flag = 1
        a += 1
  return a

y = sys.stdin.readline()
y = int(y)

x = sys.stdin.readline()
x_list = x.split(" ")

for i in range(y):
  x_list[i] = int(x_list[i])

a = bubbleSort(x_list, y)

for k in range(0, y):
  print x_list[k],
print
print a