import sys

n = int(raw_input())
A = map(int, sys.stdin.readline().split())

cnt = 0

for i in xrange(len(A)-1):
    for j in xrange(len(A)-1, i, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            cnt += 1

for x in A:
	print x,
print 
print cnt import sys sys n = int(raw_input()) n int(raw_input()) int raw_input() raw_input A = map(int, sys.stdin.readline().split()) A map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split cnt = 0 cnt 0 for i in xrange(len(A)-1):
    for j in xrange(len(A)-1, i, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            cnt += 1 i xrange(len(A)-1) xrange len(A)-1 len(A) len A 1 for j in xrange(len(A)-1, i, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            cnt += 1 j xrange(len(A)-1, i, -1) xrange len(A)-1 len(A) len A 1 i -1 if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            cnt += 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 cnt += 1 cnt 1 for x in A:
	print x, x A print x print print A = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) A n = int(raw_input()) int(raw_input()) n cnt += 1 1 cnt cnt = 0 0 cnt
import sys

n = int(raw_input())
A = map(int, sys.stdin.readline().split())

cnt = 0

for i in xrange(len(A)-1):
    for j in xrange(len(A)-1, i, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            cnt += 1

for x in A:
	print x,
print 
print cnt