
n = int(input())
num_list = input().split()

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

    result = ' '.join(num_list)
    print(result)
    print(count)

bubbleSort(num_list, n) n = int(input()) n int(input()) int input() input num_list = input().split() num_list input().split() ().split () input split def bubbleSort(num_list, n):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if int(num_list[j]) < int(num_list[j-1]):
                a = num_list[j]
                b = num_list[j-1]
                num_list[j] = b
                num_list[j-1] = a
                flag = 1
                count += 1

    result = ' '.join(num_list)
    print(result)
    print(count) bubbleSort flag = 1 flag 1 count = 0 count 0 while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if int(num_list[j]) < int(num_list[j-1]):
                a = num_list[j]
                b = num_list[j-1]
                num_list[j] = b
                num_list[j-1] = a
                flag = 1
                count += 1

     flag flag = 0 flag 0 for j in range(n-1, 0, -1):
            if int(num_list[j]) < int(num_list[j-1]):
                a = num_list[j]
                b = num_list[j-1]
                num_list[j] = b
                num_list[j-1] = a
                flag = 1
                count += 1

     j range(n-1, 0, -1) range n-1 n 1 0 -1 if int(num_list[j]) < int(num_list[j-1]):
                a = num_list[j]
                b = num_list[j-1]
                num_list[j] = b
                num_list[j-1] = a
                flag = 1
                count += 1

     int(num_list[j]) < int(num_list[j-1]) int(num_list[j]) int num_list[j] num_list j int(num_list[j-1]) int num_list[j-1] num_list j-1 j 1 a = num_list[j] a num_list[j] num_list j b = num_list[j-1] b num_list[j-1] num_list j-1 j 1 num_list[j] = b num_list[j] num_list j b num_list[j-1] = a num_list[j-1] num_list j-1 j 1 a flag = 1 flag 1 count += 1 count 1 result = ' '.join(num_list) result ' '.join(num_list) ' '.join ' ' join num_list print(result) print result print(count) print count num_list num_list n n bubbleSort(num_list, n) bubbleSort num_list n num_list = input().split() input().split() num_list def bubbleSort(num_list, n):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if int(num_list[j]) < int(num_list[j-1]):
                a = num_list[j]
                b = num_list[j-1]
                num_list[j] = b
                num_list[j-1] = a
                flag = 1
                count += 1

    result = ' '.join(num_list)
    print(result)
    print(count) def bubbleSort(num_list, n):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if int(num_list[j]) < int(num_list[j-1]):
                a = num_list[j]
                b = num_list[j-1]
                num_list[j] = b
                num_list[j-1] = a
                flag = 1
                count += 1

    result = ' '.join(num_list)
    print(result)
    print(count) bubbleSort n = int(input()) int(input()) n

n = int(input())
num_list = input().split()

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

    result = ' '.join(num_list)
    print(result)
    print(count)

bubbleSort(num_list, n)