#!/usr/bin/env python
#-*- coding:utf-8 -*-

N = int(raw_input())

A = map(int,raw_input().split())
counter = 0 
for i in range(len(A)):
    for j in range(len(A) - 1, 0, -1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1], A[j]
            counter += 1

print ' '.join(map(str,A))
print counter N = int(raw_input()) N int(raw_input()) int raw_input() raw_input A = map(int,raw_input().split()) A map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split counter = 0 counter 0 for i in range(len(A)):
    for j in range(len(A) - 1, 0, -1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1], A[j]
            counter += 1 i range(len(A)) range len(A) len A for j in range(len(A) - 1, 0, -1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1], A[j]
            counter += 1 j range(len(A) - 1, 0, -1) range len(A) - 1 len(A) len A 1 0 -1 if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1], A[j]
            counter += 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 counter += 1 counter 1 print ' '.join(map(str,A)) ' '.join ' ' join map(str,A) map str A print counter = 0 0 counter A = map(int,raw_input().split()) map(int,raw_input().split()) A N = int(raw_input()) int(raw_input()) N counter += 1 1 counter
#!/usr/bin/env python
#-*- coding:utf-8 -*-

N = int(raw_input())

A = map(int,raw_input().split())
counter = 0 
for i in range(len(A)):
    for j in range(len(A) - 1, 0, -1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1], A[j]
            counter += 1

print ' '.join(map(str,A))
print counter