import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//データ読み込み
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		int s = 1;
		int counter = 0;
		
		while (true){
			if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			}
			
			for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			}
			s++;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		//データ読み込み
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		int s = 1;
		int counter = 0;
		
		while (true){
			if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			}
			
			for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			}
			s++;
		}
	}
} Main public static void main(String[] args){
		//データ読み込み
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		int s = 1;
		int counter = 0;
		
		while (true){
			if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			}
			
			for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			}
			s++;
		}
	} main {
		//データ読み込み
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		int s = 1;
		int counter = 0;
		
		while (true){
			if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			}
			
			for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			}
			s++;
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int a[] = new int[n]; a new int[n] n for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int s = 1; s 1 int counter = 0; counter 0 while (true){
			if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			}
			
			for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			}
			s++;
		} true {
			if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			}
			
			for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			}
			s++;
		} if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			} s == n s n {
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			} System.out.print(a[0]) System.out.print System.out System System.out a[0] a 0 for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
					System.out.print(" " + a[i]);
				} {
					System.out.print(" " + a[i]);
				} System.out.print(" " + a[i]) System.out.print System.out System System.out " " + a[i] " " a[i] a i System.out.print("\n") System.out.print System.out System System.out "\n" System.out.println(counter) System.out.println System.out System System.out counter break; for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			} int i = n - 1; int i = n - 1; i n - 1 n 1 i >= s i s i-- i-- i {
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			} {
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			} if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				} a[i - 1] > a[i] a[i - 1] a i - 1 i 1 a[i] a i {
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				} int temp = a[i - 1]; temp a[i - 1] a i - 1 i 1 a[i - 1] = a[i] a[i - 1] a i - 1 i 1 a[i] a i a[i] = temp a[i] a i temp counter++ counter s++ s String[] args args public class Main{
	public static void main(String[] args){
		//データ読み込み
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		int s = 1;
		int counter = 0;
		
		while (true){
			if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			}
			
			for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			}
			s++;
		}
	}
} public class Main{
	public static void main(String[] args){
		//データ読み込み
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		int s = 1;
		int counter = 0;
		
		while (true){
			if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			}
			
			for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			}
			s++;
		}
	}
} Main
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//データ読み込み
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		int s = 1;
		int counter = 0;
		
		while (true){
			if (s == n){
				System.out.print(a[0]);
				
				for(int i = 1; i < n; i++){
					System.out.print(" " + a[i]);
				}
				System.out.print("\n");
				System.out.println(counter);
				break;
			}
			
			for(int i = n - 1; i >= s; i--){
				//左の要素の方が大きかった時には、swap
				if(a[i - 1] > a[i]){
					int temp = a[i - 1];
					a[i - 1] = a[i];
					a[i] = temp;
					counter++;
				}	
			}
			s++;
		}
	}
}
