# -*- coding: utf 8 -*-
# Bubble Sort
# 2019. 4/22

def bubbleSort(A, N):
    sw = 0
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(int(N) - 1, i, -1):
            if A[j - 1] > A[j]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                sw = sw + 1
        i = i + 1
    return A, sw

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    A_sorted, num_sw = bubbleSort(A, N)

    for i in range(N-1):
        print(A[i], end=" ")
    print(A[N-1])
    print(num_sw)
 def bubbleSort(A, N):
    sw = 0
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(int(N) - 1, i, -1):
            if A[j - 1] > A[j]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                sw = sw + 1
        i = i + 1
    return A, sw bubbleSort sw = 0 sw 0 flag = 1 flag 1 i = 0 i 0 while flag:
        flag = 0
        for j in range(int(N) - 1, i, -1):
            if A[j - 1] > A[j]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                sw = sw + 1
        i = i + 1
     flag flag = 0 flag 0 for j in range(int(N) - 1, i, -1):
            if A[j - 1] > A[j]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                sw = sw + 1
         j range(int(N) - 1, i, -1) range int(N) - 1 int(N) int N 1 i -1 if A[j - 1] > A[j]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                sw = sw + 1
         A[j - 1] > A[j] A[j - 1] A j - 1 j 1 A[j] A j 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 sw = sw + 1 sw sw + 1 sw 1 i = i + 1 i i + 1 i 1 return A, sw return A, sw A sw A A N N if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    A_sorted, num_sw = bubbleSort(A, N)

    for i in range(N-1):
        print(A[i], end=" ")
    print(A[N-1])
    print(num_sw) __name__ == '__main__' __name__ '__main__' 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 A_sorted, num_sw = bubbleSort(A, N) A_sorted bubbleSort(A, N) bubbleSort A N num_sw for i in range(N-1):
        print(A[i], end=" ")
     i range(N-1) range N-1 N 1 print(A[i], end=" ") print A[i] A i end=" " end " " print(A[N-1]) print A[N-1] A N-1 N 1 print(num_sw) print num_sw num_sw = bubbleSort(A, N) bubbleSort(A, N) num_sw N = int(input()) int(input()) N A = list(map(int, input().split())) list(map(int, input().split())) A A_sorted, num_sw = bubbleSort(A, N) bubbleSort(A, N) A_sorted def bubbleSort(A, N):
    sw = 0
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(int(N) - 1, i, -1):
            if A[j - 1] > A[j]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                sw = sw + 1
        i = i + 1
    return A, sw def bubbleSort(A, N):
    sw = 0
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(int(N) - 1, i, -1):
            if A[j - 1] > A[j]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                sw = sw + 1
        i = i + 1
    return A, sw bubbleSort
# -*- coding: utf 8 -*-
# Bubble Sort
# 2019. 4/22

def bubbleSort(A, N):
    sw = 0
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(int(N) - 1, i, -1):
            if A[j - 1] > A[j]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = 1
                sw = sw + 1
        i = i + 1
    return A, sw

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    A_sorted, num_sw = bubbleSort(A, N)

    for i in range(N-1):
        print(A[i], end=" ")
    print(A[N-1])
    print(num_sw)

