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 show(array):
    for i in range(len(array)):
        if i != len(array) - 1:
            print(array[i], end=' ')
        else:
            print(array[i]) show for i in range(len(array)):
        if i != len(array) - 1:
            print(array[i], end=' ')
        else:
            print(array[i]) i range(len(array)) range len(array) len array if i != len(array) - 1:
            print(array[i], end=' ')
        else:
            print(array[i]) i != len(array) - 1 i len(array) - 1 len(array) len array 1 print(array[i], end=' ') print array[i] array i end=' ' end ' ' print(array[i]) print array[i] array i array array 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 bubbleSort flag = True flag True count = 0 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
     flag flag = False 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
     j sorted(range(1, len(array)), reverse=True) sorted range(1, len(array)) range 1 len(array) len array reverse=True reverse True if array[j] < array[j - 1]:
                array[j], array[j - 1] = [array[j - 1], array[j]]
                flag = True
                count += 1
     array[j] < array[j - 1] array[j] array j array[j - 1] array j - 1 j 1 array[j], array[j - 1] = [array[j - 1], array[j]] array[j] array j [array[j - 1], array[j]] array[j - 1] array j - 1 j 1 array[j] array j array[j - 1] array j - 1 j 1 flag = True flag True count += 1 count 1 show(array) show array return count count array array input() input int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x array = [int(x) for x in input().split()] array [int(x) for x in input().split()] print(bubbleSort(array)) print bubbleSort(array) bubbleSort array 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 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 bubbleSort array = [int(x) for x in input().split()] [int(x) for x in input().split()] array def show(array):
    for i in range(len(array)):
        if i != len(array) - 1:
            print(array[i], end=' ')
        else:
            print(array[i]) def show(array):
    for i in range(len(array)):
        if i != len(array) - 1:
            print(array[i], end=' ')
        else:
            print(array[i]) show
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))

