n = int(input())
nums=list(input().split())

def bubbleSort(nums,n):
    flag=True
    count=0
    while flag:
        flag=False
        for j in range(n-1,0,-1):
            if int(nums[j])<int(nums[j-1]):
                tmp=nums[j]
                nums[j]=nums[j-1]
                nums[j-1]=tmp
                flag=True
                count+=1

    print(' '.join(nums))
    print(count)

bubbleSort(nums,n) n = int(input()) n int(input()) int input() input nums=list(input().split()) nums list(input().split()) list input().split() ().split () input split def bubbleSort(nums,n):
    flag=True
    count=0
    while flag:
        flag=False
        for j in range(n-1,0,-1):
            if int(nums[j])<int(nums[j-1]):
                tmp=nums[j]
                nums[j]=nums[j-1]
                nums[j-1]=tmp
                flag=True
                count+=1

    print(' '.join(nums))
    print(count) bubbleSort flag=True flag True count=0 count 0 while flag:
        flag=False
        for j in range(n-1,0,-1):
            if int(nums[j])<int(nums[j-1]):
                tmp=nums[j]
                nums[j]=nums[j-1]
                nums[j-1]=tmp
                flag=True
                count+=1

     flag flag=False flag False for j in range(n-1,0,-1):
            if int(nums[j])<int(nums[j-1]):
                tmp=nums[j]
                nums[j]=nums[j-1]
                nums[j-1]=tmp
                flag=True
                count+=1

     j range(n-1,0,-1) range n-1 n 1 0 -1 if int(nums[j])<int(nums[j-1]):
                tmp=nums[j]
                nums[j]=nums[j-1]
                nums[j-1]=tmp
                flag=True
                count+=1

     int(nums[j])<int(nums[j-1]) int(nums[j]) int nums[j] nums j int(nums[j-1]) int nums[j-1] nums j-1 j 1 tmp=nums[j] tmp nums[j] nums j nums[j]=nums[j-1] nums[j] nums j nums[j-1] nums j-1 j 1 nums[j-1]=tmp nums[j-1] nums j-1 j 1 tmp flag=True flag True count+=1 count 1 print(' '.join(nums)) print ' '.join(nums) ' '.join ' ' join nums print(count) print count nums nums n n bubbleSort(nums,n) bubbleSort nums n nums=list(input().split()) list(input().split()) nums n = int(input()) int(input()) n def bubbleSort(nums,n):
    flag=True
    count=0
    while flag:
        flag=False
        for j in range(n-1,0,-1):
            if int(nums[j])<int(nums[j-1]):
                tmp=nums[j]
                nums[j]=nums[j-1]
                nums[j-1]=tmp
                flag=True
                count+=1

    print(' '.join(nums))
    print(count) def bubbleSort(nums,n):
    flag=True
    count=0
    while flag:
        flag=False
        for j in range(n-1,0,-1):
            if int(nums[j])<int(nums[j-1]):
                tmp=nums[j]
                nums[j]=nums[j-1]
                nums[j-1]=tmp
                flag=True
                count+=1

    print(' '.join(nums))
    print(count) bubbleSort
n = int(input())
nums=list(input().split())

def bubbleSort(nums,n):
    flag=True
    count=0
    while flag:
        flag=False
        for j in range(n-1,0,-1):
            if int(nums[j])<int(nums[j-1]):
                tmp=nums[j]
                nums[j]=nums[j-1]
                nums[j-1]=tmp
                flag=True
                count+=1

    print(' '.join(nums))
    print(count)

bubbleSort(nums,n)
