def main():
    N = int(input())
    A = list(map(int, input().split(' ')))

    A, count = bubbleSort(A, N)

    print(' '.join([str(a) for a in A]))
    print(count)

def bubbleSort(A, N):
    flag = True
    count = 0

    while flag:
        flag = False

        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = True

    return A, count

if __name__ == '__main__':
    main() def main():
    N = int(input())
    A = list(map(int, input().split(' ')))

    A, count = bubbleSort(A, N)

    print(' '.join([str(a) for a in A]))
    print(count) main 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 ' ' A, count = bubbleSort(A, N) A bubbleSort(A, N) bubbleSort A N count str(a) for a in A for a in A a A for a in A str(a) str a print(' '.join([str(a) for a in A])) print ' '.join([str(a) for a in A]) ' '.join ' ' join [str(a) for a in A] print(count) print count def bubbleSort(A, N):
    flag = True
    count = 0

    while flag:
        flag = False

        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = True

    return A, count bubbleSort flag = True flag True count = 0 count 0 while flag:
        flag = False

        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = True

     flag flag = False flag False for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = True

     j range(N-1, 0, -1) range N-1 N 1 0 -1 if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = True

     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 count += 1 count 1 flag = True flag True return A, count return A, count A count A A N N if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N = int(input())
    A = list(map(int, input().split(' ')))

    A, count = bubbleSort(A, N)

    print(' '.join([str(a) for a in A]))
    print(count) def main():
    N = int(input())
    A = list(map(int, input().split(' ')))

    A, count = bubbleSort(A, N)

    print(' '.join([str(a) for a in A]))
    print(count) main def bubbleSort(A, N):
    flag = True
    count = 0

    while flag:
        flag = False

        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = True

    return A, count def bubbleSort(A, N):
    flag = True
    count = 0

    while flag:
        flag = False

        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = True

    return A, count bubbleSort
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))

    A, count = bubbleSort(A, N)

    print(' '.join([str(a) for a in A]))
    print(count)

def bubbleSort(A, N):
    flag = True
    count = 0

    while flag:
        flag = False

        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = True

    return A, count

if __name__ == '__main__':
    main()