# insertionSort                                                
# divide list into ordered part and part wait to sort          
# select one from part wait to sort and insert into ordered part                                                              
global r, signals                                              
r, signals = 0, False                                          
def insertionSort(A):                                          
    global r, signals                                          
    # Get length of A                                          
    l = len(A)                                                 
    for i in range(l):                                         
        # Selected i-th element to swap from 0 to n            
        v = A[i]                                               
        # j is point to tail of order                          
        j = i - 1                                              
        # Move forward, Control order of sorted                
        while j >= 0 and A[j] > v:                             
            A[j+1] = A[j]                                      
            j -= 1                                             
            signals = True                                     
        A[j+1] = v                                             
        r += 1 if signals else 0                               
        signals = False                                        
    return A                                                   
                                                               
raw_input()                                                    
res, l = "", 0                                                 
for i in insertionSort(map(int, raw_input().split())):         
    res += (" " if l != 0 else "") + str(i)                    
    l += 1                                                     
print res
print r