# completed
def print_list(ele_list):
    print(" ".join(map(str, ele_list)))

def bubble_sort(ele_list):
    len_ele_list = len(ele_list)
    num_swap = 0
    for i in range(0, len_ele_list):
       for j in range(len_ele_list-1, i, -1):
           if ele_list[j] < ele_list[j-1]:
               key = ele_list[j]
               ele_list[j] = ele_list[j-1]
               ele_list[j-1] = key
               num_swap += 1
    print_list(ele_list)
    print(num_swap)

N = int(input())
ele_list = list(map(int, input().split()))

bubble_sort(ele_list) def print_list(ele_list):
    print(" ".join(map(str, ele_list))) print_list print(" ".join(map(str, ele_list))) print " ".join(map(str, ele_list)) " ".join " " join map(str, ele_list) map str ele_list ele_list ele_list def bubble_sort(ele_list):
    len_ele_list = len(ele_list)
    num_swap = 0
    for i in range(0, len_ele_list):
       for j in range(len_ele_list-1, i, -1):
           if ele_list[j] < ele_list[j-1]:
               key = ele_list[j]
               ele_list[j] = ele_list[j-1]
               ele_list[j-1] = key
               num_swap += 1
    print_list(ele_list)
    print(num_swap) bubble_sort len_ele_list = len(ele_list) len_ele_list len(ele_list) len ele_list num_swap = 0 num_swap 0 for i in range(0, len_ele_list):
       for j in range(len_ele_list-1, i, -1):
           if ele_list[j] < ele_list[j-1]:
               key = ele_list[j]
               ele_list[j] = ele_list[j-1]
               ele_list[j-1] = key
               num_swap += 1
     i range(0, len_ele_list) range 0 len_ele_list for j in range(len_ele_list-1, i, -1):
           if ele_list[j] < ele_list[j-1]:
               key = ele_list[j]
               ele_list[j] = ele_list[j-1]
               ele_list[j-1] = key
               num_swap += 1
     j range(len_ele_list-1, i, -1) range len_ele_list-1 len_ele_list 1 i -1 if ele_list[j] < ele_list[j-1]:
               key = ele_list[j]
               ele_list[j] = ele_list[j-1]
               ele_list[j-1] = key
               num_swap += 1
     ele_list[j] < ele_list[j-1] ele_list[j] ele_list j ele_list[j-1] ele_list j-1 j 1 key = ele_list[j] key ele_list[j] ele_list j ele_list[j] = ele_list[j-1] ele_list[j] ele_list j ele_list[j-1] ele_list j-1 j 1 ele_list[j-1] = key ele_list[j-1] ele_list j-1 j 1 key num_swap += 1 num_swap 1 print_list(ele_list) print_list ele_list print(num_swap) print num_swap ele_list ele_list N = int(input()) N int(input()) int input() input ele_list = list(map(int, input().split())) ele_list list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bubble_sort(ele_list) bubble_sort ele_list ele_list = list(map(int, input().split())) list(map(int, input().split())) ele_list def print_list(ele_list):
    print(" ".join(map(str, ele_list))) def print_list(ele_list):
    print(" ".join(map(str, ele_list))) print_list N = int(input()) int(input()) N def bubble_sort(ele_list):
    len_ele_list = len(ele_list)
    num_swap = 0
    for i in range(0, len_ele_list):
       for j in range(len_ele_list-1, i, -1):
           if ele_list[j] < ele_list[j-1]:
               key = ele_list[j]
               ele_list[j] = ele_list[j-1]
               ele_list[j-1] = key
               num_swap += 1
    print_list(ele_list)
    print(num_swap) def bubble_sort(ele_list):
    len_ele_list = len(ele_list)
    num_swap = 0
    for i in range(0, len_ele_list):
       for j in range(len_ele_list-1, i, -1):
           if ele_list[j] < ele_list[j-1]:
               key = ele_list[j]
               ele_list[j] = ele_list[j-1]
               ele_list[j-1] = key
               num_swap += 1
    print_list(ele_list)
    print(num_swap) bubble_sort
# completed
def print_list(ele_list):
    print(" ".join(map(str, ele_list)))

def bubble_sort(ele_list):
    len_ele_list = len(ele_list)
    num_swap = 0
    for i in range(0, len_ele_list):
       for j in range(len_ele_list-1, i, -1):
           if ele_list[j] < ele_list[j-1]:
               key = ele_list[j]
               ele_list[j] = ele_list[j-1]
               ele_list[j-1] = key
               num_swap += 1
    print_list(ele_list)
    print(num_swap)

N = int(input())
ele_list = list(map(int, input().split()))

bubble_sort(ele_list)