# -*- coding: UTF-8 -*-
#Bubble Sort

#標準入力から
N = int(input()) #要素数
A = list(map(int,input().split())) #ソート対象（スペース区切り→配列に展開）

#print('input')
#print(N)
#print(A)

flag = 1
i = 0
cnt = 0

#Sort処理（自分メモ：flagが0になったらループを抜ける）
while flag:
    flag = 0
    for j in reversed(range(i+1,N)):
        if A[j] < A[j-1]:
            tmp = A[j-1]
            A[j-1] = A[j]
            A[j] = tmp
            flag = 1
            cnt += 1
    i += 1

#print('output')
#print(A)
print(' '.join(map(str,A)))
print(cnt)
 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 flag = 1 flag 1 i = 0 i 0 cnt = 0 cnt 0 while flag:
    flag = 0
    for j in reversed(range(i+1,N)):
        if A[j] < A[j-1]:
            tmp = A[j-1]
            A[j-1] = A[j]
            A[j] = tmp
            flag = 1
            cnt += 1
    i += 1

#print('output')
#print(A) flag flag = 0 flag 0 for j in reversed(range(i+1,N)):
        if A[j] < A[j-1]:
            tmp = A[j-1]
            A[j-1] = A[j]
            A[j] = tmp
            flag = 1
            cnt += 1
     j reversed(range(i+1,N)) reversed range(i+1,N) range i+1 i 1 N if A[j] < A[j-1]:
            tmp = A[j-1]
            A[j-1] = A[j]
            A[j] = tmp
            flag = 1
            cnt += 1
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 tmp = A[j-1] tmp A[j-1] A j-1 j 1 A[j-1] = A[j] A[j-1] A j-1 j 1 A[j] A j A[j] = tmp A[j] A j tmp flag = 1 flag 1 cnt += 1 cnt 1 i += 1 i 1 print(' '.join(map(str,A))) print ' '.join(map(str,A)) ' '.join ' ' join map(str,A) map str A print(cnt) print cnt cnt += 1 1 cnt tmp = A[j-1] A[j-1] tmp flag = 1 1 flag cnt = 0 0 cnt i += 1 1 i N = int(input()) int(input()) N flag = 0 0 flag flag = 1 1 flag i = 0 0 i A = list(map(int,input().split())) list(map(int,input().split())) A
# -*- coding: UTF-8 -*-
#Bubble Sort

#標準入力から
N = int(input()) #要素数
A = list(map(int,input().split())) #ソート対象（スペース区切り→配列に展開）

#print('input')
#print(N)
#print(A)

flag = 1
i = 0
cnt = 0

#Sort処理（自分メモ：flagが0になったらループを抜ける）
while flag:
    flag = 0
    for j in reversed(range(i+1,N)):
        if A[j] < A[j-1]:
            tmp = A[j-1]
            A[j-1] = A[j]
            A[j] = tmp
            flag = 1
            cnt += 1
    i += 1

#print('output')
#print(A)
print(' '.join(map(str,A)))
print(cnt)

