def bubble_sort(r, n):
    flag = True  # ??£??\????´?????????¨????????°
    count = 0
    while flag:
        flag = False
        for i in range(n-1, 0, -1):
            if r[i-1] > r[i]:
                r[i-1],r[i] = r[i],r[i-1]
                count += 1
                flag = True

    print(*r)
    print(count)

N = int(input())
A = list(map(int, input().split()))
bubble_sort(A,N) def bubble_sort(r, n):
    flag = True  # ??£??\????´?????????¨????????°
    count = 0
    while flag:
        flag = False
        for i in range(n-1, 0, -1):
            if r[i-1] > r[i]:
                r[i-1],r[i] = r[i],r[i-1]
                count += 1
                flag = True

    print(*r)
    print(count) bubble_sort flag = True flag True count = 0 count 0 while flag:
        flag = False
        for i in range(n-1, 0, -1):
            if r[i-1] > r[i]:
                r[i-1],r[i] = r[i],r[i-1]
                count += 1
                flag = True

     flag flag = False flag False for i in range(n-1, 0, -1):
            if r[i-1] > r[i]:
                r[i-1],r[i] = r[i],r[i-1]
                count += 1
                flag = True

     i range(n-1, 0, -1) range n-1 n 1 0 -1 if r[i-1] > r[i]:
                r[i-1],r[i] = r[i],r[i-1]
                count += 1
                flag = True

     r[i-1] > r[i] r[i-1] r i-1 i 1 r[i] r i r[i-1],r[i] = r[i],r[i-1] r[i-1] r i-1 i 1 r[i] r i r[i] r i r[i-1] r i-1 i 1 count += 1 count 1 flag = True flag True print(*r) print *r r print(count) print count r r n n N = int(input()) N int(input()) int input() input A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bubble_sort(A,N) bubble_sort A N A = list(map(int, input().split())) list(map(int, input().split())) A N = int(input()) int(input()) N def bubble_sort(r, n):
    flag = True  # ??£??\????´?????????¨????????°
    count = 0
    while flag:
        flag = False
        for i in range(n-1, 0, -1):
            if r[i-1] > r[i]:
                r[i-1],r[i] = r[i],r[i-1]
                count += 1
                flag = True

    print(*r)
    print(count) def bubble_sort(r, n):
    flag = True  # ??£??\????´?????????¨????????°
    count = 0
    while flag:
        flag = False
        for i in range(n-1, 0, -1):
            if r[i-1] > r[i]:
                r[i-1],r[i] = r[i],r[i-1]
                count += 1
                flag = True

    print(*r)
    print(count) bubble_sort
def bubble_sort(r, n):
    flag = True  # ??£??\????´?????????¨????????°
    count = 0
    while flag:
        flag = False
        for i in range(n-1, 0, -1):
            if r[i-1] > r[i]:
                r[i-1],r[i] = r[i],r[i-1]
                count += 1
                flag = True

    print(*r)
    print(count)

N = int(input())
A = list(map(int, input().split()))
bubble_sort(A,N)