def bubblesort(N, A):
    c, flag = 0, 1
    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]
                c += 1
                flag = True
    return (A, c)

A, c = bubblesort(int(input()), list(map(int, input().split())))
print(' '.join([str(v) for v in A]))
print(c) def bubblesort(N, A):
    c, flag = 0, 1
    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]
                c += 1
                flag = True
    return (A, c) bubblesort c, flag = 0, 1 c 0 flag 1 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]
                c += 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]
                c += 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]
                c += 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 c += 1 c 1 flag = True flag True return (A, c) (A, c) A c N N A A A, c = bubblesort(int(input()), list(map(int, input().split()))) A bubblesort(int(input()), list(map(int, input().split()))) bubblesort int(input()) int input() input list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c str(v) for v in A for v in A v A for v in A str(v) str v print(' '.join([str(v) for v in A])) print ' '.join([str(v) for v in A]) ' '.join ' ' join [str(v) for v in A] print(c) print c def bubblesort(N, A):
    c, flag = 0, 1
    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]
                c += 1
                flag = True
    return (A, c) def bubblesort(N, A):
    c, flag = 0, 1
    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]
                c += 1
                flag = True
    return (A, c) bubblesort c = bubblesort(int(input()), list(map(int, input().split()))) bubblesort(int(input()), list(map(int, input().split()))) c A, c = bubblesort(int(input()), list(map(int, input().split()))) bubblesort(int(input()), list(map(int, input().split()))) A
def bubblesort(N, A):
    c, flag = 0, 1
    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]
                c += 1
                flag = True
    return (A, c)

A, c = bubblesort(int(input()), list(map(int, input().split())))
print(' '.join([str(v) for v in A]))
print(c)