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


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


n = int(input())
a = list(map(int, input().split()))
bubbleSort(n, a)
