class Main
{
	static int count = 0;
	public static void main( String[] args )
	{
		java.util.Scanner sc = new java.util.Scanner( System.in );
		int n = sc.nextInt();
		int[] data = new int[n];
		for( int i = 0 ; i < n ; i++ )
			data[i] = sc.nextInt();
		data = bubbleSort( data, n );
		for( int i = 0 ; i < n-1 ; i++ )
			System.out.printf( "%d " ,data[i] );
		System.out.println( data[n-1] );
		System.out.println( count );
	}
	static int[] bubbleSort( int[] data, int n )
	{
		boolean flag = true;
		int work;
		while( flag )
		{
			flag = false;
			for( int j = n-1 ; j > 0 ; j-- )
			{
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			}
		}
		return data;
	}
} class Main
{
	static int count = 0;
	public static void main( String[] args )
	{
		java.util.Scanner sc = new java.util.Scanner( System.in );
		int n = sc.nextInt();
		int[] data = new int[n];
		for( int i = 0 ; i < n ; i++ )
			data[i] = sc.nextInt();
		data = bubbleSort( data, n );
		for( int i = 0 ; i < n-1 ; i++ )
			System.out.printf( "%d " ,data[i] );
		System.out.println( data[n-1] );
		System.out.println( count );
	}
	static int[] bubbleSort( int[] data, int n )
	{
		boolean flag = true;
		int work;
		while( flag )
		{
			flag = false;
			for( int j = n-1 ; j > 0 ; j-- )
			{
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			}
		}
		return data;
	}
} Main static int count = 0; count 0 public static void main( String[] args )
	{
		java.util.Scanner sc = new java.util.Scanner( System.in );
		int n = sc.nextInt();
		int[] data = new int[n];
		for( int i = 0 ; i < n ; i++ )
			data[i] = sc.nextInt();
		data = bubbleSort( data, n );
		for( int i = 0 ; i < n-1 ; i++ )
			System.out.printf( "%d " ,data[i] );
		System.out.println( data[n-1] );
		System.out.println( count );
	} main {
		java.util.Scanner sc = new java.util.Scanner( System.in );
		int n = sc.nextInt();
		int[] data = new int[n];
		for( int i = 0 ; i < n ; i++ )
			data[i] = sc.nextInt();
		data = bubbleSort( data, n );
		for( int i = 0 ; i < n-1 ; i++ )
			System.out.printf( "%d " ,data[i] );
		System.out.println( data[n-1] );
		System.out.println( count );
	} java.util.Scanner sc = new java.util.Scanner( System.in ); sc new java.util.Scanner( System.in ) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] data = new int[n]; data new int[n] n for( int i = 0 ; i < n ; i++ )
			data[i] = sc.nextInt(); int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i data[i] = sc.nextInt(); data[i] = sc.nextInt() data[i] data i sc.nextInt() sc.nextInt sc data = bubbleSort( data, n ) data bubbleSort( data, n ) bubbleSort data n for( int i = 0 ; i < n-1 ; i++ )
			System.out.printf( "%d " ,data[i] ); int i = 0 ; int i = 0 ; i 0 i < n-1 i n-1 n 1 i++ i++ i System.out.printf( "%d " ,data[i] ); System.out.printf( "%d " ,data[i] ) System.out.printf System.out System System.out "%d " data[i] data i System.out.println( data[n-1] ) System.out.println System.out System System.out data[n-1] data n-1 n 1 System.out.println( count ) System.out.println System.out System System.out count String[] args args static int[] bubbleSort( int[] data, int n )
	{
		boolean flag = true;
		int work;
		while( flag )
		{
			flag = false;
			for( int j = n-1 ; j > 0 ; j-- )
			{
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			}
		}
		return data;
	} bubbleSort {
		boolean flag = true;
		int work;
		while( flag )
		{
			flag = false;
			for( int j = n-1 ; j > 0 ; j-- )
			{
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			}
		}
		return data;
	} boolean flag = true; flag true int work; work while( flag )
		{
			flag = false;
			for( int j = n-1 ; j > 0 ; j-- )
			{
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			}
		} flag {
			flag = false;
			for( int j = n-1 ; j > 0 ; j-- )
			{
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			}
		} flag = false flag false for( int j = n-1 ; j > 0 ; j-- )
			{
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			} int j = n-1 ; int j = n-1 ; j n-1 n 1 j > 0 j 0 j-- j-- j {
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			} {
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			} if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				} data[j] < data[j-1] data[j] data j data[j-1] data j-1 j 1 {
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				} work = data[j] work data[j] data j data[j] = data[j-1] data[j] data j data[j-1] data j-1 j 1 data[j-1] = work data[j-1] data j-1 j 1 work flag = true flag true count++ count return data; data int[] data data int n n
class Main
{
	static int count = 0;
	public static void main( String[] args )
	{
		java.util.Scanner sc = new java.util.Scanner( System.in );
		int n = sc.nextInt();
		int[] data = new int[n];
		for( int i = 0 ; i < n ; i++ )
			data[i] = sc.nextInt();
		data = bubbleSort( data, n );
		for( int i = 0 ; i < n-1 ; i++ )
			System.out.printf( "%d " ,data[i] );
		System.out.println( data[n-1] );
		System.out.println( count );
	}
	static int[] bubbleSort( int[] data, int n )
	{
		boolean flag = true;
		int work;
		while( flag )
		{
			flag = false;
			for( int j = n-1 ; j > 0 ; j-- )
			{
				if( data[j] < data[j-1] ){
					work = data[j];
					data[j] = data[j-1];
					data[j-1] = work;
					flag = true;//????????£??\????´?????????¨????????´???
					count++;
				}
			}
		}
		return data;
	}
}