def bubbleSort(A, N):
    s = 0
    flag = 0
    while flag == 0:
        flag = 1
        for j in range(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 0
                s += 1
    t = str(A[0])
    for i in range(1,N):
        t = t + " " + str(A[i])
    print(t)
    print(s)

n = int(input())
a = [int(i) for i in input().split()]

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

n = int(input())
a = [int(i) for i in input().split()]

bubbleSort(a, n)