def showList(A, N):
    for i in range(N-1):
        print(A[i],end=' ')
    print(A[N-1])

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

N = int(input())
A = [int(x) for x in input().split(' ')]
bubbleSort(A, N) def showList(A, N):
    for i in range(N-1):
        print(A[i],end=' ')
    print(A[N-1]) showList for i in range(N-1):
        print(A[i],end=' ')
     i range(N-1) range N-1 N 1 print(A[i],end=' ') print A[i] A i end=' ' end ' ' print(A[N-1]) print A[N-1] A N-1 N 1 A A N N def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                v = A[i]
                A[i] = A[i-1]
                A[i-1] = v
                flag = 1
                count += 1
    showList(A, N)
    print(count) bubbleSort flag = 1 flag 1 count = 0 count 0 while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                v = A[i]
                A[i] = A[i-1]
                A[i-1] = v
                flag = 1
                count += 1
     flag flag = 0 flag 0 for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                v = A[i]
                A[i] = A[i-1]
                A[i-1] = v
                flag = 1
                count += 1
     i range(N-1, 0, -1) range N-1 N 1 0 -1 if A[i] < A[i-1]:
                v = A[i]
                A[i] = A[i-1]
                A[i-1] = v
                flag = 1
                count += 1
     A[i] < A[i-1] A[i] A i A[i-1] A i-1 i 1 v = A[i] v A[i] A i A[i] = A[i-1] A[i] A i A[i-1] A i-1 i 1 A[i-1] = v A[i-1] A i-1 i 1 v flag = 1 flag 1 count += 1 count 1 showList(A, N) showList A N print(count) print count A A N N N = int(input()) N int(input()) int input() input int(x) for x in input().split(' ') for x in input().split(' ') x input().split(' ') ().split () input split ' ' for x in input().split(' ') int(x) int x A = [int(x) for x in input().split(' ')] A [int(x) for x in input().split(' ')] bubbleSort(A, N) bubbleSort A N N = int(input()) int(input()) N def showList(A, N):
    for i in range(N-1):
        print(A[i],end=' ')
    print(A[N-1]) def showList(A, N):
    for i in range(N-1):
        print(A[i],end=' ')
    print(A[N-1]) showList def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                v = A[i]
                A[i] = A[i-1]
                A[i-1] = v
                flag = 1
                count += 1
    showList(A, N)
    print(count) def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                v = A[i]
                A[i] = A[i-1]
                A[i-1] = v
                flag = 1
                count += 1
    showList(A, N)
    print(count) bubbleSort A = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] A
def showList(A, N):
    for i in range(N-1):
        print(A[i],end=' ')
    print(A[N-1])

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

N = int(input())
A = [int(x) for x in input().split(' ')]
bubbleSort(A, N)
