def bubbleSort(nums, length):
  count = 0
  flag = 1
  while flag:
    flag = 0
    for j in xrange(length - 1, 0, -1):
      if nums[j] < nums[j - 1]:
        nums[j], nums[j - 1] = nums[j - 1], nums[j]
        count += 1
        flag = 1
  return [nums, count]

length = int(raw_input())
nums = map(int, raw_input().split())
ans = bubbleSort(nums, length)
print " ".join(map(str, ans[0]))
print ans[1] def bubbleSort(nums, length):
  count = 0
  flag = 1
  while flag:
    flag = 0
    for j in xrange(length - 1, 0, -1):
      if nums[j] < nums[j - 1]:
        nums[j], nums[j - 1] = nums[j - 1], nums[j]
        count += 1
        flag = 1
  return [nums, count] bubbleSort count = 0 count 0 flag = 1 flag 1 while flag:
    flag = 0
    for j in xrange(length - 1, 0, -1):
      if nums[j] < nums[j - 1]:
        nums[j], nums[j - 1] = nums[j - 1], nums[j]
        count += 1
        flag = 1
   flag flag = 0 flag 0 for j in xrange(length - 1, 0, -1):
      if nums[j] < nums[j - 1]:
        nums[j], nums[j - 1] = nums[j - 1], nums[j]
        count += 1
        flag = 1
   j xrange(length - 1, 0, -1) xrange length - 1 length 1 0 -1 if nums[j] < nums[j - 1]:
        nums[j], nums[j - 1] = nums[j - 1], nums[j]
        count += 1
        flag = 1
   nums[j] < nums[j - 1] nums[j] nums j nums[j - 1] nums j - 1 j 1 nums[j], nums[j - 1] = nums[j - 1], nums[j] nums[j] nums j nums[j - 1] nums j - 1 j 1 nums[j - 1] nums j - 1 j 1 nums[j] nums j count += 1 count 1 flag = 1 flag 1 return [nums, count] [nums, count] nums count nums nums length length length = int(raw_input()) length int(raw_input()) int raw_input() raw_input nums = map(int, raw_input().split()) nums map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split ans = bubbleSort(nums, length) ans bubbleSort(nums, length) bubbleSort nums length print " ".join(map(str, ans[0])) " ".join " " join map(str, ans[0]) map str ans[0] ans 0 print ans[1] ans 1 def bubbleSort(nums, length):
  count = 0
  flag = 1
  while flag:
    flag = 0
    for j in xrange(length - 1, 0, -1):
      if nums[j] < nums[j - 1]:
        nums[j], nums[j - 1] = nums[j - 1], nums[j]
        count += 1
        flag = 1
  return [nums, count] def bubbleSort(nums, length):
  count = 0
  flag = 1
  while flag:
    flag = 0
    for j in xrange(length - 1, 0, -1):
      if nums[j] < nums[j - 1]:
        nums[j], nums[j - 1] = nums[j - 1], nums[j]
        count += 1
        flag = 1
  return [nums, count] bubbleSort nums = map(int, raw_input().split()) map(int, raw_input().split()) nums ans = bubbleSort(nums, length) bubbleSort(nums, length) ans length = int(raw_input()) int(raw_input()) length
def bubbleSort(nums, length):
  count = 0
  flag = 1
  while flag:
    flag = 0
    for j in xrange(length - 1, 0, -1):
      if nums[j] < nums[j - 1]:
        nums[j], nums[j - 1] = nums[j - 1], nums[j]
        count += 1
        flag = 1
  return [nums, count]

length = int(raw_input())
nums = map(int, raw_input().split())
ans = bubbleSort(nums, length)
print " ".join(map(str, ans[0]))
print ans[1]