def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = list(A)
    ans, n = bubbleSort(a, N)
    print(*ans, sep=' ')
    print(n)

def bubbleSort(a, n):
    j = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = 1
                j += 1
    return a, j

main() def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = list(A)
    ans, n = bubbleSort(a, N)
    print(*ans, sep=' ')
    print(n) main N = int(input()) N int(input()) int input() input A = tuple(map(int, input().split())) A tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split a = list(A) a list(A) list A ans, n = bubbleSort(a, N) ans bubbleSort(a, N) bubbleSort a N n print(*ans, sep=' ') print *ans ans sep=' ' sep ' ' print(n) print n def bubbleSort(a, n):
    j = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = 1
                j += 1
    return a, j bubbleSort j = 0 j 0 flag = 1 flag 1 while flag:
        flag = 0
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = 1
                j += 1
     flag flag = 0 flag 0 for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = 1
                j += 1
     i range(1, n) range 1 n if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = 1
                j += 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 = 1 flag 1 j += 1 j 1 return a, j return a, j a j a a n n main() main def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = list(A)
    ans, n = bubbleSort(a, N)
    print(*ans, sep=' ')
    print(n) def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = list(A)
    ans, n = bubbleSort(a, N)
    print(*ans, sep=' ')
    print(n) main def bubbleSort(a, n):
    j = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = 1
                j += 1
    return a, j def bubbleSort(a, n):
    j = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = 1
                j += 1
    return a, j bubbleSort
def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = list(A)
    ans, n = bubbleSort(a, N)
    print(*ans, sep=' ')
    print(n)

def bubbleSort(a, n):
    j = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = 1
                j += 1
    return a, j

main()