def bubble_sort(numbers, n):
    """bubble sort method

    Args:
        numbers: a list of numbers to be sorted by bubble sort
        n: len(list)

    Returns:
        sorted list
    """
    flag = True
    counter = 0
    while flag:
        flag = False
        for index in range(n - 1, 0, -1):
            if numbers[index] < numbers[index - 1]:
                numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index]
                flag = True
                counter += 1
    return numbers, counter


n = int(raw_input())
numbers = [int(x) for x in raw_input().split()]
numbers, swapped_numbers = bubble_sort(numbers, n)

print(" ".join([str(x) for x in numbers]))
print(swapped_numbers) def bubble_sort(numbers, n):
    """bubble sort method

    Args:
        numbers: a list of numbers to be sorted by bubble sort
        n: len(list)

    Returns:
        sorted list
    """
    flag = True
    counter = 0
    while flag:
        flag = False
        for index in range(n - 1, 0, -1):
            if numbers[index] < numbers[index - 1]:
                numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index]
                flag = True
                counter += 1
    return numbers, counter bubble_sort """bubble sort method

    Args:
        numbers: a list of numbers to be sorted by bubble sort
        n: len(list)

    Returns:
        sorted list
    """ flag = True flag True counter = 0 counter 0 while flag:
        flag = False
        for index in range(n - 1, 0, -1):
            if numbers[index] < numbers[index - 1]:
                numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index]
                flag = True
                counter += 1
     flag flag = False flag False for index in range(n - 1, 0, -1):
            if numbers[index] < numbers[index - 1]:
                numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index]
                flag = True
                counter += 1
     index range(n - 1, 0, -1) range n - 1 n 1 0 -1 if numbers[index] < numbers[index - 1]:
                numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index]
                flag = True
                counter += 1
     numbers[index] < numbers[index - 1] numbers[index] numbers index numbers[index - 1] numbers index - 1 index 1 numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index] numbers[index] numbers index numbers[index - 1] numbers index - 1 index 1 numbers[index - 1] numbers index - 1 index 1 numbers[index] numbers index flag = True flag True counter += 1 counter 1 return numbers, counter return numbers, counter numbers counter numbers numbers n n n = int(raw_input()) n int(raw_input()) int raw_input() raw_input int(x) for x in raw_input().split() for x in raw_input().split() x raw_input().split() ().split () raw_input split for x in raw_input().split() int(x) int x numbers = [int(x) for x in raw_input().split()] numbers [int(x) for x in raw_input().split()] numbers, swapped_numbers = bubble_sort(numbers, n) numbers bubble_sort(numbers, n) bubble_sort numbers n swapped_numbers str(x) for x in numbers for x in numbers x numbers for x in numbers str(x) str x print(" ".join([str(x) for x in numbers])) print " ".join([str(x) for x in numbers]) " ".join " " join [str(x) for x in numbers] print(swapped_numbers) print swapped_numbers swapped_numbers = bubble_sort(numbers, n) bubble_sort(numbers, n) swapped_numbers n = int(raw_input()) int(raw_input()) n def bubble_sort(numbers, n):
    """bubble sort method

    Args:
        numbers: a list of numbers to be sorted by bubble sort
        n: len(list)

    Returns:
        sorted list
    """
    flag = True
    counter = 0
    while flag:
        flag = False
        for index in range(n - 1, 0, -1):
            if numbers[index] < numbers[index - 1]:
                numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index]
                flag = True
                counter += 1
    return numbers, counter def bubble_sort(numbers, n):
    """bubble sort method

    Args:
        numbers: a list of numbers to be sorted by bubble sort
        n: len(list)

    Returns:
        sorted list
    """
    flag = True
    counter = 0
    while flag:
        flag = False
        for index in range(n - 1, 0, -1):
            if numbers[index] < numbers[index - 1]:
                numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index]
                flag = True
                counter += 1
    return numbers, counter bubble_sort numbers = [int(x) for x in raw_input().split()] [int(x) for x in raw_input().split()] numbers numbers, swapped_numbers = bubble_sort(numbers, n) bubble_sort(numbers, n) numbers
def bubble_sort(numbers, n):
    """bubble sort method

    Args:
        numbers: a list of numbers to be sorted by bubble sort
        n: len(list)

    Returns:
        sorted list
    """
    flag = True
    counter = 0
    while flag:
        flag = False
        for index in range(n - 1, 0, -1):
            if numbers[index] < numbers[index - 1]:
                numbers[index], numbers[index - 1] = numbers[index - 1], numbers[index]
                flag = True
                counter += 1
    return numbers, counter


n = int(raw_input())
numbers = [int(x) for x in raw_input().split()]
numbers, swapped_numbers = bubble_sort(numbers, n)

print(" ".join([str(x) for x in numbers]))
print(swapped_numbers)