def bubble_sort(a, n):
    sw_num = 0
    is_swapped = True
    i = 0
    while is_swapped:
        is_swapped = False
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                is_swapped = True
                sw_num += 1
        i += 1

    return sw_num


n = int(input())
a = [int(i) for i in input().split()]

sw_num = bubble_sort(a, n)

print(' '.join([str(i) for i in a]))
print(sw_num) def bubble_sort(a, n):
    sw_num = 0
    is_swapped = True
    i = 0
    while is_swapped:
        is_swapped = False
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                is_swapped = True
                sw_num += 1
        i += 1

    return sw_num bubble_sort sw_num = 0 sw_num 0 is_swapped = True is_swapped True i = 0 i 0 while is_swapped:
        is_swapped = False
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                is_swapped = True
                sw_num += 1
        i += 1

     is_swapped is_swapped = False is_swapped False for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                is_swapped = True
                sw_num += 1
         j range(n-1, i, -1) range n-1 n 1 i -1 if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                is_swapped = True
                sw_num += 1
         a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 tmp = a[j] tmp a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = tmp a[j-1] a j-1 j 1 tmp is_swapped = True is_swapped True sw_num += 1 sw_num 1 i += 1 i 1 return sw_num sw_num a a n n 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()] sw_num = bubble_sort(a, n) sw_num bubble_sort(a, n) bubble_sort a n str(i) for i in a for i in a i a for i in a str(i) str i print(' '.join([str(i) for i in a])) print ' '.join([str(i) for i in a]) ' '.join ' ' join [str(i) for i in a] print(sw_num) print sw_num sw_num = bubble_sort(a, n) bubble_sort(a, n) sw_num a = [int(i) for i in input().split()] [int(i) for i in input().split()] a def bubble_sort(a, n):
    sw_num = 0
    is_swapped = True
    i = 0
    while is_swapped:
        is_swapped = False
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                is_swapped = True
                sw_num += 1
        i += 1

    return sw_num def bubble_sort(a, n):
    sw_num = 0
    is_swapped = True
    i = 0
    while is_swapped:
        is_swapped = False
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                is_swapped = True
                sw_num += 1
        i += 1

    return sw_num bubble_sort n = int(input()) int(input()) n
def bubble_sort(a, n):
    sw_num = 0
    is_swapped = True
    i = 0
    while is_swapped:
        is_swapped = False
        for j in range(n-1, i, -1):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                is_swapped = True
                sw_num += 1
        i += 1

    return sw_num


n = int(input())
a = [int(i) for i in input().split()]

sw_num = bubble_sort(a, n)

print(' '.join([str(i) for i in a]))
print(sw_num)
