

def bsort(array):
    i = 0
    counter = 0
    while i < len(array)-1:
        for c in range(len(array)-1,i,-1):
            if array[c]<array[c-1]:
                a = array[c-1]
                array[c-1] = array[c]
                array[c] = a
                counter += 1

        i = i+1
    resul = ' '.join([str(i) for i in array])
    print(resul)
    print(counter)

n = int(input())

inputarr = input().split()
intarr = [int(i) for i in inputarr]

bsort(intarr) def bsort(array):
    i = 0
    counter = 0
    while i < len(array)-1:
        for c in range(len(array)-1,i,-1):
            if array[c]<array[c-1]:
                a = array[c-1]
                array[c-1] = array[c]
                array[c] = a
                counter += 1

        i = i+1
    resul = ' '.join([str(i) for i in array])
    print(resul)
    print(counter) bsort i = 0 i 0 counter = 0 counter 0 while i < len(array)-1:
        for c in range(len(array)-1,i,-1):
            if array[c]<array[c-1]:
                a = array[c-1]
                array[c-1] = array[c]
                array[c] = a
                counter += 1

        i = i+1
     i < len(array)-1 i len(array)-1 len(array) len array 1 for c in range(len(array)-1,i,-1):
            if array[c]<array[c-1]:
                a = array[c-1]
                array[c-1] = array[c]
                array[c] = a
                counter += 1

         c range(len(array)-1,i,-1) range len(array)-1 len(array) len array 1 i -1 if array[c]<array[c-1]:
                a = array[c-1]
                array[c-1] = array[c]
                array[c] = a
                counter += 1

         array[c]<array[c-1] array[c] array c array[c-1] array c-1 c 1 a = array[c-1] a array[c-1] array c-1 c 1 array[c-1] = array[c] array[c-1] array c-1 c 1 array[c] array c array[c] = a array[c] array c a counter += 1 counter 1 i = i+1 i i+1 i 1 str(i) for i in array for i in array i array for i in array str(i) str i resul = ' '.join([str(i) for i in array]) resul ' '.join([str(i) for i in array]) ' '.join ' ' join [str(i) for i in array] print(resul) print resul print(counter) print counter array array n = int(input()) n int(input()) int input() input inputarr = input().split() inputarr input().split() ().split () input split int(i) for i in inputarr for i in inputarr i inputarr for i in inputarr int(i) int i intarr = [int(i) for i in inputarr] intarr [int(i) for i in inputarr] bsort(intarr) bsort intarr def bsort(array):
    i = 0
    counter = 0
    while i < len(array)-1:
        for c in range(len(array)-1,i,-1):
            if array[c]<array[c-1]:
                a = array[c-1]
                array[c-1] = array[c]
                array[c] = a
                counter += 1

        i = i+1
    resul = ' '.join([str(i) for i in array])
    print(resul)
    print(counter) def bsort(array):
    i = 0
    counter = 0
    while i < len(array)-1:
        for c in range(len(array)-1,i,-1):
            if array[c]<array[c-1]:
                a = array[c-1]
                array[c-1] = array[c]
                array[c] = a
                counter += 1

        i = i+1
    resul = ' '.join([str(i) for i in array])
    print(resul)
    print(counter) bsort inputarr = input().split() input().split() inputarr n = int(input()) int(input()) n intarr = [int(i) for i in inputarr] [int(i) for i in inputarr] intarr


def bsort(array):
    i = 0
    counter = 0
    while i < len(array)-1:
        for c in range(len(array)-1,i,-1):
            if array[c]<array[c-1]:
                a = array[c-1]
                array[c-1] = array[c]
                array[c] = a
                counter += 1

        i = i+1
    resul = ' '.join([str(i) for i in array])
    print(resul)
    print(counter)

n = int(input())

inputarr = input().split()
intarr = [int(i) for i in inputarr]

bsort(intarr)