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

def BubbleSort(A):
    count = 0
    for i in range(len(A)):
        for j in reversed(range(i+1,len(A))):
            if A[j]<A[j-1]:
                #入れ替え
                a = A[j]
                b = A[j-1]
                A[j-1] = a
                A[j] = b
                count+=1
    return [A,count]

result = BubbleSort(li)    

print(" ".join(list(map(str,result[0]))))
print(result[1]) N = int(input()) N int(input()) int input() input li = list(map(int,input().split())) li list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def BubbleSort(A):
    count = 0
    for i in range(len(A)):
        for j in reversed(range(i+1,len(A))):
            if A[j]<A[j-1]:
                #入れ替え
                a = A[j]
                b = A[j-1]
                A[j-1] = a
                A[j] = b
                count+=1
    return [A,count] BubbleSort count = 0 count 0 for i in range(len(A)):
        for j in reversed(range(i+1,len(A))):
            if A[j]<A[j-1]:
                #入れ替え
                a = A[j]
                b = A[j-1]
                A[j-1] = a
                A[j] = b
                count+=1
     i range(len(A)) range len(A) len A for j in reversed(range(i+1,len(A))):
            if A[j]<A[j-1]:
                #入れ替え
                a = A[j]
                b = A[j-1]
                A[j-1] = a
                A[j] = b
                count+=1
     j reversed(range(i+1,len(A))) reversed range(i+1,len(A)) range i+1 i 1 len(A) len A if A[j]<A[j-1]:
                #入れ替え
                a = A[j]
                b = A[j-1]
                A[j-1] = a
                A[j] = b
                count+=1
     A[j]<A[j-1] A[j] A j A[j-1] A j-1 j 1 a = A[j] a A[j] A j b = A[j-1] b A[j-1] A j-1 j 1 A[j-1] = a A[j-1] A j-1 j 1 a A[j] = b A[j] A j b count+=1 count 1 return [A,count] [A,count] A count A A result = BubbleSort(li) result BubbleSort(li) BubbleSort li print(" ".join(list(map(str,result[0])))) print " ".join(list(map(str,result[0]))) " ".join " " join list(map(str,result[0])) list map(str,result[0]) map str result[0] result 0 print(result[1]) print result[1] result 1 N = int(input()) int(input()) N def BubbleSort(A):
    count = 0
    for i in range(len(A)):
        for j in reversed(range(i+1,len(A))):
            if A[j]<A[j-1]:
                #入れ替え
                a = A[j]
                b = A[j-1]
                A[j-1] = a
                A[j] = b
                count+=1
    return [A,count] def BubbleSort(A):
    count = 0
    for i in range(len(A)):
        for j in reversed(range(i+1,len(A))):
            if A[j]<A[j-1]:
                #入れ替え
                a = A[j]
                b = A[j-1]
                A[j-1] = a
                A[j] = b
                count+=1
    return [A,count] BubbleSort li = list(map(int,input().split())) list(map(int,input().split())) li result = BubbleSort(li) BubbleSort(li) result

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

def BubbleSort(A):
    count = 0
    for i in range(len(A)):
        for j in reversed(range(i+1,len(A))):
            if A[j]<A[j-1]:
                #入れ替え
                a = A[j]
                b = A[j-1]
                A[j-1] = a
                A[j] = b
                count+=1
    return [A,count]

result = BubbleSort(li)    

print(" ".join(list(map(str,result[0]))))
print(result[1])
