N = int(input())
A = [int(n) for n in input().split()]
flg = 1
cnt = 0
while flg:
    flg = 0
    for i in range(N-1, 0, -1):
        if A[i] < A[i-1]:
            t = A[i]
            A[i] = A[i-1]
            A[i-1] = t
            flg = 1
            cnt += 1
for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print(A[i], end=" ")
print(cnt) N = int(input()) N int(input()) int input() input int(n) for n in input().split() for n in input().split() n input().split() ().split () input split for n in input().split() int(n) int n A = [int(n) for n in input().split()] A [int(n) for n in input().split()] flg = 1 flg 1 cnt = 0 cnt 0 while flg:
    flg = 0
    for i in range(N-1, 0, -1):
        if A[i] < A[i-1]:
            t = A[i]
            A[i] = A[i-1]
            A[i-1] = t
            flg = 1
            cnt += 1 flg flg = 0 flg 0 for i in range(N-1, 0, -1):
        if A[i] < A[i-1]:
            t = A[i]
            A[i] = A[i-1]
            A[i-1] = t
            flg = 1
            cnt += 1 i range(N-1, 0, -1) range N-1 N 1 0 -1 if A[i] < A[i-1]:
            t = A[i]
            A[i] = A[i-1]
            A[i-1] = t
            flg = 1
            cnt += 1 A[i] < A[i-1] A[i] A i A[i-1] A i-1 i 1 t = A[i] t A[i] A i A[i] = A[i-1] A[i] A i A[i-1] A i-1 i 1 A[i-1] = t A[i-1] A i-1 i 1 t flg = 1 flg 1 cnt += 1 cnt 1 for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print(A[i], end=" ") i range(N) range N if i == N - 1:
        print(A[i])
    else:
        print(A[i], end=" ") i == N - 1 i N - 1 N 1 print(A[i]) print A[i] A i print(A[i], end=" ") print A[i] A i end=" " end " " print(cnt) print cnt flg = 0 0 flg N = int(input()) int(input()) N A = [int(n) for n in input().split()] [int(n) for n in input().split()] A cnt = 0 0 cnt cnt += 1 1 cnt flg = 1 1 flg t = A[i] A[i] t flg = 1 1 flg
N = int(input())
A = [int(n) for n in input().split()]
flg = 1
cnt = 0
while flg:
    flg = 0
    for i in range(N-1, 0, -1):
        if A[i] < A[i-1]:
            t = A[i]
            A[i] = A[i-1]
            A[i-1] = t
            flg = 1
            cnt += 1
for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print(A[i], end=" ")
print(cnt)