# Bubble sort: ALDS1_2_A

def bsort(A, N):
    flag = 1
    swap = 0
    while flag:
        flag = 0
        for j in reversed(range(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                swap += 1
    return swap

N = int(raw_input())
A = [int(i) for i in raw_input().split()]

swap = bsort(A, N)
print " ".join([repr(i) for i in A])
print swap
 def bsort(A, N):
    flag = 1
    swap = 0
    while flag:
        flag = 0
        for j in reversed(range(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                swap += 1
    return swap bsort flag = 1 flag 1 swap = 0 swap 0 while flag:
        flag = 0
        for j in reversed(range(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                swap += 1
     flag flag = 0 flag 0 for j in reversed(range(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                swap += 1
     j reversed(range(1, N)) reversed range(1, N) range 1 N if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                swap += 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 flag = 1 flag 1 swap += 1 swap 1 return swap swap A A N N N = int(raw_input()) N int(raw_input()) int raw_input() raw_input int(i) for i in raw_input().split() for i in raw_input().split() i raw_input().split() ().split () raw_input split for i in raw_input().split() int(i) int i A = [int(i) for i in raw_input().split()] A [int(i) for i in raw_input().split()] swap = bsort(A, N) swap bsort(A, N) bsort A N print repr(i) for i in A for i in A i A for i in A repr(i) repr i " ".join([repr(i) for i in A]) " ".join " " join [repr(i) for i in A] print swap = bsort(A, N) bsort(A, N) swap A = [int(i) for i in raw_input().split()] [int(i) for i in raw_input().split()] A def bsort(A, N):
    flag = 1
    swap = 0
    while flag:
        flag = 0
        for j in reversed(range(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                swap += 1
    return swap def bsort(A, N):
    flag = 1
    swap = 0
    while flag:
        flag = 0
        for j in reversed(range(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                swap += 1
    return swap bsort N = int(raw_input()) int(raw_input()) N
# Bubble sort: ALDS1_2_A

def bsort(A, N):
    flag = 1
    swap = 0
    while flag:
        flag = 0
        for j in reversed(range(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                swap += 1
    return swap

N = int(raw_input())
A = [int(i) for i in raw_input().split()]

swap = bsort(A, N)
print " ".join([repr(i) for i in A])
print swap

