N = int(eval(input()))

A = [int(x) for x in input().split(" ")]

flag = True

swap_count = 0

i = 0

while flag:

    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

            swap_count += 1

    i += 1



print((*A))

print(swap_count)
1# bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A

2#   flag = 1 // 逆の隣接要素が存在する

3#   while flag

4#     flag = 0

5#     for j が N-1 から 1 まで

6#       if A[j] < A[j-1]

7#         A[j] と A[j-1] を交換

8#         flag = 1



n = int(eval(input()))

nums = list(map(int, input().split()))

count = 0

flag = True

while flag:

    flag = False

    for j in range(n-1, 0, -1):

        if nums[j] < nums[j-1]:

            nums[j], nums[j-1] = nums[j-1], nums[j]

            count += 1

            flag = True



print((*nums))

print(count)

N = int(eval(input()))
A = [int(x) for x in input().split(" ")]
flag = True
swap_count = 0
i = 0
while flag:
    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
            swap_count += 1
    i += 1
print((*A))
print(swap_count)

1  # bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A
2  #   flag = 1 // 逆の隣接要素が存在する
3  #   while flag
4  #     flag = 0
5  #     for j が N-1 から 1 まで
6  #       if A[j] < A[j-1]
7  #         A[j] と A[j-1] を交換
8  #         flag = 1
n = int(eval(input()))
nums = list(map(int, input().split()))
count = 0
flag = True
while flag:
    flag = False
    for j in range(n - 1, 0, -1):
        if nums[j] < nums[j - 1]:
            nums[j], nums[j - 1] = nums[j - 1], nums[j]
            count += 1
            flag = True
print((*nums))
print(count)

-N = int(eval(input())) -A = [int(x) for x in input().split(" ")] +1  # bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A +2  #   flag = 1 // 逆の隣接要素が存在する +3  #   while flag +4  #     flag = 0 +5  #     for j が N-1 から 1 まで +6  #       if A[j] < A[j-1] +7  #         A[j] と A[j-1] を交換 +8  #         flag = 1 +n = int(eval(input())) +nums = list(map(int, input().split())) +count = 0 -swap_count = 0 -i = 0 -    for j in range(N - 1, i, -1): -        if A[j] < A[j - 1]: -            A[j], A[j - 1] = A[j - 1], A[j] +    for j in range(n - 1, 0, -1): +        if nums[j] < nums[j - 1]: +            nums[j], nums[j - 1] = nums[j - 1], nums[j] +            count += 1 -            swap_count += 1 -    i += 1 -print((*A)) -print(swap_count) +print((*nums)) +print(count)