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