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

def bubbleSort(A):
    n = len(A)
    flag = True
    i = 0
    while flag:
        flag = False
        for j in range(n-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                i += 1
                flag = True
    print(*A)
    print(i)
bubbleSort(A) 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 " " def bubbleSort(A):
    n = len(A)
    flag = True
    i = 0
    while flag:
        flag = False
        for j in range(n-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                i += 1
                flag = True
    print(*A)
    print(i) bubbleSort n = len(A) n len(A) len A flag = True flag True i = 0 i 0 while flag:
        flag = False
        for j in range(n-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                i += 1
                flag = True
     flag flag = False flag False for j in range(n-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                i += 1
                flag = True
     j range(n-1, 0, -1) range n-1 n 1 0 -1 if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                i += 1
                flag = True
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j i += 1 i 1 flag = True flag True print(*A) print *A A print(i) print i A A bubbleSort(A) bubbleSort A n = int(input()) int(input()) n def bubbleSort(A):
    n = len(A)
    flag = True
    i = 0
    while flag:
        flag = False
        for j in range(n-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                i += 1
                flag = True
    print(*A)
    print(i) def bubbleSort(A):
    n = len(A)
    flag = True
    i = 0
    while flag:
        flag = False
        for j in range(n-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                i += 1
                flag = True
    print(*A)
    print(i) bubbleSort A = list(map(int, input().split(" "))) list(map(int, input().split(" "))) A
n = int(input())
A = list(map(int, input().split(" ")))

def bubbleSort(A):
    n = len(A)
    flag = True
    i = 0
    while flag:
        flag = False
        for j in range(n-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                i += 1
                flag = True
    print(*A)
    print(i)
bubbleSort(A)
