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


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

A,count = bubbleSort(A,N)

for i in range(len(A)):  # output
    if i == len(A) - 1:
        print(A[i])
    else:
        print(A[i], end=' ')

print(count) def bubbleSort(A,N):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(N-1,i,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A,count bubbleSort flag = 1 flag 1 i = 0 i 0 count = 0 count 0 while flag:
        flag = 0
        for j in range(N-1,i,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
     flag flag = 0 flag 0 for j in range(N-1,i,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
         j range(N-1,i,-1) range N-1 N 1 i -1 if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
         A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 tmp = A[j] tmp A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = tmp A[j-1] A j-1 j 1 tmp flag = 1 flag 1 count += 1 count 1 i += 1 i 1 return A,count return A,count A count A A N N 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 for i in range(len(A)):  # output
    if i == len(A) - 1:
        print(A[i])
    else:
        print(A[i], end=' ') i range(len(A)) range len(A) len A if i == len(A) - 1:
        print(A[i])
    else:
        print(A[i], end=' ') i == len(A) - 1 i len(A) - 1 len(A) len A 1 print(A[i]) print A[i] A i print(A[i], end=' ') print A[i] A i end=' ' end ' ' print(count) print count N = int(input()) int(input()) N def bubbleSort(A,N):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(N-1,i,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A,count def bubbleSort(A,N):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(N-1,i,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A,count bubbleSort A = list(map(int,input().split(' '))) list(map(int,input().split(' '))) A count = bubbleSort(A,N) bubbleSort(A,N) count A,count = bubbleSort(A,N) bubbleSort(A,N) A
def bubbleSort(A,N):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(N-1,i,-1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A,count


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

A,count = bubbleSort(A,N)

for i in range(len(A)):  # output
    if i == len(A) - 1:
        print(A[i])
    else:
        print(A[i], end=' ')

print(count)