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.
n = int(input())
nums = list(map(int, input().split()))
count = 0

for i in range(n):
    for j in range(i + 1, n):
        if (nums[j] < nums[i]):
            temp = nums[j]
            nums[j] = nums[i]
            nums[i] = temp
            count += 1

print(count)
print(' '.join([str(i) for i in nums]))


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

def bubble_sort(a):
    global cnt
    for i in range(len(a)):
        l = 0
        r = 1

        while r < len(a):
            if a[l] > a[r]:
                a[l], a[r] = a[r], a[l]
                cnt += 1
            l += 1
            r += 1


    
    #     for j in range(i + 1, len(a)):
    #         if a[i] > a[j]:
    #             a[i], a[j] = a[j], a[i]

bubble_sort(a)
print(*a)
print(cnt)

