import java.util.Scanner;

public class Main {
	public static Scanner sc;
	
	public static void main(String[] args) {
		//宣言
		int N=0;
		int A[]= new int[300];
		sc = new Scanner(System.in);
		int count=0;
		//入力
		N= sc.nextInt();
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		//出力
		for(int j=0;j<N;j++) {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		}
		for(int i=0;i<N;i++) {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		}
		System.out.println(count);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static Scanner sc;
	
	public static void main(String[] args) {
		//宣言
		int N=0;
		int A[]= new int[300];
		sc = new Scanner(System.in);
		int count=0;
		//入力
		N= sc.nextInt();
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		//出力
		for(int j=0;j<N;j++) {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		}
		for(int i=0;i<N;i++) {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		}
		System.out.println(count);
	}
} Main public static Scanner sc; sc public static void main(String[] args) {
		//宣言
		int N=0;
		int A[]= new int[300];
		sc = new Scanner(System.in);
		int count=0;
		//入力
		N= sc.nextInt();
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		//出力
		for(int j=0;j<N;j++) {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		}
		for(int i=0;i<N;i++) {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		}
		System.out.println(count);
	} main {
		//宣言
		int N=0;
		int A[]= new int[300];
		sc = new Scanner(System.in);
		int count=0;
		//入力
		N= sc.nextInt();
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		//出力
		for(int j=0;j<N;j++) {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		}
		for(int i=0;i<N;i++) {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		}
		System.out.println(count);
	} int N=0; N 0 int A[]= new int[300]; A new int[300] 300 sc = new Scanner(System.in) sc new Scanner(System.in) int count=0; count 0 N= sc.nextInt() N sc.nextInt() sc.nextInt sc 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 for(int j=0;j<N;j++) {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		} int j=0; int j=0; j 0 j<N j N j++ j++ j {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		} {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		} for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			} int i=N-1; int i=N-1; i N-1 N 1 i>=j+1 i j+1 j 1 i-- i-- i {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			} {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			} if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				} A[i]<A[i-1] A[i] A i A[i-1] A i-1 i 1 {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				} int w = A[i]; w A[i] A i A[i]=A[i-1] A[i] A i A[i-1] A i-1 i 1 A[i-1]=w A[i-1] A i-1 i 1 w count++ count for(int i=0;i<N;i++) {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		} {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		} if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			} i>=0 &&i<N-1 i>=0 i 0 i<N-1 i N-1 N 1 {
				System.out.print(A[i]+" ");
			} System.out.print(A[i]+" ") System.out.print System.out System System.out A[i]+" " A[i] A i " " if(i==N-1) {
				System.out.println(A[i]);
			} i==N-1 i N-1 N 1 {
				System.out.println(A[i]);
			} System.out.println(A[i]) System.out.println System.out System System.out A[i] A i System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static Scanner sc;
	
	public static void main(String[] args) {
		//宣言
		int N=0;
		int A[]= new int[300];
		sc = new Scanner(System.in);
		int count=0;
		//入力
		N= sc.nextInt();
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		//出力
		for(int j=0;j<N;j++) {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		}
		for(int i=0;i<N;i++) {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		}
		System.out.println(count);
	}
} public class Main {
	public static Scanner sc;
	
	public static void main(String[] args) {
		//宣言
		int N=0;
		int A[]= new int[300];
		sc = new Scanner(System.in);
		int count=0;
		//入力
		N= sc.nextInt();
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		//出力
		for(int j=0;j<N;j++) {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		}
		for(int i=0;i<N;i++) {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		}
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	
	public static void main(String[] args) {
		//宣言
		int N=0;
		int A[]= new int[300];
		sc = new Scanner(System.in);
		int count=0;
		//入力
		N= sc.nextInt();
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		//出力
		for(int j=0;j<N;j++) {
			for(int i=N-1;i>=j+1;i--) {
				if(A[i]<A[i-1]) {
					int w = A[i];
					A[i]=A[i-1];
					A[i-1]=w;
					count++;
				}
			}	
		}
		for(int i=0;i<N;i++) {
			if(i>=0 &&i<N-1) {
				System.out.print(A[i]+" ");
			}else if(i==N-1) {
				System.out.println(A[i]);
			}
		}
		System.out.println(count);
	}
}
