#ALDS1_2-A Bubble Sort
def bubbleSort(A,N):
    c=0
    flag=1
    while flag:
        flag=0
        j=N-1
        while j>0:
            if(int(A[j])<int(A[j-1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1
    return c

N=int(input())
A=input().split()
c=bubbleSort(A,N)
S=""
for i in range(N-1):
    S+=A[i]+" "
S+=str(A[-1])
print(S)
print(c) def bubbleSort(A,N):
    c=0
    flag=1
    while flag:
        flag=0
        j=N-1
        while j>0:
            if(int(A[j])<int(A[j-1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1
    return c bubbleSort c=0 c 0 flag=1 flag 1 while flag:
        flag=0
        j=N-1
        while j>0:
            if(int(A[j])<int(A[j-1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1
     flag flag=0 flag 0 j=N-1 j N-1 N 1 while j>0:
            if(int(A[j])<int(A[j-1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1
     j>0 j 0 if(int(A[j])<int(A[j-1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
             int(A[j])<int(A[j-1]) int(A[j]) int A[j] A j int(A[j-1]) int A[j-1] A j-1 j 1 c+=1 c 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 j-=1 j 1 return c c A A N N N=int(input()) N int(input()) int input() input A=input().split() A input().split() ().split () input split c=bubbleSort(A,N) c bubbleSort(A,N) bubbleSort A N S="" S "" for i in range(N-1):
    S+=A[i]+" " i range(N-1) range N-1 N 1 S+=A[i]+" " S A[i]+" " A[i] A i " " S+=str(A[-1]) S str(A[-1]) str A[-1] A -1 print(S) print S print(c) print c S+=A[i]+" " A[i]+" " S S+=str(A[-1]) str(A[-1]) S def bubbleSort(A,N):
    c=0
    flag=1
    while flag:
        flag=0
        j=N-1
        while j>0:
            if(int(A[j])<int(A[j-1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1
    return c def bubbleSort(A,N):
    c=0
    flag=1
    while flag:
        flag=0
        j=N-1
        while j>0:
            if(int(A[j])<int(A[j-1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1
    return c bubbleSort A=input().split() input().split() A c=bubbleSort(A,N) bubbleSort(A,N) c N=int(input()) int(input()) N S="" "" S
#ALDS1_2-A Bubble Sort
def bubbleSort(A,N):
    c=0
    flag=1
    while flag:
        flag=0
        j=N-1
        while j>0:
            if(int(A[j])<int(A[j-1])):
                c+=1
                A[j],A[j-1]=A[j-1],A[j]
                flag=1
            j-=1
    return c

N=int(input())
A=input().split()
c=bubbleSort(A,N)
S=""
for i in range(N-1):
    S+=A[i]+" "
S+=str(A[-1])
print(S)
print(c)