import java.util.Scanner;
public class Main {
	static void swap(int[] data,int x){
		int tmp=data[x];
		data[x]=data[x-1];
		data[x-1]=tmp;
	}
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int data[]=new int[N];
		int count=0;
		for(int i=0;i<N;i++){
			data[i]=scan.nextInt();
		}
		for(int i=0;i<N;i++){
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		}
		System.out.println();
		System.out.println(count);
		scan.close();
		
	}
	
} import java.util.Scanner; Scanner java.util public class Main {
	static void swap(int[] data,int x){
		int tmp=data[x];
		data[x]=data[x-1];
		data[x-1]=tmp;
	}
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int data[]=new int[N];
		int count=0;
		for(int i=0;i<N;i++){
			data[i]=scan.nextInt();
		}
		for(int i=0;i<N;i++){
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		}
		System.out.println();
		System.out.println(count);
		scan.close();
		
	}
	
} Main static void swap(int[] data,int x){
		int tmp=data[x];
		data[x]=data[x-1];
		data[x-1]=tmp;
	} swap {
		int tmp=data[x];
		data[x]=data[x-1];
		data[x-1]=tmp;
	} int tmp=data[x]; tmp data[x] data x data[x]=data[x-1] data[x] data x data[x-1] data x-1 x 1 data[x-1]=tmp data[x-1] data x-1 x 1 tmp int[] data data int x x public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int data[]=new int[N];
		int count=0;
		for(int i=0;i<N;i++){
			data[i]=scan.nextInt();
		}
		for(int i=0;i<N;i++){
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		}
		System.out.println();
		System.out.println(count);
		scan.close();
		
	} main {
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int data[]=new int[N];
		int count=0;
		for(int i=0;i<N;i++){
			data[i]=scan.nextInt();
		}
		for(int i=0;i<N;i++){
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		}
		System.out.println();
		System.out.println(count);
		scan.close();
		
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int N=scan.nextInt(); N scan.nextInt() scan.nextInt scan int data[]=new int[N]; data new int[N] N int count=0; count 0 for(int i=0;i<N;i++){
			data[i]=scan.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			data[i]=scan.nextInt();
		} {
			data[i]=scan.nextInt();
		} data[i]=scan.nextInt() data[i] data i scan.nextInt() scan.nextInt scan for(int i=0;i<N;i++){
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		} {
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		} for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			} int j=N-1; int j=N-1; j N-1 N 1 i+1<=j i+1 i 1 j j-- j-- j {
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			} {
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			} if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				} data[j]<data[j-1] data[j] data j data[j-1] data j-1 j 1 {
					swap(data,j);
					count++;
				} swap(data,j) swap data j count++ count for(int i=0;i<N;i++){
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		} {
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		} if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]); i==0 i 0 System.out.print(data[i]) System.out.print System.out System System.out data[i] data i System.out.print(" "+data[i]) System.out.print System.out System System.out " "+data[i] " " data[i] data i System.out.println() System.out.println System.out System System.out System.out.println(count) System.out.println System.out System System.out count scan.close() scan.close scan String[] args args public class Main {
	static void swap(int[] data,int x){
		int tmp=data[x];
		data[x]=data[x-1];
		data[x-1]=tmp;
	}
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int data[]=new int[N];
		int count=0;
		for(int i=0;i<N;i++){
			data[i]=scan.nextInt();
		}
		for(int i=0;i<N;i++){
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		}
		System.out.println();
		System.out.println(count);
		scan.close();
		
	}
	
} public class Main {
	static void swap(int[] data,int x){
		int tmp=data[x];
		data[x]=data[x-1];
		data[x-1]=tmp;
	}
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int data[]=new int[N];
		int count=0;
		for(int i=0;i<N;i++){
			data[i]=scan.nextInt();
		}
		for(int i=0;i<N;i++){
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		}
		System.out.println();
		System.out.println(count);
		scan.close();
		
	}
	
} Main
import java.util.Scanner;
public class Main {
	static void swap(int[] data,int x){
		int tmp=data[x];
		data[x]=data[x-1];
		data[x-1]=tmp;
	}
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int data[]=new int[N];
		int count=0;
		for(int i=0;i<N;i++){
			data[i]=scan.nextInt();
		}
		for(int i=0;i<N;i++){
			for(int j=N-1;i+1<=j;j--){
				if(data[j]<data[j-1]){
					swap(data,j);
					count++;
				}
			}
		}
		for(int i=0;i<N;i++){
			if(i==0) System.out.print(data[i]);
			else System.out.print(" "+data[i]);
		}
		System.out.println();
		System.out.println(count);
		scan.close();
		
	}
	
}