# -*- coding: utf-8 -*-


def bubbleSort(A, N):
    flag = True  # 未ソートの可能性があるか
    i = 0  # 未ソート部分の先頭
    inv_num = 0  # 転倒数
    while flag:
        flag = False
        for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                inv_num += 1
        i += 1

    return A, inv_num


if __name__ == '__main__':

    N = int(input())
    A = [int(a) for a in input().split(" ")]

    A, inv_num = bubbleSort(A, N)
    print(" ".join(map(str, A)))
    print(inv_num)
 def bubbleSort(A, N):
    flag = True  # 未ソートの可能性があるか
    i = 0  # 未ソート部分の先頭
    inv_num = 0  # 転倒数
    while flag:
        flag = False
        for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                inv_num += 1
        i += 1

    return A, inv_num bubbleSort flag = True flag True i = 0 i 0 inv_num = 0 inv_num 0 while flag:
        flag = False
        for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                inv_num += 1
        i += 1

     flag flag = False flag False for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                inv_num += 1
         j range(N - 1, i, -1) range N - 1 N 1 i -1 if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                inv_num += 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 = True flag True inv_num += 1 inv_num 1 i += 1 i 1 return A, inv_num return A, inv_num A inv_num A A N N if __name__ == '__main__':

    N = int(input())
    A = [int(a) for a in input().split(" ")]

    A, inv_num = bubbleSort(A, N)
    print(" ".join(map(str, A)))
    print(inv_num) __name__ == '__main__' __name__ '__main__' N = int(input()) N int(input()) int input() input int(a) for a in input().split(" ") for a in input().split(" ") a input().split(" ") ().split () input split " " for a in input().split(" ") int(a) int a A = [int(a) for a in input().split(" ")] A [int(a) for a in input().split(" ")] A, inv_num = bubbleSort(A, N) A bubbleSort(A, N) bubbleSort A N inv_num print(" ".join(map(str, A))) print " ".join(map(str, A)) " ".join " " join map(str, A) map str A print(inv_num) print inv_num A = [int(a) for a in input().split(" ")] [int(a) for a in input().split(" ")] A inv_num = bubbleSort(A, N) bubbleSort(A, N) inv_num N = int(input()) int(input()) N A, inv_num = bubbleSort(A, N) bubbleSort(A, N) A def bubbleSort(A, N):
    flag = True  # 未ソートの可能性があるか
    i = 0  # 未ソート部分の先頭
    inv_num = 0  # 転倒数
    while flag:
        flag = False
        for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                inv_num += 1
        i += 1

    return A, inv_num def bubbleSort(A, N):
    flag = True  # 未ソートの可能性があるか
    i = 0  # 未ソート部分の先頭
    inv_num = 0  # 転倒数
    while flag:
        flag = False
        for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                inv_num += 1
        i += 1

    return A, inv_num bubbleSort
# -*- coding: utf-8 -*-


def bubbleSort(A, N):
    flag = True  # 未ソートの可能性があるか
    i = 0  # 未ソート部分の先頭
    inv_num = 0  # 転倒数
    while flag:
        flag = False
        for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                inv_num += 1
        i += 1

    return A, inv_num


if __name__ == '__main__':

    N = int(input())
    A = [int(a) for a in input().split(" ")]

    A, inv_num = bubbleSort(A, N)
    print(" ".join(map(str, A)))
    print(inv_num)

