# inputList = list(map(int, '''5
# 5 3 2 4 1'''.split()))
# N = inputList.pop(0)


def formatting(nums):
    for i in range(len(nums)):
        if i != len(nums) - 1:
            print(nums[i], end=' ')
        else:
            print(nums[i])


def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0

        for j in range(N - 1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                count += 1
                flag = 1
    formatting(A)
    print(count)




N = int(input())
inputList = list(map(int, input().split()))

bubbleSort(inputList, N)
 def formatting(nums):
    for i in range(len(nums)):
        if i != len(nums) - 1:
            print(nums[i], end=' ')
        else:
            print(nums[i]) formatting for i in range(len(nums)):
        if i != len(nums) - 1:
            print(nums[i], end=' ')
        else:
            print(nums[i]) i range(len(nums)) range len(nums) len nums if i != len(nums) - 1:
            print(nums[i], end=' ')
        else:
            print(nums[i]) i != len(nums) - 1 i len(nums) - 1 len(nums) len nums 1 print(nums[i], end=' ') print nums[i] nums i end=' ' end ' ' print(nums[i]) print nums[i] nums i nums nums def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0

        for j in range(N - 1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                count += 1
                flag = 1
    formatting(A)
    print(count) bubbleSort count = 0 count 0 flag = 1 flag 1 while flag:
        flag = 0

        for j in range(N - 1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                count += 1
                flag = 1
     flag flag = 0 flag 0 for j in range(N - 1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                count += 1
                flag = 1
     j range(N - 1, 0, -1) range N - 1 N 1 0 -1 if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                count += 1
                flag = 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 flag = 1 flag 1 formatting(A) formatting A print(count) print count A A N N N = int(input()) N int(input()) int input() input inputList = list(map(int, input().split())) inputList list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bubbleSort(inputList, N) bubbleSort inputList N N = int(input()) int(input()) N inputList = list(map(int, input().split())) list(map(int, input().split())) inputList def formatting(nums):
    for i in range(len(nums)):
        if i != len(nums) - 1:
            print(nums[i], end=' ')
        else:
            print(nums[i]) def formatting(nums):
    for i in range(len(nums)):
        if i != len(nums) - 1:
            print(nums[i], end=' ')
        else:
            print(nums[i]) formatting def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0

        for j in range(N - 1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                count += 1
                flag = 1
    formatting(A)
    print(count) def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0

        for j in range(N - 1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                count += 1
                flag = 1
    formatting(A)
    print(count) bubbleSort
# inputList = list(map(int, '''5
# 5 3 2 4 1'''.split()))
# N = inputList.pop(0)


def formatting(nums):
    for i in range(len(nums)):
        if i != len(nums) - 1:
            print(nums[i], end=' ')
        else:
            print(nums[i])


def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0

        for j in range(N - 1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                count += 1
                flag = 1
    formatting(A)
    print(count)




N = int(input())
inputList = list(map(int, input().split()))

bubbleSort(inputList, N)

