n = int(input())
data = [int(i) for i in input().split(' ')]

def bubble_sort(raw_list):
    n_list = len(raw_list)
    n_swap = 0
    sorted_i = 1
    flag = True
    while flag:
        flag = False
        for j in reversed(range(sorted_i, n_list)):
            if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
        sorted_i += 1
    print(' '.join([str(i) for i in raw_list]))
    print(n_swap)
        
bubble_sort(data) n = int(input()) n 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 data = [int(i) for i in input().split(' ')] data [int(i) for i in input().split(' ')] def bubble_sort(raw_list):
    n_list = len(raw_list)
    n_swap = 0
    sorted_i = 1
    flag = True
    while flag:
        flag = False
        for j in reversed(range(sorted_i, n_list)):
            if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
        sorted_i += 1
    print(' '.join([str(i) for i in raw_list]))
    print(n_swap)
         bubble_sort n_list = len(raw_list) n_list len(raw_list) len raw_list n_swap = 0 n_swap 0 sorted_i = 1 sorted_i 1 flag = True flag True while flag:
        flag = False
        for j in reversed(range(sorted_i, n_list)):
            if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
        sorted_i += 1
     flag flag = False flag False for j in reversed(range(sorted_i, n_list)):
            if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
         j reversed(range(sorted_i, n_list)) reversed range(sorted_i, n_list) range sorted_i n_list if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
         raw_list[j] < raw_list[j-1] raw_list[j] raw_list j raw_list[j-1] raw_list j-1 j 1 raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1] raw_list[j-1] raw_list j-1 j 1 raw_list[j] raw_list j raw_list[j] raw_list j raw_list[j-1] raw_list j-1 j 1 n_swap += 1 n_swap 1 flag = True flag True sorted_i += 1 sorted_i 1 str(i) for i in raw_list for i in raw_list i raw_list for i in raw_list str(i) str i print(' '.join([str(i) for i in raw_list])) print ' '.join([str(i) for i in raw_list]) ' '.join ' ' join [str(i) for i in raw_list] print(n_swap) print n_swap raw_list raw_list bubble_sort(data) bubble_sort data n = int(input()) int(input()) n data = [int(i) for i in input().split(' ')] [int(i) for i in input().split(' ')] data def bubble_sort(raw_list):
    n_list = len(raw_list)
    n_swap = 0
    sorted_i = 1
    flag = True
    while flag:
        flag = False
        for j in reversed(range(sorted_i, n_list)):
            if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
        sorted_i += 1
    print(' '.join([str(i) for i in raw_list]))
    print(n_swap)
         def bubble_sort(raw_list):
    n_list = len(raw_list)
    n_swap = 0
    sorted_i = 1
    flag = True
    while flag:
        flag = False
        for j in reversed(range(sorted_i, n_list)):
            if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
        sorted_i += 1
    print(' '.join([str(i) for i in raw_list]))
    print(n_swap)
         bubble_sort
n = int(input())
data = [int(i) for i in input().split(' ')]

def bubble_sort(raw_list):
    n_list = len(raw_list)
    n_swap = 0
    sorted_i = 1
    flag = True
    while flag:
        flag = False
        for j in reversed(range(sorted_i, n_list)):
            if raw_list[j] < raw_list[j-1]:
                raw_list[j-1], raw_list[j] = raw_list[j], raw_list[j-1]
                n_swap += 1
                flag = True
        sorted_i += 1
    print(' '.join([str(i) for i in raw_list]))
    print(n_swap)
        
bubble_sort(data)