#!/usr/bin/env python

def bubbleSort(A, N):
    swap_count = 0

    flag = True
    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]
                swap_count += 1
                flag = True
    ans = " ".join(map(str, A))
    print(ans)
    print(swap_count)

def main():
    size = int(input())
    line = list(map(int, input().split()))
    bubbleSort(line, size)

if __name__ == '__main__':
    main() def bubbleSort(A, N):
    swap_count = 0

    flag = True
    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]
                swap_count += 1
                flag = True
    ans = " ".join(map(str, A))
    print(ans)
    print(swap_count) bubbleSort swap_count = 0 swap_count 0 flag = True flag True 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]
                swap_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]
                swap_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]
                swap_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 swap_count += 1 swap_count 1 flag = True flag True ans = " ".join(map(str, A)) ans " ".join(map(str, A)) " ".join " " join map(str, A) map str A print(ans) print ans print(swap_count) print swap_count A A N N def main():
    size = int(input())
    line = list(map(int, input().split()))
    bubbleSort(line, size) main size = int(input()) size int(input()) int input() input line = list(map(int, input().split())) line list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bubbleSort(line, size) bubbleSort line size if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def bubbleSort(A, N):
    swap_count = 0

    flag = True
    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]
                swap_count += 1
                flag = True
    ans = " ".join(map(str, A))
    print(ans)
    print(swap_count) def bubbleSort(A, N):
    swap_count = 0

    flag = True
    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]
                swap_count += 1
                flag = True
    ans = " ".join(map(str, A))
    print(ans)
    print(swap_count) bubbleSort def main():
    size = int(input())
    line = list(map(int, input().split()))
    bubbleSort(line, size) def main():
    size = int(input())
    line = list(map(int, input().split()))
    bubbleSort(line, size) main
#!/usr/bin/env python

def bubbleSort(A, N):
    swap_count = 0

    flag = True
    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]
                swap_count += 1
                flag = True
    ans = " ".join(map(str, A))
    print(ans)
    print(swap_count)

def main():
    size = int(input())
    line = list(map(int, input().split()))
    bubbleSort(line, size)

if __name__ == '__main__':
    main()