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

