def bubbleSort(lst, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if lst[j] < lst[j-1]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                flag = 1
                i = i + 1
    print(" ".join([str(n) for n in lst]))
    print(i)


if __name__ == "__main__":
    n = int(input())
    lst = [int(n) for n in input().split()]
    bubbleSort(lst, n) def bubbleSort(lst, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if lst[j] < lst[j-1]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                flag = 1
                i = i + 1
    print(" ".join([str(n) for n in lst]))
    print(i) bubbleSort flag = 1 flag 1 i = 0 i 0 while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if lst[j] < lst[j-1]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                flag = 1
                i = i + 1
     flag flag = 0 flag 0 for j in range(n-1, 0, -1):
            if lst[j] < lst[j-1]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                flag = 1
                i = i + 1
     j range(n-1, 0, -1) range n-1 n 1 0 -1 if lst[j] < lst[j-1]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                flag = 1
                i = i + 1
     lst[j] < lst[j-1] lst[j] lst j lst[j-1] lst j-1 j 1 tmp = lst[j] tmp lst[j] lst j lst[j] = lst[j-1] lst[j] lst j lst[j-1] lst j-1 j 1 lst[j-1] = tmp lst[j-1] lst j-1 j 1 tmp flag = 1 flag 1 i = i + 1 i i + 1 i 1 str(n) for n in lst for n in lst n lst for n in lst str(n) str n print(" ".join([str(n) for n in lst])) print " ".join([str(n) for n in lst]) " ".join " " join [str(n) for n in lst] print(i) print i lst lst n n if __name__ == "__main__":
    n = int(input())
    lst = [int(n) for n in input().split()]
    bubbleSort(lst, n) __name__ == "__main__" __name__ "__main__" n = int(input()) n int(input()) int input() input int(n) for n in input().split() for n in input().split() n input().split() ().split () input split for n in input().split() int(n) int n lst = [int(n) for n in input().split()] lst [int(n) for n in input().split()] bubbleSort(lst, n) bubbleSort lst n lst = [int(n) for n in input().split()] [int(n) for n in input().split()] lst def bubbleSort(lst, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if lst[j] < lst[j-1]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                flag = 1
                i = i + 1
    print(" ".join([str(n) for n in lst]))
    print(i) def bubbleSort(lst, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if lst[j] < lst[j-1]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                flag = 1
                i = i + 1
    print(" ".join([str(n) for n in lst]))
    print(i) bubbleSort n = int(input()) int(input()) n
def bubbleSort(lst, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if lst[j] < lst[j-1]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                flag = 1
                i = i + 1
    print(" ".join([str(n) for n in lst]))
    print(i)


if __name__ == "__main__":
    n = int(input())
    lst = [int(n) for n in input().split()]
    bubbleSort(lst, n)