n = int(input())
A = list(map(int,input().split()))
f = 1 
c = 0

while f == 1:
    f = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            inc = A[j]
            A[j] = A[j-1] 
            A[j-1] = inc
            f = 1
            c += 1
print(" ".join(map(str,A)))
print(c) 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 f = 1 f 1 c = 0 c 0 while f == 1:
    f = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            inc = A[j]
            A[j] = A[j-1] 
            A[j-1] = inc
            f = 1
            c += 1 f == 1 f 1 f = 0 f 0 for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            inc = A[j]
            A[j] = A[j-1] 
            A[j-1] = inc
            f = 1
            c += 1 j range(n-1,0,-1) range n-1 n 1 0 -1 if A[j] < A[j-1]:
            inc = A[j]
            A[j] = A[j-1] 
            A[j-1] = inc
            f = 1
            c += 1 A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 inc = A[j] inc A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = inc A[j-1] A j-1 j 1 inc f = 1 f 1 c += 1 c 1 print(" ".join(map(str,A))) print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print(c) print c f = 1 1 f c = 0 0 c c += 1 1 c inc = A[j] A[j] inc f = 1 1 f A = list(map(int,input().split())) list(map(int,input().split())) A n = int(input()) int(input()) n f = 0 0 f
n = int(input())
A = list(map(int,input().split()))
f = 1 
c = 0

while f == 1:
    f = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            inc = A[j]
            A[j] = A[j-1] 
            A[j-1] = inc
            f = 1
            c += 1
print(" ".join(map(str,A)))
print(c)