numberOfArray=int(input())
arrayList=list(map(int,input().split()))

def bubbleSort():
    frag=1
    count=0
    while frag:
        frag=0
        for i in range(1,numberOfArray):
            if arrayList[i-1]>arrayList[i]:
                arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
                frag=1
                count+=1
    arrayForReturn=str(arrayList[0])
    for i2 in range(1,numberOfArray):
        arrayForReturn+=" "+str(arrayList[i2])
    print(arrayForReturn)
    print(count)

#------------------main--------------
bubbleSort() numberOfArray=int(input()) numberOfArray int(input()) int input() input arrayList=list(map(int,input().split())) arrayList list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def bubbleSort():
    frag=1
    count=0
    while frag:
        frag=0
        for i in range(1,numberOfArray):
            if arrayList[i-1]>arrayList[i]:
                arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
                frag=1
                count+=1
    arrayForReturn=str(arrayList[0])
    for i2 in range(1,numberOfArray):
        arrayForReturn+=" "+str(arrayList[i2])
    print(arrayForReturn)
    print(count)

#------------------main-------------- bubbleSort frag=1 frag 1 count=0 count 0 while frag:
        frag=0
        for i in range(1,numberOfArray):
            if arrayList[i-1]>arrayList[i]:
                arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
                frag=1
                count+=1
     frag frag=0 frag 0 for i in range(1,numberOfArray):
            if arrayList[i-1]>arrayList[i]:
                arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
                frag=1
                count+=1
     i range(1,numberOfArray) range 1 numberOfArray if arrayList[i-1]>arrayList[i]:
                arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
                frag=1
                count+=1
     arrayList[i-1]>arrayList[i] arrayList[i-1] arrayList i-1 i 1 arrayList[i] arrayList i arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1] arrayList[i-1] arrayList i-1 i 1 arrayList[i] arrayList i arrayList[i] arrayList i arrayList[i-1] arrayList i-1 i 1 frag=1 frag 1 count+=1 count 1 arrayForReturn=str(arrayList[0]) arrayForReturn str(arrayList[0]) str arrayList[0] arrayList 0 for i2 in range(1,numberOfArray):
        arrayForReturn+=" "+str(arrayList[i2])
     i2 range(1,numberOfArray) range 1 numberOfArray arrayForReturn+=" "+str(arrayList[i2]) arrayForReturn " "+str(arrayList[i2]) " " str(arrayList[i2]) str arrayList[i2] arrayList i2 print(arrayForReturn) print arrayForReturn print(count) print count bubbleSort() bubbleSort arrayList=list(map(int,input().split())) list(map(int,input().split())) arrayList def bubbleSort():
    frag=1
    count=0
    while frag:
        frag=0
        for i in range(1,numberOfArray):
            if arrayList[i-1]>arrayList[i]:
                arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
                frag=1
                count+=1
    arrayForReturn=str(arrayList[0])
    for i2 in range(1,numberOfArray):
        arrayForReturn+=" "+str(arrayList[i2])
    print(arrayForReturn)
    print(count)

#------------------main-------------- def bubbleSort():
    frag=1
    count=0
    while frag:
        frag=0
        for i in range(1,numberOfArray):
            if arrayList[i-1]>arrayList[i]:
                arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
                frag=1
                count+=1
    arrayForReturn=str(arrayList[0])
    for i2 in range(1,numberOfArray):
        arrayForReturn+=" "+str(arrayList[i2])
    print(arrayForReturn)
    print(count)

#------------------main-------------- bubbleSort numberOfArray=int(input()) int(input()) numberOfArray
numberOfArray=int(input())
arrayList=list(map(int,input().split()))

def bubbleSort():
    frag=1
    count=0
    while frag:
        frag=0
        for i in range(1,numberOfArray):
            if arrayList[i-1]>arrayList[i]:
                arrayList[i-1],arrayList[i]=arrayList[i],arrayList[i-1]
                frag=1
                count+=1
    arrayForReturn=str(arrayList[0])
    for i2 in range(1,numberOfArray):
        arrayForReturn+=" "+str(arrayList[i2])
    print(arrayForReturn)
    print(count)

#------------------main--------------
bubbleSort()
