# Aizu Problem ALDS_1_2_A: Bubble Sort
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def printA(A):
    print(' '.join([str(a) for a in A]))

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

        
N = int(input())
A = [int(_) for _ in input().split()]
A, swaps = bubble_sort(A)
printA(A)
print(swaps) import sys, math, os sys math os PYDEV = os.environ.get('PYDEV') PYDEV os.environ.get('PYDEV') os.environ.get os.environ os environ get 'PYDEV' if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt") PYDEV=="True" PYDEV "True" sys.stdin = open("sample-input2.txt", "rt") sys.stdin sys stdin open("sample-input2.txt", "rt") open "sample-input2.txt" "rt" def printA(A):
    print(' '.join([str(a) for a in A])) printA str(a) for a in A for a in A a A for a in A str(a) str a print(' '.join([str(a) for a in A])) print ' '.join([str(a) for a in A]) ' '.join ' ' join [str(a) for a in A] A A def bubble_sort(A):
    swaps = 0
    for i in range(len(A) - 1):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                swaps += 1
                A[j], A[j - 1] = A[j - 1], A[j]
    return A, swaps

         bubble_sort swaps = 0 swaps 0 for i in range(len(A) - 1):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                swaps += 1
                A[j], A[j - 1] = A[j - 1], A[j]
     i range(len(A) - 1) range len(A) - 1 len(A) len A 1 for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                swaps += 1
                A[j], A[j - 1] = A[j - 1], A[j]
     j range(len(A) - 1, i, -1) range len(A) - 1 len(A) len A 1 i -1 if A[j] < A[j - 1]:
                swaps += 1
                A[j], A[j - 1] = A[j - 1], A[j]
     A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 swaps += 1 swaps 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 return A, swaps return A, swaps A swaps A A N = int(input()) N int(input()) int input() input int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ A = [int(_) for _ in input().split()] A [int(_) for _ in input().split()] A, swaps = bubble_sort(A) A bubble_sort(A) bubble_sort A swaps printA(A) printA A print(swaps) print swaps A = [int(_) for _ in input().split()] [int(_) for _ in input().split()] A def bubble_sort(A):
    swaps = 0
    for i in range(len(A) - 1):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                swaps += 1
                A[j], A[j - 1] = A[j - 1], A[j]
    return A, swaps

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

         bubble_sort A, swaps = bubble_sort(A) bubble_sort(A) A PYDEV = os.environ.get('PYDEV') os.environ.get('PYDEV') PYDEV def printA(A):
    print(' '.join([str(a) for a in A])) def printA(A):
    print(' '.join([str(a) for a in A])) printA N = int(input()) int(input()) N swaps = bubble_sort(A) bubble_sort(A) swaps
# Aizu Problem ALDS_1_2_A: Bubble Sort
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def printA(A):
    print(' '.join([str(a) for a in A]))

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

        
N = int(input())
A = [int(_) for _ in input().split()]
A, swaps = bubble_sort(A)
printA(A)
print(swaps)