def bubble_sort(alist):
    """Sort alist by bubble sort.
    Returns (number of swap operations, sorted list)

    >>> bubble_sort([5, 3, 2, 4, 1])
    ([1, 2, 3, 4, 5], 8)
    """
    size = len(alist)
    count = 0

    for i in range(size-1):
        for j in reversed(range(i+1, size)):
            if alist[j] < alist[j-1]:
                count += 1
                alist[j-1], alist[j] = alist[j], alist[j-1]

    return (alist, count)


def run():
    _ = int(input()) # flake8: noqa
    nums = [int(i) for i in input().split()]

    (sorted_list, num_swap) = bubble_sort(nums)

    print(" ".join([str(i) for i in sorted_list]))
    print(num_swap)


if __name__ == '__main__':
    run() def bubble_sort(alist):
    """Sort alist by bubble sort.
    Returns (number of swap operations, sorted list)

    >>> bubble_sort([5, 3, 2, 4, 1])
    ([1, 2, 3, 4, 5], 8)
    """
    size = len(alist)
    count = 0

    for i in range(size-1):
        for j in reversed(range(i+1, size)):
            if alist[j] < alist[j-1]:
                count += 1
                alist[j-1], alist[j] = alist[j], alist[j-1]

    return (alist, count) bubble_sort """Sort alist by bubble sort.
    Returns (number of swap operations, sorted list)

    >>> bubble_sort([5, 3, 2, 4, 1])
    ([1, 2, 3, 4, 5], 8)
    """ size = len(alist) size len(alist) len alist count = 0 count 0 for i in range(size-1):
        for j in reversed(range(i+1, size)):
            if alist[j] < alist[j-1]:
                count += 1
                alist[j-1], alist[j] = alist[j], alist[j-1]

     i range(size-1) range size-1 size 1 for j in reversed(range(i+1, size)):
            if alist[j] < alist[j-1]:
                count += 1
                alist[j-1], alist[j] = alist[j], alist[j-1]

     j reversed(range(i+1, size)) reversed range(i+1, size) range i+1 i 1 size if alist[j] < alist[j-1]:
                count += 1
                alist[j-1], alist[j] = alist[j], alist[j-1]

     alist[j] < alist[j-1] alist[j] alist j alist[j-1] alist j-1 j 1 count += 1 count 1 alist[j-1], alist[j] = alist[j], alist[j-1] alist[j-1] alist j-1 j 1 alist[j] alist j alist[j] alist j alist[j-1] alist j-1 j 1 return (alist, count) (alist, count) alist count alist alist def run():
    _ = int(input()) # flake8: noqa
    nums = [int(i) for i in input().split()]

    (sorted_list, num_swap) = bubble_sort(nums)

    print(" ".join([str(i) for i in sorted_list]))
    print(num_swap) run _ = int(input()) _ int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i nums = [int(i) for i in input().split()] nums [int(i) for i in input().split()] (sorted_list, num_swap) = bubble_sort(nums) (sorted_list, num_swap) sorted_list num_swap bubble_sort(nums) bubble_sort nums str(i) for i in sorted_list for i in sorted_list i sorted_list for i in sorted_list str(i) str i print(" ".join([str(i) for i in sorted_list])) print " ".join([str(i) for i in sorted_list]) " ".join " " join [str(i) for i in sorted_list] print(num_swap) print num_swap if __name__ == '__main__':
    run() __name__ == '__main__' __name__ '__main__' run() run def run():
    _ = int(input()) # flake8: noqa
    nums = [int(i) for i in input().split()]

    (sorted_list, num_swap) = bubble_sort(nums)

    print(" ".join([str(i) for i in sorted_list]))
    print(num_swap) def run():
    _ = int(input()) # flake8: noqa
    nums = [int(i) for i in input().split()]

    (sorted_list, num_swap) = bubble_sort(nums)

    print(" ".join([str(i) for i in sorted_list]))
    print(num_swap) run def bubble_sort(alist):
    """Sort alist by bubble sort.
    Returns (number of swap operations, sorted list)

    >>> bubble_sort([5, 3, 2, 4, 1])
    ([1, 2, 3, 4, 5], 8)
    """
    size = len(alist)
    count = 0

    for i in range(size-1):
        for j in reversed(range(i+1, size)):
            if alist[j] < alist[j-1]:
                count += 1
                alist[j-1], alist[j] = alist[j], alist[j-1]

    return (alist, count) def bubble_sort(alist):
    """Sort alist by bubble sort.
    Returns (number of swap operations, sorted list)

    >>> bubble_sort([5, 3, 2, 4, 1])
    ([1, 2, 3, 4, 5], 8)
    """
    size = len(alist)
    count = 0

    for i in range(size-1):
        for j in reversed(range(i+1, size)):
            if alist[j] < alist[j-1]:
                count += 1
                alist[j-1], alist[j] = alist[j], alist[j-1]

    return (alist, count) bubble_sort
def bubble_sort(alist):
    """Sort alist by bubble sort.
    Returns (number of swap operations, sorted list)

    >>> bubble_sort([5, 3, 2, 4, 1])
    ([1, 2, 3, 4, 5], 8)
    """
    size = len(alist)
    count = 0

    for i in range(size-1):
        for j in reversed(range(i+1, size)):
            if alist[j] < alist[j-1]:
                count += 1
                alist[j-1], alist[j] = alist[j], alist[j-1]

    return (alist, count)


def run():
    _ = int(input()) # flake8: noqa
    nums = [int(i) for i in input().split()]

    (sorted_list, num_swap) = bubble_sort(nums)

    print(" ".join([str(i) for i in sorted_list]))
    print(num_swap)


if __name__ == '__main__':
    run()
