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

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

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


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

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

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


bubbleSort(A,N)

