#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def bubble_sort(A):
    swap_count = 0
    for i in range(len(A)):
        for x in range(len(A)-1, i, -1):
            if A[x] < A[x-1]:
                swap_count += 1
                A[x], A[x-1] = A[x-1], A[x]

    return swap_count

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

swap_count = bubble_sort(A)
s_list = list(map(str, A))
print(' '.join(s_list))
print(swap_count)
 import sys sys def bubble_sort(A):
    swap_count = 0
    for i in range(len(A)):
        for x in range(len(A)-1, i, -1):
            if A[x] < A[x-1]:
                swap_count += 1
                A[x], A[x-1] = A[x-1], A[x]

    return swap_count bubble_sort swap_count = 0 swap_count 0 for i in range(len(A)):
        for x in range(len(A)-1, i, -1):
            if A[x] < A[x-1]:
                swap_count += 1
                A[x], A[x-1] = A[x-1], A[x]

     i range(len(A)) range len(A) len A for x in range(len(A)-1, i, -1):
            if A[x] < A[x-1]:
                swap_count += 1
                A[x], A[x-1] = A[x-1], A[x]

     x range(len(A)-1, i, -1) range len(A)-1 len(A) len A 1 i -1 if A[x] < A[x-1]:
                swap_count += 1
                A[x], A[x-1] = A[x-1], A[x]

     A[x] < A[x-1] A[x] A x A[x-1] A x-1 x 1 swap_count += 1 swap_count 1 A[x], A[x-1] = A[x-1], A[x] A[x] A x A[x-1] A x-1 x 1 A[x-1] A x-1 x 1 A[x] A x return swap_count swap_count A A n = int(sys.stdin.readline()) n int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline A = list(map(int, sys.stdin.readline().split())) A list(map(int, sys.stdin.readline().split())) list map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split swap_count = bubble_sort(A) swap_count bubble_sort(A) bubble_sort A s_list = list(map(str, A)) s_list list(map(str, A)) list map(str, A) map str A print(' '.join(s_list)) print ' '.join(s_list) ' '.join ' ' join s_list print(swap_count) print swap_count def bubble_sort(A):
    swap_count = 0
    for i in range(len(A)):
        for x in range(len(A)-1, i, -1):
            if A[x] < A[x-1]:
                swap_count += 1
                A[x], A[x-1] = A[x-1], A[x]

    return swap_count def bubble_sort(A):
    swap_count = 0
    for i in range(len(A)):
        for x in range(len(A)-1, i, -1):
            if A[x] < A[x-1]:
                swap_count += 1
                A[x], A[x-1] = A[x-1], A[x]

    return swap_count bubble_sort n = int(sys.stdin.readline()) int(sys.stdin.readline()) n A = list(map(int, sys.stdin.readline().split())) list(map(int, sys.stdin.readline().split())) A s_list = list(map(str, A)) list(map(str, A)) s_list swap_count = bubble_sort(A) bubble_sort(A) swap_count
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def bubble_sort(A):
    swap_count = 0
    for i in range(len(A)):
        for x in range(len(A)-1, i, -1):
            if A[x] < A[x-1]:
                swap_count += 1
                A[x], A[x-1] = A[x-1], A[x]

    return swap_count

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

swap_count = bubble_sort(A)
s_list = list(map(str, A))
print(' '.join(s_list))
print(swap_count)

