itemCount = int(input())
items = list(map(int, input().split(" ")))

def bubbleSort(items, itemCount):
    hasPrevious = True
    swapCount = 0
    while hasPrevious:
        hasPrevious = False
        for index in reversed(range(1, itemCount )):
            if items[index] < items[index - 1]:
                items[index], items[index - 1] = [items[index - 1], items[index]]
                hasPrevious = True
                swapCount += 1
    print(" ".join(map(str, items)))
    print(swapCount)

bubbleSort(items, itemCount) itemCount = int(input()) itemCount int(input()) int input() input items = list(map(int, input().split(" "))) items list(map(int, input().split(" "))) list map(int, input().split(" ")) map int input().split(" ") ().split () input split " " def bubbleSort(items, itemCount):
    hasPrevious = True
    swapCount = 0
    while hasPrevious:
        hasPrevious = False
        for index in reversed(range(1, itemCount )):
            if items[index] < items[index - 1]:
                items[index], items[index - 1] = [items[index - 1], items[index]]
                hasPrevious = True
                swapCount += 1
    print(" ".join(map(str, items)))
    print(swapCount) bubbleSort hasPrevious = True hasPrevious True swapCount = 0 swapCount 0 while hasPrevious:
        hasPrevious = False
        for index in reversed(range(1, itemCount )):
            if items[index] < items[index - 1]:
                items[index], items[index - 1] = [items[index - 1], items[index]]
                hasPrevious = True
                swapCount += 1
     hasPrevious hasPrevious = False hasPrevious False for index in reversed(range(1, itemCount )):
            if items[index] < items[index - 1]:
                items[index], items[index - 1] = [items[index - 1], items[index]]
                hasPrevious = True
                swapCount += 1
     index reversed(range(1, itemCount )) reversed range(1, itemCount ) range 1 itemCount if items[index] < items[index - 1]:
                items[index], items[index - 1] = [items[index - 1], items[index]]
                hasPrevious = True
                swapCount += 1
     items[index] < items[index - 1] items[index] items index items[index - 1] items index - 1 index 1 items[index], items[index - 1] = [items[index - 1], items[index]] items[index] items index [items[index - 1], items[index]] items[index - 1] items index - 1 index 1 items[index] items index items[index - 1] items index - 1 index 1 hasPrevious = True hasPrevious True swapCount += 1 swapCount 1 print(" ".join(map(str, items))) print " ".join(map(str, items)) " ".join " " join map(str, items) map str items print(swapCount) print swapCount items items itemCount itemCount bubbleSort(items, itemCount) bubbleSort items itemCount def bubbleSort(items, itemCount):
    hasPrevious = True
    swapCount = 0
    while hasPrevious:
        hasPrevious = False
        for index in reversed(range(1, itemCount )):
            if items[index] < items[index - 1]:
                items[index], items[index - 1] = [items[index - 1], items[index]]
                hasPrevious = True
                swapCount += 1
    print(" ".join(map(str, items)))
    print(swapCount) def bubbleSort(items, itemCount):
    hasPrevious = True
    swapCount = 0
    while hasPrevious:
        hasPrevious = False
        for index in reversed(range(1, itemCount )):
            if items[index] < items[index - 1]:
                items[index], items[index - 1] = [items[index - 1], items[index]]
                hasPrevious = True
                swapCount += 1
    print(" ".join(map(str, items)))
    print(swapCount) bubbleSort items = list(map(int, input().split(" "))) list(map(int, input().split(" "))) items itemCount = int(input()) int(input()) itemCount
itemCount = int(input())
items = list(map(int, input().split(" ")))

def bubbleSort(items, itemCount):
    hasPrevious = True
    swapCount = 0
    while hasPrevious:
        hasPrevious = False
        for index in reversed(range(1, itemCount )):
            if items[index] < items[index - 1]:
                items[index], items[index - 1] = [items[index - 1], items[index]]
                hasPrevious = True
                swapCount += 1
    print(" ".join(map(str, items)))
    print(swapCount)

bubbleSort(items, itemCount)