
def swap(A, i, j):
    tmp = A[i]
    A[i] = A[j]
    A[j] = tmp



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

n = int(input())
A = [int(x) for x in input().split()]

s_A, count = bubble_sort(A, n)

print(" ".join([str(x) for x in s_A]))
print(count) def swap(A, i, j):
    tmp = A[i]
    A[i] = A[j]
    A[j] = tmp swap tmp = A[i] tmp A[i] A i A[i] = A[j] A[i] A i A[j] A j A[j] = tmp A[j] A j tmp A A i i j j def bubble_sort(A, n):
    count = 0
    for i in range(0, n):
        for j in range(n-1, i, -1):
                if A[j] < A[j-1]:
                    swap(A, j, j-1)
                    count += 1
    return A, count bubble_sort count = 0 count 0 for i in range(0, n):
        for j in range(n-1, i, -1):
                if A[j] < A[j-1]:
                    swap(A, j, j-1)
                    count += 1
     i range(0, n) range 0 n for j in range(n-1, i, -1):
                if A[j] < A[j-1]:
                    swap(A, j, j-1)
                    count += 1
     j range(n-1, i, -1) range n-1 n 1 i -1 if A[j] < A[j-1]:
                    swap(A, j, j-1)
                    count += 1
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 swap(A, j, j-1) swap A j j-1 j 1 count += 1 count 1 return A, count return A, count A count A A n n n = int(input()) n int(input()) int input() input int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x A = [int(x) for x in input().split()] A [int(x) for x in input().split()] s_A, count = bubble_sort(A, n) s_A bubble_sort(A, n) bubble_sort A n count str(x) for x in s_A for x in s_A x s_A for x in s_A str(x) str x print(" ".join([str(x) for x in s_A])) print " ".join([str(x) for x in s_A]) " ".join " " join [str(x) for x in s_A] print(count) print count count = bubble_sort(A, n) bubble_sort(A, n) count def bubble_sort(A, n):
    count = 0
    for i in range(0, n):
        for j in range(n-1, i, -1):
                if A[j] < A[j-1]:
                    swap(A, j, j-1)
                    count += 1
    return A, count def bubble_sort(A, n):
    count = 0
    for i in range(0, n):
        for j in range(n-1, i, -1):
                if A[j] < A[j-1]:
                    swap(A, j, j-1)
                    count += 1
    return A, count bubble_sort n = int(input()) int(input()) n s_A, count = bubble_sort(A, n) bubble_sort(A, n) s_A A = [int(x) for x in input().split()] [int(x) for x in input().split()] A def swap(A, i, j):
    tmp = A[i]
    A[i] = A[j]
    A[j] = tmp def swap(A, i, j):
    tmp = A[i]
    A[i] = A[j]
    A[j] = tmp swap

def swap(A, i, j):
    tmp = A[i]
    A[i] = A[j]
    A[j] = tmp



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

n = int(input())
A = [int(x) for x in input().split()]

s_A, count = bubble_sort(A, n)

print(" ".join([str(x) for x in s_A]))
print(count)
