# -*- coding: utf-8 -*-

def bubbleSort(num_list):
    flag = True
    length = len(num_list)
    count = 0
    while flag:
        flag = False
        for j in range(length-1, 0, -1):
            if num_list[j] < num_list[j-1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = True
                count += 1
    return num_list, count


input_num = int(input())
num_list = [int(i) for i in input().split()]

bubble_list, swap_num = bubbleSort(num_list)
for i in range(len(num_list)):
    if i > 0:
        print(" ", end="")
    print(num_list[i], end="")
print()
print(swap_num) def bubbleSort(num_list):
    flag = True
    length = len(num_list)
    count = 0
    while flag:
        flag = False
        for j in range(length-1, 0, -1):
            if num_list[j] < num_list[j-1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = True
                count += 1
    return num_list, count bubbleSort flag = True flag True length = len(num_list) length len(num_list) len num_list count = 0 count 0 while flag:
        flag = False
        for j in range(length-1, 0, -1):
            if num_list[j] < num_list[j-1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = True
                count += 1
     flag flag = False flag False for j in range(length-1, 0, -1):
            if num_list[j] < num_list[j-1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = True
                count += 1
     j range(length-1, 0, -1) range length-1 length 1 0 -1 if num_list[j] < num_list[j-1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = True
                count += 1
     num_list[j] < num_list[j-1] num_list[j] num_list j num_list[j-1] num_list j-1 j 1 num_list[j], num_list[j-1] = num_list[j-1], num_list[j] num_list[j] num_list j num_list[j-1] num_list j-1 j 1 num_list[j-1] num_list j-1 j 1 num_list[j] num_list j flag = True flag True count += 1 count 1 return num_list, count return num_list, count num_list count num_list num_list input_num = int(input()) input_num int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i num_list = [int(i) for i in input().split()] num_list [int(i) for i in input().split()] bubble_list, swap_num = bubbleSort(num_list) bubble_list bubbleSort(num_list) bubbleSort num_list swap_num for i in range(len(num_list)):
    if i > 0:
        print(" ", end="")
    print(num_list[i], end="") i range(len(num_list)) range len(num_list) len num_list if i > 0:
        print(" ", end="")
     i > 0 i 0 print(" ", end="") print " " end="" end "" print(num_list[i], end="") print num_list[i] num_list i end="" end "" print() print print(swap_num) print swap_num def bubbleSort(num_list):
    flag = True
    length = len(num_list)
    count = 0
    while flag:
        flag = False
        for j in range(length-1, 0, -1):
            if num_list[j] < num_list[j-1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = True
                count += 1
    return num_list, count def bubbleSort(num_list):
    flag = True
    length = len(num_list)
    count = 0
    while flag:
        flag = False
        for j in range(length-1, 0, -1):
            if num_list[j] < num_list[j-1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = True
                count += 1
    return num_list, count bubbleSort num_list = [int(i) for i in input().split()] [int(i) for i in input().split()] num_list input_num = int(input()) int(input()) input_num bubble_list, swap_num = bubbleSort(num_list) bubbleSort(num_list) bubble_list swap_num = bubbleSort(num_list) bubbleSort(num_list) swap_num
# -*- coding: utf-8 -*-

def bubbleSort(num_list):
    flag = True
    length = len(num_list)
    count = 0
    while flag:
        flag = False
        for j in range(length-1, 0, -1):
            if num_list[j] < num_list[j-1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = True
                count += 1
    return num_list, count


input_num = int(input())
num_list = [int(i) for i in input().split()]

bubble_list, swap_num = bubbleSort(num_list)
for i in range(len(num_list)):
    if i > 0:
        print(" ", end="")
    print(num_list[i], end="")
print()
print(swap_num)