import sys

l = []
for i in sys.stdin:
    l.append(i.split())

def bubble_sort(data):
    count = 0
    for i in range(0,len(data)):
        for j in range(len(data)-1,i,-1):
            if data[j] < data[j-1]:
                count += 1
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
    for i in range(0,len(data)):
        print(data[i],end='')
        print(" ",end='') if i < len(data)-1 else print()
    print(count)

for i in range(0,len(l[1])):
    l[1][i] = int(l[1][i])

bubble_sort(l[1]) import sys sys l = [] l [] for i in sys.stdin:
    l.append(i.split()) i sys.stdin sys stdin l.append(i.split()) l.append l append i.split() i.split i split def bubble_sort(data):
    count = 0
    for i in range(0,len(data)):
        for j in range(len(data)-1,i,-1):
            if data[j] < data[j-1]:
                count += 1
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
    for i in range(0,len(data)):
        print(data[i],end='')
        print(" ",end='') if i < len(data)-1 else print()
    print(count) bubble_sort count = 0 count 0 for i in range(0,len(data)):
        for j in range(len(data)-1,i,-1):
            if data[j] < data[j-1]:
                count += 1
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
     i range(0,len(data)) range 0 len(data) len data for j in range(len(data)-1,i,-1):
            if data[j] < data[j-1]:
                count += 1
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
     j range(len(data)-1,i,-1) range len(data)-1 len(data) len data 1 i -1 if data[j] < data[j-1]:
                count += 1
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
     data[j] < data[j-1] data[j] data j data[j-1] data j-1 j 1 count += 1 count 1 temp = data[j] temp data[j] data j data[j] = data[j-1] data[j] data j data[j-1] data j-1 j 1 data[j-1] = temp data[j-1] data j-1 j 1 temp for i in range(0,len(data)):
        print(data[i],end='')
        print(" ",end='') if i < len(data)-1 else print()
     i range(0,len(data)) range 0 len(data) len data print(data[i],end='') print data[i] data i end='' end '' print(" ",end='') if i < len(data)-1 else print() i < len(data)-1 i len(data)-1 len(data) len data 1 print(" ",end='') print " " end='' end '' print() print print(count) print count data data for i in range(0,len(l[1])):
    l[1][i] = int(l[1][i]) i range(0,len(l[1])) range 0 len(l[1]) len l[1] l 1 l[1][i] = int(l[1][i]) l[1][i] [1] l 1 i int(l[1][i]) int l[1][i] [1] l 1 i bubble_sort(l[1]) bubble_sort l[1] l 1 def bubble_sort(data):
    count = 0
    for i in range(0,len(data)):
        for j in range(len(data)-1,i,-1):
            if data[j] < data[j-1]:
                count += 1
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
    for i in range(0,len(data)):
        print(data[i],end='')
        print(" ",end='') if i < len(data)-1 else print()
    print(count) def bubble_sort(data):
    count = 0
    for i in range(0,len(data)):
        for j in range(len(data)-1,i,-1):
            if data[j] < data[j-1]:
                count += 1
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
    for i in range(0,len(data)):
        print(data[i],end='')
        print(" ",end='') if i < len(data)-1 else print()
    print(count) bubble_sort l = [] [] l
import sys

l = []
for i in sys.stdin:
    l.append(i.split())

def bubble_sort(data):
    count = 0
    for i in range(0,len(data)):
        for j in range(len(data)-1,i,-1):
            if data[j] < data[j-1]:
                count += 1
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
    for i in range(0,len(data)):
        print(data[i],end='')
        print(" ",end='') if i < len(data)-1 else print()
    print(count)

for i in range(0,len(l[1])):
    l[1][i] = int(l[1][i])

bubble_sort(l[1])
