# coding:utf-8
n = int(input())
nums = [int(x) for x in input().split(" ")]
flag = True
count = 0
while flag:
    flag = False
    for i in range(n - 1, 0, -1):
        if nums[i] < nums[i - 1]:
            nums[i], nums[i - 1] = nums[i - 1], nums[i]
            flag = True
            count += 1
print(" ".join([str(i) for i in nums]))
print(count) n = int(input()) n int(input()) int input() input int(x) for x in input().split(" ") for x in input().split(" ") x input().split(" ") ().split () input split " " for x in input().split(" ") int(x) int x nums = [int(x) for x in input().split(" ")] nums [int(x) for x in input().split(" ")] flag = True flag True count = 0 count 0 while flag:
    flag = False
    for i in range(n - 1, 0, -1):
        if nums[i] < nums[i - 1]:
            nums[i], nums[i - 1] = nums[i - 1], nums[i]
            flag = True
            count += 1 flag flag = False flag False for i in range(n - 1, 0, -1):
        if nums[i] < nums[i - 1]:
            nums[i], nums[i - 1] = nums[i - 1], nums[i]
            flag = True
            count += 1 i range(n - 1, 0, -1) range n - 1 n 1 0 -1 if nums[i] < nums[i - 1]:
            nums[i], nums[i - 1] = nums[i - 1], nums[i]
            flag = True
            count += 1 nums[i] < nums[i - 1] nums[i] nums i nums[i - 1] nums i - 1 i 1 nums[i], nums[i - 1] = nums[i - 1], nums[i] nums[i] nums i nums[i - 1] nums i - 1 i 1 nums[i - 1] nums i - 1 i 1 nums[i] nums i flag = True flag True count += 1 count 1 str(i) for i in nums for i in nums i nums for i in nums str(i) str i print(" ".join([str(i) for i in nums])) print " ".join([str(i) for i in nums]) " ".join " " join [str(i) for i in nums] print(count) print count n = int(input()) int(input()) n flag = True True flag nums = [int(x) for x in input().split(" ")] [int(x) for x in input().split(" ")] nums flag = True True flag flag = False False flag count += 1 1 count count = 0 0 count
# coding:utf-8
n = int(input())
nums = [int(x) for x in input().split(" ")]
flag = True
count = 0
while flag:
    flag = False
    for i in range(n - 1, 0, -1):
        if nums[i] < nums[i - 1]:
            nums[i], nums[i - 1] = nums[i - 1], nums[i]
            flag = True
            count += 1
print(" ".join([str(i) for i in nums]))
print(count)