def bubble_sort(A):
    count = 0
    for i in reversed(range(len(A))):
        for j in range(i):
            if A[j] > A[j+1]:
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    return count

N = int(input())
A = list(map(int,input().split()))

count = bubble_sort(A)
print(" ".join(map(str,A)))
print(count) def bubble_sort(A):
    count = 0
    for i in reversed(range(len(A))):
        for j in range(i):
            if A[j] > A[j+1]:
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    return count bubble_sort count = 0 count 0 for i in reversed(range(len(A))):
        for j in range(i):
            if A[j] > A[j+1]:
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
     i reversed(range(len(A))) reversed range(len(A)) range len(A) len A for j in range(i):
            if A[j] > A[j+1]:
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
     j range(i) range i if A[j] > A[j+1]:
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
     A[j] > A[j+1] A[j] A j A[j+1] A j+1 j 1 temp = A[j] temp A[j] A j A[j] = A[j+1] A[j] A j A[j+1] A j+1 j 1 A[j+1] = temp A[j+1] A j+1 j 1 temp count += 1 count 1 return count count A A N = int(input()) N int(input()) int input() input A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split count = bubble_sort(A) count bubble_sort(A) bubble_sort A print(" ".join(map(str,A))) print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print(count) print count N = int(input()) int(input()) N A = list(map(int,input().split())) list(map(int,input().split())) A def bubble_sort(A):
    count = 0
    for i in reversed(range(len(A))):
        for j in range(i):
            if A[j] > A[j+1]:
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    return count def bubble_sort(A):
    count = 0
    for i in reversed(range(len(A))):
        for j in range(i):
            if A[j] > A[j+1]:
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    return count bubble_sort count = bubble_sort(A) bubble_sort(A) count
def bubble_sort(A):
    count = 0
    for i in reversed(range(len(A))):
        for j in range(i):
            if A[j] > A[j+1]:
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    return count

N = int(input())
A = list(map(int,input().split()))

count = bubble_sort(A)
print(" ".join(map(str,A)))
print(count)