import java.util.Scanner;
class Main {
	public static void main(String[] args){
		final int Number=100;
		try(Scanner sc = new Scanner(System.in)){
			int N = Integer.parseInt(sc.next());
			int[] p=new int[N];
			for(int i=0;i<N;i++) p[i] = Integer.parseInt(sc.next());
			int cnt=0;
			for(int i=0;i<N;i++){
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			}
			
			
			System.out.print(p[0]);
			for(int i=1;i<N;i++)System.out.print(" "+p[i]);
			System.out.println();
			System.out.println(cnt);
		}
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args){
		final int Number=100;
		try(Scanner sc = new Scanner(System.in)){
			int N = Integer.parseInt(sc.next());
			int[] p=new int[N];
			for(int i=0;i<N;i++) p[i] = Integer.parseInt(sc.next());
			int cnt=0;
			for(int i=0;i<N;i++){
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			}
			
			
			System.out.print(p[0]);
			for(int i=1;i<N;i++)System.out.print(" "+p[i]);
			System.out.println();
			System.out.println(cnt);
		}
	}
} Main public static void main(String[] args){
		final int Number=100;
		try(Scanner sc = new Scanner(System.in)){
			int N = Integer.parseInt(sc.next());
			int[] p=new int[N];
			for(int i=0;i<N;i++) p[i] = Integer.parseInt(sc.next());
			int cnt=0;
			for(int i=0;i<N;i++){
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			}
			
			
			System.out.print(p[0]);
			for(int i=1;i<N;i++)System.out.print(" "+p[i]);
			System.out.println();
			System.out.println(cnt);
		}
	} main {
		final int Number=100;
		try(Scanner sc = new Scanner(System.in)){
			int N = Integer.parseInt(sc.next());
			int[] p=new int[N];
			for(int i=0;i<N;i++) p[i] = Integer.parseInt(sc.next());
			int cnt=0;
			for(int i=0;i<N;i++){
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			}
			
			
			System.out.print(p[0]);
			for(int i=1;i<N;i++)System.out.print(" "+p[i]);
			System.out.println();
			System.out.println(cnt);
		}
	} final int Number=100; Number 100 try(Scanner sc = new Scanner(System.in)){
			int N = Integer.parseInt(sc.next());
			int[] p=new int[N];
			for(int i=0;i<N;i++) p[i] = Integer.parseInt(sc.next());
			int cnt=0;
			for(int i=0;i<N;i++){
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			}
			
			
			System.out.print(p[0]);
			for(int i=1;i<N;i++)System.out.print(" "+p[i]);
			System.out.println();
			System.out.println(cnt);
		} {
			int N = Integer.parseInt(sc.next());
			int[] p=new int[N];
			for(int i=0;i<N;i++) p[i] = Integer.parseInt(sc.next());
			int cnt=0;
			for(int i=0;i<N;i++){
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			}
			
			
			System.out.print(p[0]);
			for(int i=1;i<N;i++)System.out.print(" "+p[i]);
			System.out.println();
			System.out.println(cnt);
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] p=new int[N]; p new int[N] N for(int i=0;i<N;i++) p[i] = Integer.parseInt(sc.next()); int i=0; int i=0; i 0 i<N i N i++ i++ i p[i] = Integer.parseInt(sc.next()); p[i] = Integer.parseInt(sc.next()) p[i] p i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int cnt=0; cnt 0 for(int i=0;i<N;i++){
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			} int i=0; int i=0; i 0 i<N i N i++ i++ i {
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			} {
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			} for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				} int j=N-1; int j=N-1; j N-1 N 1 j>i j i j-- j-- j {
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				} {
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				} if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					} p[j]<p[j-1] p[j] p j p[j-1] p j-1 j 1 {
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					} cnt++ cnt int tmp=p[j-1]; tmp p[j-1] p j-1 j 1 p[j-1]=p[j] p[j-1] p j-1 j 1 p[j] p j p[j]=tmp p[j] p j tmp System.out.print(p[0]) System.out.print System.out System System.out p[0] p 0 for(int i=1;i<N;i++)System.out.print(" "+p[i]); int i=1; int i=1; i 1 i<N i N i++ i++ i System.out.print(" "+p[i]); System.out.print(" "+p[i]) System.out.print System.out System System.out " "+p[i] " " p[i] p i System.out.println() System.out.println System.out System System.out System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		final int Number=100;
		try(Scanner sc = new Scanner(System.in)){
			int N = Integer.parseInt(sc.next());
			int[] p=new int[N];
			for(int i=0;i<N;i++) p[i] = Integer.parseInt(sc.next());
			int cnt=0;
			for(int i=0;i<N;i++){
				for(int j=N-1;j>i;j--){
					if(p[j]<p[j-1]){
						cnt++;
						int tmp=p[j-1];
						p[j-1]=p[j];
						p[j]=tmp;
					}
				}
			}
			
			
			System.out.print(p[0]);
			for(int i=1;i<N;i++)System.out.print(" "+p[i]);
			System.out.println();
			System.out.println(cnt);
		}
	}
}