def show(array):

    for i in range(len(array)):

        if i != len(array) - 1:

            print(array[i], end=' ')

        else:

            print(array[i])





def bubbleSort(array):

    flag = True

    count = 0

    while flag:

        flag = False

        for j in sorted(range(1, len(array)), reverse=True):

            if array[j] < array[j - 1]:

                array[j], array[j - 1] = [array[j - 1], array[j]]

                flag = True

                count += 1

    show(array)

    return count





input()

array = [int(x) for x in input().split()]



print(bubbleSort(array))



def bubbleSort(array):

    n = len(array)

    cnt = 0

    flag = True

    while flag:

        flag = False

        for i in range(n-1, 0, -1):

            if array[i-1] > array[i]:

                array[i-1], array[i] = array[i], array[i-1]

                flag = True

                cnt += 1

    return (array, cnt)



n = int(eval(input()))

array = [int(x) for x in input().split()]



resultArray, cnt = bubbleSort(array)



print((*resultArray))

print(cnt)

def show(array):
    for i in range(len(array)):
        if i != len(array) - 1:
            print(array[i], end=" ")
        else:
            print(array[i])


def bubbleSort(array):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in sorted(range(1, len(array)), reverse=True):
            if array[j] < array[j - 1]:
                array[j], array[j - 1] = [array[j - 1], array[j]]
                flag = True
                count += 1
    show(array)
    return count


input()
array = [int(x) for x in input().split()]
print(bubbleSort(array))

def bubbleSort(array):
    n = len(array)
    cnt = 0
    flag = True
    while flag:
        flag = False
        for i in range(n - 1, 0, -1):
            if array[i - 1] > array[i]:
                array[i - 1], array[i] = array[i], array[i - 1]
                flag = True
                cnt += 1
    return (array, cnt)


n = int(eval(input()))
array = [int(x) for x in input().split()]
resultArray, cnt = bubbleSort(array)
print((*resultArray))
print(cnt)

-def show(array): -    for i in range(len(array)): -        if i != len(array) - 1: -            print(array[i], end=" ") -        else: -            print(array[i]) +def bubbleSort(array): +    n = len(array) +    cnt = 0 +    flag = True +    while flag: +        flag = False +        for i in range(n - 1, 0, -1): +            if array[i - 1] > array[i]: +                array[i - 1], array[i] = array[i], array[i - 1] +                flag = True +                cnt += 1 +    return (array, cnt) -def bubbleSort(array): -    flag = True -    count = 0 -    while flag: -        flag = False -        for j in sorted(range(1, len(array)), reverse=True): -            if array[j] < array[j - 1]: -                array[j], array[j - 1] = [array[j - 1], array[j]] -                flag = True -                count += 1 -    show(array) -    return count - - -input() +n = int(eval(input())) -print(bubbleSort(array)) +resultArray, cnt = bubbleSort(array) +print((*resultArray)) +print(cnt)