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]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = 1
                count += 1
    return A,count

N = int(input())
A = list(map(int, input().split()))
A,count = bubbleSort(A,N)
print(" ".join(map(str,A)))
print("%d"%(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]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = 1
                count += 1
    return A,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]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = 1
                count += 1
     flag flag = 0 flag 0 for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = 1
                count += 1
     j range(N-1,0,-1) range N-1 N 1 0 -1 if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = 1
                count += 1
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j],A[j-1] = A[j-1],A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j flag = 1 flag 1 count += 1 count 1 return A,count return A,count A 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 A,count = bubbleSort(A,N) A bubbleSort(A,N) bubbleSort A N count print(" ".join(map(str,A))) print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print("%d"%(count)) print "%d"%(count) "%d" count A,count = bubbleSort(A,N) bubbleSort(A,N) A 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]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = 1
                count += 1
    return A,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]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = 1
                count += 1
    return A,count bubbleSort N = int(input()) int(input()) N A = list(map(int, input().split())) list(map(int, input().split())) A count = bubbleSort(A,N) bubbleSort(A,N) 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]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = 1
                count += 1
    return A,count

N = int(input())
A = list(map(int, input().split()))
A,count = bubbleSort(A,N)
print(" ".join(map(str,A)))
print("%d"%(count))

