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

def bubbleSort(A, N):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                i += 1

    print(' '.join(map(str, A)))
    print(i)

if __name__ == '__main__':
    main() def main():
    N = int(input())
    A = list(map(int, input().split()))
    bubbleSort(A, N) 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 bubbleSort(A, N) bubbleSort A N def bubbleSort(A, N):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                i += 1

    print(' '.join(map(str, A)))
    print(i) bubbleSort flag = 1 flag 1 i = 0 i 0 while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                i += 1

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

     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]
                flag = 1
                i += 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 = 1 flag 1 i += 1 i 1 print(' '.join(map(str, A))) print ' '.join(map(str, A)) ' '.join ' ' join map(str, A) map str A print(i) print i A A N N if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def bubbleSort(A, N):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                i += 1

    print(' '.join(map(str, A)))
    print(i) def bubbleSort(A, N):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                i += 1

    print(' '.join(map(str, A)))
    print(i) bubbleSort def main():
    N = int(input())
    A = list(map(int, input().split()))
    bubbleSort(A, N) def main():
    N = int(input())
    A = list(map(int, input().split()))
    bubbleSort(A, N) main
def main():
    N = int(input())
    A = list(map(int, input().split()))
    bubbleSort(A, N)

def bubbleSort(A, N):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                i += 1

    print(' '.join(map(str, A)))
    print(i)

if __name__ == '__main__':
    main()