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

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

if __name__ == '__main__':
    N = int(input())
    A = list(map(int,input().split()))
    bubbleSort(N, A)