def bubble_sort(A):
    flag = True
    i = 0
    global count
    while flag:
        flag = False
        for j in range(i, len(A)-1):
           if A[j+1] < A[j]:
                A[j], A[j+1] = A[j+1], A[j]
                count += 1
                flag = True
        if not flag:
            i += 1
            flag = True
        if i >= len(A)-1:
            flag = False

n = int(input())
A = list(map(int, input().split()))
count = 0
bubble_sort(A)
print(*A)
print(count) def bubble_sort(A):
    flag = True
    i = 0
    global count
    while flag:
        flag = False
        for j in range(i, len(A)-1):
           if A[j+1] < A[j]:
                A[j], A[j+1] = A[j+1], A[j]
                count += 1
                flag = True
        if not flag:
            i += 1
            flag = True
        if i >= len(A)-1:
            flag = False bubble_sort flag = True flag True i = 0 i 0 global count while flag:
        flag = False
        for j in range(i, len(A)-1):
           if A[j+1] < A[j]:
                A[j], A[j+1] = A[j+1], A[j]
                count += 1
                flag = True
        if not flag:
            i += 1
            flag = True
        if i >= len(A)-1:
            flag = False flag flag = False flag False for j in range(i, len(A)-1):
           if A[j+1] < A[j]:
                A[j], A[j+1] = A[j+1], A[j]
                count += 1
                flag = True
         j range(i, len(A)-1) range i len(A)-1 len(A) len A 1 if A[j+1] < A[j]:
                A[j], A[j+1] = A[j+1], A[j]
                count += 1
                flag = True
         A[j+1] < A[j] A[j+1] A j+1 j 1 A[j] A j 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 count += 1 count 1 flag = True flag True if not flag:
            i += 1
            flag = True
         not flag flag i += 1 i 1 flag = True flag True if i >= len(A)-1:
            flag = False i >= len(A)-1 i len(A)-1 len(A) len A 1 flag = False flag False 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 count = 0 count 0 bubble_sort(A) bubble_sort A print(*A) print *A A print(count) print count n = int(input()) int(input()) n def bubble_sort(A):
    flag = True
    i = 0
    global count
    while flag:
        flag = False
        for j in range(i, len(A)-1):
           if A[j+1] < A[j]:
                A[j], A[j+1] = A[j+1], A[j]
                count += 1
                flag = True
        if not flag:
            i += 1
            flag = True
        if i >= len(A)-1:
            flag = False def bubble_sort(A):
    flag = True
    i = 0
    global count
    while flag:
        flag = False
        for j in range(i, len(A)-1):
           if A[j+1] < A[j]:
                A[j], A[j+1] = A[j+1], A[j]
                count += 1
                flag = True
        if not flag:
            i += 1
            flag = True
        if i >= len(A)-1:
            flag = False bubble_sort A = list(map(int, input().split())) list(map(int, input().split())) A count = 0 0 count
def bubble_sort(A):
    flag = True
    i = 0
    global count
    while flag:
        flag = False
        for j in range(i, len(A)-1):
           if A[j+1] < A[j]:
                A[j], A[j+1] = A[j+1], A[j]
                count += 1
                flag = True
        if not flag:
            i += 1
            flag = True
        if i >= len(A)-1:
            flag = False

n = int(input())
A = list(map(int, input().split()))
count = 0
bubble_sort(A)
print(*A)
print(count)
