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

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

def bubbleSort(a, n):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                flag = 1
                count += 1
        i += 1
    print(*a)
    print(count)
                   
bubbleSort(a,n)