def bubbleSort( nums ):
	cnt = 0
	for i in range( 0, len( nums ) ):
		for j in range( len( nums )-1 , i, -1 ):
			if nums[j] < nums[ j-1 ]:
				nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j]
				cnt += 1

	print( " ".join( map( str, nums) ) )
	print( cnt )


n = int( raw_input( ) )
nums = [ int( val ) for val in raw_input( ).split( " " ) ]
bubbleSort( nums ) def bubbleSort( nums ):
	cnt = 0
	for i in range( 0, len( nums ) ):
		for j in range( len( nums )-1 , i, -1 ):
			if nums[j] < nums[ j-1 ]:
				nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j]
				cnt += 1

	print( " ".join( map( str, nums) ) )
	print( cnt ) bubbleSort cnt = 0 cnt 0 for i in range( 0, len( nums ) ):
		for j in range( len( nums )-1 , i, -1 ):
			if nums[j] < nums[ j-1 ]:
				nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j]
				cnt += 1

	 i range( 0, len( nums ) ) range 0 len( nums ) len nums for j in range( len( nums )-1 , i, -1 ):
			if nums[j] < nums[ j-1 ]:
				nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j]
				cnt += 1

	 j range( len( nums )-1 , i, -1 ) range len( nums )-1 len( nums ) len nums 1 i -1 if nums[j] < nums[ j-1 ]:
				nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j]
				cnt += 1

	 nums[j] < nums[ j-1 ] nums[j] nums j nums[ j-1 ] nums j-1 j 1 nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j] nums[j] nums j nums[ j-1 ] nums j-1 j 1 nums[ j-1 ] nums j-1 j 1 nums[j] nums j cnt += 1 cnt 1 print( " ".join( map( str, nums) ) ) print " ".join( map( str, nums) ) " ".join " " join map( str, nums) map str nums print( cnt ) print cnt nums nums n = int( raw_input( ) ) n int( raw_input( ) ) int raw_input( ) raw_input int( val ) for val in raw_input( ).split( " " ) for val in raw_input( ).split( " " ) val raw_input( ).split( " " ) ( ).split ( ) raw_input split " " for val in raw_input( ).split( " " ) int( val ) int val nums = [ int( val ) for val in raw_input( ).split( " " ) ] nums [ int( val ) for val in raw_input( ).split( " " ) ] bubbleSort( nums ) bubbleSort nums n = int( raw_input( ) ) int( raw_input( ) ) n def bubbleSort( nums ):
	cnt = 0
	for i in range( 0, len( nums ) ):
		for j in range( len( nums )-1 , i, -1 ):
			if nums[j] < nums[ j-1 ]:
				nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j]
				cnt += 1

	print( " ".join( map( str, nums) ) )
	print( cnt ) def bubbleSort( nums ):
	cnt = 0
	for i in range( 0, len( nums ) ):
		for j in range( len( nums )-1 , i, -1 ):
			if nums[j] < nums[ j-1 ]:
				nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j]
				cnt += 1

	print( " ".join( map( str, nums) ) )
	print( cnt ) bubbleSort nums = [ int( val ) for val in raw_input( ).split( " " ) ] [ int( val ) for val in raw_input( ).split( " " ) ] nums
def bubbleSort( nums ):
	cnt = 0
	for i in range( 0, len( nums ) ):
		for j in range( len( nums )-1 , i, -1 ):
			if nums[j] < nums[ j-1 ]:
				nums[j], nums[ j-1 ] = nums[ j-1 ], nums[j]
				cnt += 1

	print( " ".join( map( str, nums) ) )
	print( cnt )


n = int( raw_input( ) )
nums = [ int( val ) for val in raw_input( ).split( " " ) ]
bubbleSort( nums )