def bubble_sort(A):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, len(A))):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                count += 1
    return A, count

if __name__ == '__main__':
    n = int(input())
    array, count = bubble_sort(list(map(int, input().split())))
    print(' '.join(map(str, array)))
    print(count) def bubble_sort(A):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, len(A))):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                count += 1
    return A, count bubble_sort count = 0 count 0 flag = True flag True while flag:
        flag = False
        for j in reversed(range(1, len(A))):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                count += 1
     flag flag = False flag False for j in reversed(range(1, len(A))):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                count += 1
     j reversed(range(1, len(A))) reversed range(1, len(A)) range 1 len(A) len A if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                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 = True flag True count += 1 count 1 return A, count return A, count A count A A if __name__ == '__main__':
    n = int(input())
    array, count = bubble_sort(list(map(int, input().split())))
    print(' '.join(map(str, array)))
    print(count) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input array, count = bubble_sort(list(map(int, input().split()))) array bubble_sort(list(map(int, input().split()))) bubble_sort list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split count print(' '.join(map(str, array))) print ' '.join(map(str, array)) ' '.join ' ' join map(str, array) map str array print(count) print count def bubble_sort(A):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, len(A))):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                count += 1
    return A, count def bubble_sort(A):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, len(A))):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                count += 1
    return A, count bubble_sort count = bubble_sort(list(map(int, input().split()))) bubble_sort(list(map(int, input().split()))) count array, count = bubble_sort(list(map(int, input().split()))) bubble_sort(list(map(int, input().split()))) array n = int(input()) int(input()) n
def bubble_sort(A):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, len(A))):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                count += 1
    return A, count

if __name__ == '__main__':
    n = int(input())
    array, count = bubble_sort(list(map(int, input().split())))
    print(' '.join(map(str, array)))
    print(count)