n = int(input())
s = input()
A = list(map(int,s.split()))
flag = 1
cnt = 0

while(flag == 1):
    flag = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1
            cnt += 1

for k in range(0,len(A)-1):
    print(A[k],end=" ")
print(A[len(A)-1])
print (cnt) n = int(input()) n int(input()) int input() input s = input() s input() input A = list(map(int,s.split())) A list(map(int,s.split())) list map(int,s.split()) map int s.split() s.split s split flag = 1 flag 1 cnt = 0 cnt 0 while(flag == 1):
    flag = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1
            cnt += 1 flag == 1 flag 1 flag = 0 flag 0 for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1
            cnt += 1 j range(n-1,0,-1) range n-1 n 1 0 -1 if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = 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] 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 cnt += 1 cnt 1 for k in range(0,len(A)-1):
    print(A[k],end=" ") k range(0,len(A)-1) range 0 len(A)-1 len(A) len A 1 print(A[k],end=" ") print A[k] A k end=" " end " " print(A[len(A)-1]) print A[len(A)-1] A len(A)-1 len(A) len A 1 print (cnt) print cnt flag = 1 1 flag cnt = 0 0 cnt flag = 0 0 flag s = input() input() s tmp = A[j] A[j] tmp cnt += 1 1 cnt n = int(input()) int(input()) n flag = 1 1 flag A = list(map(int,s.split())) list(map(int,s.split())) A
n = int(input())
s = input()
A = list(map(int,s.split()))
flag = 1
cnt = 0

while(flag == 1):
    flag = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1
            cnt += 1

for k in range(0,len(A)-1):
    print(A[k],end=" ")
print(A[len(A)-1])
print (cnt)