import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int n;

	do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 100);

	int []a = new int[n];

	for(int i = 0; i < n; i++)
	    a[i] = In.nextInt();
	
	
	int h = 0;
	int count = 0;
	int flag = 1;

	while(flag == 1)
	    {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    }
	for(int u = 0; u < n-1; u++)
	    System.out.print(a[u] + " ");
	
	System.out.println(a[n - 1]);
	System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main
{
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int n;

	do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 100);

	int []a = new int[n];

	for(int i = 0; i < n; i++)
	    a[i] = In.nextInt();
	
	
	int h = 0;
	int count = 0;
	int flag = 1;

	while(flag == 1)
	    {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    }
	for(int u = 0; u < n-1; u++)
	    System.out.print(a[u] + " ");
	
	System.out.println(a[n - 1]);
	System.out.println(count);
    }
} Main public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int n;

	do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 100);

	int []a = new int[n];

	for(int i = 0; i < n; i++)
	    a[i] = In.nextInt();
	
	
	int h = 0;
	int count = 0;
	int flag = 1;

	while(flag == 1)
	    {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    }
	for(int u = 0; u < n-1; u++)
	    System.out.print(a[u] + " ");
	
	System.out.println(a[n - 1]);
	System.out.println(count);
    } main {
	Scanner In = new Scanner(System.in);

	int n;

	do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 100);

	int []a = new int[n];

	for(int i = 0; i < n; i++)
	    a[i] = In.nextInt();
	
	
	int h = 0;
	int count = 0;
	int flag = 1;

	while(flag == 1)
	    {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    }
	for(int u = 0; u < n-1; u++)
	    System.out.print(a[u] + " ");
	
	System.out.println(a[n - 1]);
	System.out.println(count);
    } Scanner In = new Scanner(System.in); In new Scanner(System.in) int n; n do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 100); 1 >= n && n >= 100 1 >= n 1 n n >= 100 n 100 {
		n = In.nextInt();
	    } n = In.nextInt() n In.nextInt() In.nextInt In int []a = new int[n]; a new int[n] n for(int i = 0; i < n; i++)
	    a[i] = In.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = In.nextInt(); a[i] = In.nextInt() a[i] a i In.nextInt() In.nextInt In int h = 0; h 0 int count = 0; count 0 int flag = 1; flag 1 while(flag == 1)
	    {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    } flag == 1 flag 1 {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    } for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    } int i = 0; int i = 0; i 0 i <= n - 1 i n - 1 n 1 i++ i++ i {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    } {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    } for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    } int j = n - 1; int j = n - 1; j n - 1 n 1 j >= h + 1 j h + 1 h 1 j-- j-- j {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    } {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    } if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    } a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    } int v = a[j]; v a[j] a j a[j] = a[j - 1] a[j] a j a[j - 1] a j - 1 j 1 a[j - 1] = v a[j - 1] a j - 1 j 1 v count++ count flag = 1 flag 1 h++ h flag = 0 flag 0 for(int u = 0; u < n-1; u++)
	    System.out.print(a[u] + " "); int u = 0; int u = 0; u 0 u < n-1 u n-1 n 1 u++ u++ u System.out.print(a[u] + " "); System.out.print(a[u] + " ") System.out.print System.out System System.out a[u] + " " a[u] a u " " System.out.println(a[n - 1]) System.out.println System.out System System.out a[n - 1] a n - 1 n 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main
{
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int n;

	do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 100);

	int []a = new int[n];

	for(int i = 0; i < n; i++)
	    a[i] = In.nextInt();
	
	
	int h = 0;
	int count = 0;
	int flag = 1;

	while(flag == 1)
	    {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    }
	for(int u = 0; u < n-1; u++)
	    System.out.print(a[u] + " ");
	
	System.out.println(a[n - 1]);
	System.out.println(count);
    }
} public class Main
{
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int n;

	do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 100);

	int []a = new int[n];

	for(int i = 0; i < n; i++)
	    a[i] = In.nextInt();
	
	
	int h = 0;
	int count = 0;
	int flag = 1;

	while(flag == 1)
	    {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    }
	for(int u = 0; u < n-1; u++)
	    System.out.print(a[u] + " ");
	
	System.out.println(a[n - 1]);
	System.out.println(count);
    }
} Main
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int n;

	do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 100);

	int []a = new int[n];

	for(int i = 0; i < n; i++)
	    a[i] = In.nextInt();
	
	
	int h = 0;
	int count = 0;
	int flag = 1;

	while(flag == 1)
	    {
		for(int i = 0; i <= n - 1; i++)
		    {
			for(int j = n - 1; j >= h + 1; j--)
			    {
				if(a[j] < a[j-1])
				    {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					count++;
					flag = 1;
				    }
				
			    }
			h++;
			flag = 0;
		    }
		
	    }
	for(int u = 0; u < n-1; u++)
	    System.out.print(a[u] + " ");
	
	System.out.println(a[n - 1]);
	System.out.println(count);
    }
}