n = int(input())
ll = list(map(int, input().split()))


def bubble_sort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(n-2, -1, -1):
            if a[i] > a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
                flag = True
                count += 1
    print(" ".join(map(str, a)))
    print(count)


bubble_sort(ll, n) n = int(input()) n int(input()) int input() input ll = list(map(int, input().split())) ll list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def bubble_sort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(n-2, -1, -1):
            if a[i] > a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
                flag = True
                count += 1
    print(" ".join(map(str, a)))
    print(count) bubble_sort flag = True flag True count = 0 count 0 while flag:
        flag = False
        for i in range(n-2, -1, -1):
            if a[i] > a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
                flag = True
                count += 1
     flag flag = False flag False for i in range(n-2, -1, -1):
            if a[i] > a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
                flag = True
                count += 1
     i range(n-2, -1, -1) range n-2 n 2 -1 -1 if a[i] > a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
                flag = True
                count += 1
     a[i] > a[i+1] a[i] a i a[i+1] a i+1 i 1 a[i], a[i+1] = a[i+1], a[i] a[i] a i a[i+1] a i+1 i 1 a[i+1] a i+1 i 1 a[i] a i flag = True flag True count += 1 count 1 print(" ".join(map(str, a))) print " ".join(map(str, a)) " ".join " " join map(str, a) map str a print(count) print count a a n n bubble_sort(ll, n) bubble_sort ll n n = int(input()) int(input()) n def bubble_sort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(n-2, -1, -1):
            if a[i] > a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
                flag = True
                count += 1
    print(" ".join(map(str, a)))
    print(count) def bubble_sort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(n-2, -1, -1):
            if a[i] > a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
                flag = True
                count += 1
    print(" ".join(map(str, a)))
    print(count) bubble_sort ll = list(map(int, input().split())) list(map(int, input().split())) ll
n = int(input())
ll = list(map(int, input().split()))


def bubble_sort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(n-2, -1, -1):
            if a[i] > a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
                flag = True
                count += 1
    print(" ".join(map(str, a)))
    print(count)


bubble_sort(ll, n)
