def bubbleSort(A, N):
    ret = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                ret += 1
    return ret


n = int(input())
a = list(map(int, input().split()))
count = bubbleSort(a, n)
print(" ".join(map(str, a)))
print(count) def bubbleSort(A, N):
    ret = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                ret += 1
    return ret bubbleSort ret = 0 ret 0 flag = 1 flag 1 while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                ret += 1
     flag flag = 0 flag 0 for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                ret += 1
     j range(N-1, 0, -1) range N-1 N 1 0 -1 if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                ret += 1
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j flag = 1 flag 1 ret += 1 ret 1 return ret ret A A 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 count = bubbleSort(a, n) count bubbleSort(a, n) bubbleSort a n print(" ".join(map(str, a))) print " ".join(map(str, a)) " ".join " " join map(str, a) map str a print(count) print count def bubbleSort(A, N):
    ret = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                ret += 1
    return ret def bubbleSort(A, N):
    ret = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                ret += 1
    return ret bubbleSort count = bubbleSort(a, n) bubbleSort(a, n) count a = list(map(int, input().split())) list(map(int, input().split())) a n = int(input()) int(input()) n
def bubbleSort(A, N):
    ret = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                ret += 1
    return ret


n = int(input())
a = list(map(int, input().split()))
count = bubbleSort(a, n)
print(" ".join(map(str, a)))
print(count)