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

cnt = 0
amount = int(input())
nl = list(map(int, input().split()))

cnt = bubble_sort(nl)

for i in range(amount - 1):
    print(nl[i], end=" ")
print(nl[amount - 1])
print(cnt) def bubble_sort(A):
    cnt = 0
    for i in range(len(A) - 1):
        for j in reversed(range(i+1, len(A))):
            if A[j] < A[j - 1]:
                cnt += 1
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp
    return cnt bubble_sort cnt = 0 cnt 0 for i in range(len(A) - 1):
        for j in reversed(range(i+1, len(A))):
            if A[j] < A[j - 1]:
                cnt += 1
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp
     i range(len(A) - 1) range len(A) - 1 len(A) len A 1 for j in reversed(range(i+1, len(A))):
            if A[j] < A[j - 1]:
                cnt += 1
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp
     j reversed(range(i+1, len(A))) reversed range(i+1, len(A)) range i+1 i 1 len(A) len A if A[j] < A[j - 1]:
                cnt += 1
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp
     A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 cnt += 1 cnt 1 tmp = A[j] tmp A[j] A j A[j] = A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 A[j - 1] = tmp A[j - 1] A j - 1 j 1 tmp return cnt cnt A A cnt = 0 cnt 0 amount = int(input()) amount int(input()) int input() input nl = list(map(int, input().split())) nl list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cnt = bubble_sort(nl) cnt bubble_sort(nl) bubble_sort nl for i in range(amount - 1):
    print(nl[i], end=" ") i range(amount - 1) range amount - 1 amount 1 print(nl[i], end=" ") print nl[i] nl i end=" " end " " print(nl[amount - 1]) print nl[amount - 1] nl amount - 1 amount 1 print(cnt) print cnt cnt = bubble_sort(nl) bubble_sort(nl) cnt def bubble_sort(A):
    cnt = 0
    for i in range(len(A) - 1):
        for j in reversed(range(i+1, len(A))):
            if A[j] < A[j - 1]:
                cnt += 1
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp
    return cnt def bubble_sort(A):
    cnt = 0
    for i in range(len(A) - 1):
        for j in reversed(range(i+1, len(A))):
            if A[j] < A[j - 1]:
                cnt += 1
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp
    return cnt bubble_sort nl = list(map(int, input().split())) list(map(int, input().split())) nl cnt = 0 0 cnt amount = int(input()) int(input()) amount
def bubble_sort(A):
    cnt = 0
    for i in range(len(A) - 1):
        for j in reversed(range(i+1, len(A))):
            if A[j] < A[j - 1]:
                cnt += 1
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp
    return cnt

cnt = 0
amount = int(input())
nl = list(map(int, input().split()))

cnt = bubble_sort(nl)

for i in range(amount - 1):
    print(nl[i], end=" ")
print(nl[amount - 1])
print(cnt)