N = int(input())
A = list(map(int,input().split()))
flag = True
ans = 0
while flag:
    flag = False
    for j in range(N-1,0,-1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1],A[j]
            flag = True
            ans += 1
print(*A)
print(ans)
 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 = True flag True ans = 0 ans 0 while flag:
    flag = False
    for j in range(N-1,0,-1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1],A[j]
            flag = True
            ans += 1 flag flag = False flag False for j in range(N-1,0,-1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1],A[j]
            flag = True
            ans += 1 j range(N-1,0,-1) range N-1 N 1 0 -1 if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1],A[j]
            flag = True
            ans += 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 flag = True flag True ans += 1 ans 1 print(*A) print *A A print(ans) print ans ans += 1 1 ans flag = False False flag ans = 0 0 ans N = int(input()) int(input()) N flag = True True flag A = list(map(int,input().split())) list(map(int,input().split())) A flag = True True flag
N = int(input())
A = list(map(int,input().split()))
flag = True
ans = 0
while flag:
    flag = False
    for j in range(N-1,0,-1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1],A[j]
            flag = True
            ans += 1
print(*A)
print(ans)

