from typing import List


def bublle_sort(A: List[int]) -> List[int]:
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in reversed(range(1, N)):
            if A[i] < A[i - 1]:
                A[i], A[i - 1] = A[i - 1], A[i]
                cnt += 1
                flg = True
    return A, cnt


N = int(input())
A = [int(i) for i in input().split()]
A, cnt = bublle_sort(A)
print(' '.join(map(str, A)))
print(cnt)
 from typing import List def bublle_sort(A: List[int]) -> List[int]:
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in reversed(range(1, N)):
            if A[i] < A[i - 1]:
                A[i], A[i - 1] = A[i - 1], A[i]
                cnt += 1
                flg = True
    return A, cnt bublle_sort cnt = 0 cnt 0 flg = True flg True while flg:
        flg = False
        for i in reversed(range(1, N)):
            if A[i] < A[i - 1]:
                A[i], A[i - 1] = A[i - 1], A[i]
                cnt += 1
                flg = True
     flg flg = False flg False for i in reversed(range(1, N)):
            if A[i] < A[i - 1]:
                A[i], A[i - 1] = A[i - 1], A[i]
                cnt += 1
                flg = True
     i reversed(range(1, N)) reversed range(1, N) range 1 N if A[i] < A[i - 1]:
                A[i], A[i - 1] = A[i - 1], A[i]
                cnt += 1
                flg = True
     A[i] < A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 A[i], A[i - 1] = A[i - 1], A[i] A[i] A i A[i - 1] A i - 1 i 1 A[i - 1] A i - 1 i 1 A[i] A i cnt += 1 cnt 1 flg = True flg True return A, cnt return A, cnt A cnt A: List[int] A N = int(input()) N int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A = [int(i) for i in input().split()] A [int(i) for i in input().split()] A, cnt = bublle_sort(A) A bublle_sort(A) bublle_sort A cnt print(' '.join(map(str, A))) print ' '.join(map(str, A)) ' '.join ' ' join map(str, A) map str A print(cnt) print cnt cnt = bublle_sort(A) bublle_sort(A) cnt N = int(input()) int(input()) N A = [int(i) for i in input().split()] [int(i) for i in input().split()] A def bublle_sort(A: List[int]) -> List[int]:
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in reversed(range(1, N)):
            if A[i] < A[i - 1]:
                A[i], A[i - 1] = A[i - 1], A[i]
                cnt += 1
                flg = True
    return A, cnt def bublle_sort(A: List[int]) -> List[int]:
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in reversed(range(1, N)):
            if A[i] < A[i - 1]:
                A[i], A[i - 1] = A[i - 1], A[i]
                cnt += 1
                flg = True
    return A, cnt bublle_sort A, cnt = bublle_sort(A) bublle_sort(A) A
from typing import List


def bublle_sort(A: List[int]) -> List[int]:
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in reversed(range(1, N)):
            if A[i] < A[i - 1]:
                A[i], A[i - 1] = A[i - 1], A[i]
                cnt += 1
                flg = True
    return A, cnt


N = int(input())
A = [int(i) for i in input().split()]
A, cnt = bublle_sort(A)
print(' '.join(map(str, A)))
print(cnt)

