n = int(input())
A = [int(i) for i in input().split(' ')]
# A = '0 33 43 62 29 0 8 52 56 56 19 11 51 43 5 8 93 30 66 69'.split(' ')
# A = [int(i) for i in A]

def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print()

def bubble_sort(A, n):
    i = 0
    counter = 0
    while i <= n - 1:
        j = n - 1
        while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
        i += 1
    trace(A)
    print(counter)

bubble_sort(A, 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(' ')] def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print() trace for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
     index v enumerate(A) enumerate A print(v, end='') print v end='' end '' if index != len(A) - 1:
            print(' ', end='')
     index != len(A) - 1 index len(A) - 1 len(A) len A 1 print(' ', end='') print ' ' end='' end '' print() print A A def bubble_sort(A, n):
    i = 0
    counter = 0
    while i <= n - 1:
        j = n - 1
        while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
        i += 1
    trace(A)
    print(counter) bubble_sort i = 0 i 0 counter = 0 counter 0 while i <= n - 1:
        j = n - 1
        while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
        i += 1
     i <= n - 1 i n - 1 n 1 j = n - 1 j n - 1 n 1 while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
         j >= i + 1 j i + 1 i 1 if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
             A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j counter += 1 counter 1 j -= 1 j 1 i += 1 i 1 trace(A) trace A print(counter) print counter A A n n bubble_sort(A, n) bubble_sort A n def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print() def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print() trace def bubble_sort(A, n):
    i = 0
    counter = 0
    while i <= n - 1:
        j = n - 1
        while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
        i += 1
    trace(A)
    print(counter) def bubble_sort(A, n):
    i = 0
    counter = 0
    while i <= n - 1:
        j = n - 1
        while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
        i += 1
    trace(A)
    print(counter) bubble_sort A = [int(i) for i in input().split(' ')] [int(i) for i in input().split(' ')] A n = int(input()) int(input()) n
n = int(input())
A = [int(i) for i in input().split(' ')]
# A = '0 33 43 62 29 0 8 52 56 56 19 11 51 43 5 8 93 30 66 69'.split(' ')
# A = [int(i) for i in A]

def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print()

def bubble_sort(A, n):
    i = 0
    counter = 0
    while i <= n - 1:
        j = n - 1
        while j >= i + 1:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                counter += 1
            j -= 1
        i += 1
    trace(A)
    print(counter)

bubble_sort(A, n)