#coding: utf-8

def print_list(X):
    first_flag = True
    for val in X:
        if first_flag:
            print_line = str(val)
            first_flag = False
        else:
            print_line = print_line + ' ' + str(val)
    print(print_line)

def bubble_sort(A, N):
    #print_list(A)
    #flag: ???????????????????????????True???????´?
    flag = True
    counter = 0

    while flag:
        flag = False
        for j in range(1, N):
            if A[j] < A[j-1]:
                tmp_val = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp_val

                flag = True
                counter += 1
        #print_list(A)
    print_list(A)
    print(counter)

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

bubble_sort(A, N) def print_list(X):
    first_flag = True
    for val in X:
        if first_flag:
            print_line = str(val)
            first_flag = False
        else:
            print_line = print_line + ' ' + str(val)
    print(print_line) print_list first_flag = True first_flag True for val in X:
        if first_flag:
            print_line = str(val)
            first_flag = False
        else:
            print_line = print_line + ' ' + str(val)
     val X if first_flag:
            print_line = str(val)
            first_flag = False
        else:
            print_line = print_line + ' ' + str(val)
     first_flag print_line = str(val) print_line str(val) str val first_flag = False first_flag False print_line = print_line + ' ' + str(val) print_line print_line + ' ' + str(val) print_line + ' ' print_line ' ' str(val) str val print(print_line) print print_line X X def bubble_sort(A, N):
    #print_list(A)
    #flag: ???????????????????????????True???????´?
    flag = True
    counter = 0

    while flag:
        flag = False
        for j in range(1, N):
            if A[j] < A[j-1]:
                tmp_val = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp_val

                flag = True
                counter += 1
        #print_list(A)
    print_list(A)
    print(counter) bubble_sort flag = True flag True counter = 0 counter 0 while flag:
        flag = False
        for j in range(1, N):
            if A[j] < A[j-1]:
                tmp_val = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp_val

                flag = True
                counter += 1
        #print_list(A)
     flag flag = False flag False for j in range(1, N):
            if A[j] < A[j-1]:
                tmp_val = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp_val

                flag = True
                counter += 1
        #print_list(A)
     j range(1, N) range 1 N if A[j] < A[j-1]:
                tmp_val = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp_val

                flag = True
                counter += 1
        #print_list(A)
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 tmp_val = A[j] tmp_val A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = tmp_val A[j-1] A j-1 j 1 tmp_val flag = True flag True counter += 1 counter 1 print_list(A) print_list A print(counter) print counter A A N N N = int(input()) N int(input()) int input() input A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bubble_sort(A, N) bubble_sort A N def bubble_sort(A, N):
    #print_list(A)
    #flag: ???????????????????????????True???????´?
    flag = True
    counter = 0

    while flag:
        flag = False
        for j in range(1, N):
            if A[j] < A[j-1]:
                tmp_val = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp_val

                flag = True
                counter += 1
        #print_list(A)
    print_list(A)
    print(counter) def bubble_sort(A, N):
    #print_list(A)
    #flag: ???????????????????????????True???????´?
    flag = True
    counter = 0

    while flag:
        flag = False
        for j in range(1, N):
            if A[j] < A[j-1]:
                tmp_val = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp_val

                flag = True
                counter += 1
        #print_list(A)
    print_list(A)
    print(counter) bubble_sort N = int(input()) int(input()) N A = list(map(int, input().split())) list(map(int, input().split())) A def print_list(X):
    first_flag = True
    for val in X:
        if first_flag:
            print_line = str(val)
            first_flag = False
        else:
            print_line = print_line + ' ' + str(val)
    print(print_line) def print_list(X):
    first_flag = True
    for val in X:
        if first_flag:
            print_line = str(val)
            first_flag = False
        else:
            print_line = print_line + ' ' + str(val)
    print(print_line) print_list
#coding: utf-8

def print_list(X):
    first_flag = True
    for val in X:
        if first_flag:
            print_line = str(val)
            first_flag = False
        else:
            print_line = print_line + ' ' + str(val)
    print(print_line)

def bubble_sort(A, N):
    #print_list(A)
    #flag: ???????????????????????????True???????´?
    flag = True
    counter = 0

    while flag:
        flag = False
        for j in range(1, N):
            if A[j] < A[j-1]:
                tmp_val = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp_val

                flag = True
                counter += 1
        #print_list(A)
    print_list(A)
    print(counter)

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

bubble_sort(A, N)