Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode:                 BubbleSort(A) 1 for i = 0 to A.length-1 2     for j = A.length-1 downto i+1 3         if A[j] < A[j-1] 4             swap A[j] and A[j-1]   Note that, indices for array elements are based on 0-origin.  Your program should also print the number of swap operations defined in line 4 of the pseudocode.
def print_list(A):
    print(*A, sep=" ")

def swap(a, b):
    return b, a

def bubble_sort(A, n):
    print_list(A)
    flg = 1 
    i = 0
    while flg:
        flg = 0
        for j in range(n-1, i+1, -1):
            if A[j-1] > A[j]:
                A[j-1], A[j] = swap(A[j-1], A[j])
                flg = 1
                print_list(A)
        i += 1

n = int(input())
A = list(map(int,input().split()))

bubble_sort(A, n)

def print_list(A):
    print(*A, sep=" ")

def swap(a, b):
    return b, a

def bubble_sort(A, n):
    flg = 1 
    i = 0
    replace_num = 0
    while flg:
        flg = 0
        for j in range(n-1, i, -1):
            if A[j-1] > A[j]:
                A[j-1], A[j] = swap(A[j-1], A[j])
                flg = 1
                replace_num += 1 
        i += 1
    print_list(A)
    print(replace_num)

n = int(input())
A = list(map(int,input().split()))

bubble_sort(A, n)
