def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag == 1:
        flag = 0
        for i in range(1, N)[::-1]:
            if A[i] < A[i - 1]:
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = 1
                count += 1

    print(" ".join(map(str, A)))
    print(count)

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

bubbleSort(A, n) def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag == 1:
        flag = 0
        for i in range(1, N)[::-1]:
            if A[i] < A[i - 1]:
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = 1
                count += 1

    print(" ".join(map(str, A)))
    print(count) bubbleSort flag = 1 flag 1 count = 0 count 0 while flag == 1:
        flag = 0
        for i in range(1, N)[::-1]:
            if A[i] < A[i - 1]:
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = 1
                count += 1

     flag == 1 flag 1 flag = 0 flag 0 for i in range(1, N)[::-1]:
            if A[i] < A[i - 1]:
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = 1
                count += 1

     i range(1, N)[::-1] (1, N) range 1 N ::-1 -1 if A[i] < A[i - 1]:
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = 1
                count += 1

     A[i] < A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 tmp = A[i] tmp A[i] A i A[i] = A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 A[i - 1] = tmp A[i - 1] A i - 1 i 1 tmp flag = 1 flag 1 count += 1 count 1 print(" ".join(map(str, A))) print " ".join(map(str, A)) " ".join " " join map(str, A) map str A print(count) print count 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 bubbleSort(A, n) bubbleSort A n n = int(input()) int(input()) n def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag == 1:
        flag = 0
        for i in range(1, N)[::-1]:
            if A[i] < A[i - 1]:
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = 1
                count += 1

    print(" ".join(map(str, A)))
    print(count) def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag == 1:
        flag = 0
        for i in range(1, N)[::-1]:
            if A[i] < A[i - 1]:
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = 1
                count += 1

    print(" ".join(map(str, A)))
    print(count) bubbleSort A = list(map(int, input().split())) list(map(int, input().split())) A
def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag == 1:
        flag = 0
        for i in range(1, N)[::-1]:
            if A[i] < A[i - 1]:
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = 1
                count += 1

    print(" ".join(map(str, A)))
    print(count)

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

bubbleSort(A, n)