def bubbleSort():
    l = int(input())
    A = list(map(int, input().split(" ")))
    count = 0
    for i in range(l-1):
        for j in range(l-1-i):
            if (A[j]>A[j+1]):
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    print(" ".join(map(str, A)))
    print(count)

bubbleSort() def bubbleSort():
    l = int(input())
    A = list(map(int, input().split(" ")))
    count = 0
    for i in range(l-1):
        for j in range(l-1-i):
            if (A[j]>A[j+1]):
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    print(" ".join(map(str, A)))
    print(count) bubbleSort l = int(input()) l 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 " " count = 0 count 0 for i in range(l-1):
        for j in range(l-1-i):
            if (A[j]>A[j+1]):
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
     i range(l-1) range l-1 l 1 for j in range(l-1-i):
            if (A[j]>A[j+1]):
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
     j range(l-1-i) range l-1-i l-1 l 1 i if (A[j]>A[j+1]):
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
     A[j]>A[j+1] A[j] A j A[j+1] A j+1 j 1 temp = A[j] temp A[j] A j A[j] = A[j+1] A[j] A j A[j+1] A j+1 j 1 A[j+1] = temp A[j+1] A j+1 j 1 temp 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 bubbleSort() bubbleSort def bubbleSort():
    l = int(input())
    A = list(map(int, input().split(" ")))
    count = 0
    for i in range(l-1):
        for j in range(l-1-i):
            if (A[j]>A[j+1]):
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    print(" ".join(map(str, A)))
    print(count) def bubbleSort():
    l = int(input())
    A = list(map(int, input().split(" ")))
    count = 0
    for i in range(l-1):
        for j in range(l-1-i):
            if (A[j]>A[j+1]):
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    print(" ".join(map(str, A)))
    print(count) bubbleSort
def bubbleSort():
    l = int(input())
    A = list(map(int, input().split(" ")))
    count = 0
    for i in range(l-1):
        for j in range(l-1-i):
            if (A[j]>A[j+1]):
                temp = A[j]
                A[j] = A[j+1]
                A[j+1] = temp
                count += 1
    print(" ".join(map(str, A)))
    print(count)

bubbleSort()