def bubble_sort(A):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(len(A) - 1, 0, -1):
            if A[i - 1] > A[i]:
                A[i - 1], A[i] = A[i], A[i - 1]
                flag = 1
                count += 1
    return count


def show(A):
    for i in range(len(A) - 1):
        print(A[i], end=" ")
    print(A[len(A) - 1])


n = int(input())
line = input()
A = list(map(int, line.split()))
count = bubble_sort(A)
show(A)
print(count) def bubble_sort(A):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(len(A) - 1, 0, -1):
            if A[i - 1] > A[i]:
                A[i - 1], A[i] = A[i], A[i - 1]
                flag = 1
                count += 1
    return count bubble_sort flag = 1 flag 1 count = 0 count 0 while flag:
        flag = 0
        for i in range(len(A) - 1, 0, -1):
            if A[i - 1] > A[i]:
                A[i - 1], A[i] = A[i], A[i - 1]
                flag = 1
                count += 1
     flag flag = 0 flag 0 for i in range(len(A) - 1, 0, -1):
            if A[i - 1] > A[i]:
                A[i - 1], A[i] = A[i], A[i - 1]
                flag = 1
                count += 1
     i range(len(A) - 1, 0, -1) range len(A) - 1 len(A) len A 1 0 -1 if A[i - 1] > A[i]:
                A[i - 1], A[i] = A[i], A[i - 1]
                flag = 1
                count += 1
     A[i - 1] > A[i] A[i - 1] A i - 1 i 1 A[i] A i A[i - 1], A[i] = A[i], A[i - 1] A[i - 1] A i - 1 i 1 A[i] A i A[i] A i A[i - 1] A i - 1 i 1 flag = 1 flag 1 count += 1 count 1 return count count A A def show(A):
    for i in range(len(A) - 1):
        print(A[i], end=" ")
    print(A[len(A) - 1]) show for i in range(len(A) - 1):
        print(A[i], end=" ")
     i range(len(A) - 1) range len(A) - 1 len(A) len A 1 print(A[i], end=" ") print A[i] A i end=" " end " " print(A[len(A) - 1]) print A[len(A) - 1] A len(A) - 1 len(A) len A 1 A A n = int(input()) n int(input()) int input() input line = input() line input() input A = list(map(int, line.split())) A list(map(int, line.split())) list map(int, line.split()) map int line.split() line.split line split count = bubble_sort(A) count bubble_sort(A) bubble_sort A show(A) show A print(count) print count def show(A):
    for i in range(len(A) - 1):
        print(A[i], end=" ")
    print(A[len(A) - 1]) def show(A):
    for i in range(len(A) - 1):
        print(A[i], end=" ")
    print(A[len(A) - 1]) show count = bubble_sort(A) bubble_sort(A) count A = list(map(int, line.split())) list(map(int, line.split())) A n = int(input()) int(input()) n def bubble_sort(A):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(len(A) - 1, 0, -1):
            if A[i - 1] > A[i]:
                A[i - 1], A[i] = A[i], A[i - 1]
                flag = 1
                count += 1
    return count def bubble_sort(A):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(len(A) - 1, 0, -1):
            if A[i - 1] > A[i]:
                A[i - 1], A[i] = A[i], A[i - 1]
                flag = 1
                count += 1
    return count bubble_sort line = input() input() line
def bubble_sort(A):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(len(A) - 1, 0, -1):
            if A[i - 1] > A[i]:
                A[i - 1], A[i] = A[i], A[i - 1]
                flag = 1
                count += 1
    return count


def show(A):
    for i in range(len(A) - 1):
        print(A[i], end=" ")
    print(A[len(A) - 1])


n = int(input())
line = input()
A = list(map(int, line.split()))
count = bubble_sort(A)
show(A)
print(count)