import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		int i,j,k,n,c,count;
		Scanner sc=new Scanner(System.in);
		n=Integer.parseInt(sc.next());
		int a[]=new int[n+1];
		for(i=0;i<n;i++){
			a[i]=Integer.parseInt(sc.next());
		}
		
		count=0;
	for(i=0;i<n;i++){
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	}
		
		for(i=0;i<n;i++){
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
} import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String args[]){
		int i,j,k,n,c,count;
		Scanner sc=new Scanner(System.in);
		n=Integer.parseInt(sc.next());
		int a[]=new int[n+1];
		for(i=0;i<n;i++){
			a[i]=Integer.parseInt(sc.next());
		}
		
		count=0;
	for(i=0;i<n;i++){
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	}
		
		for(i=0;i<n;i++){
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
} Main public static void main(String args[]){
		int i,j,k,n,c,count;
		Scanner sc=new Scanner(System.in);
		n=Integer.parseInt(sc.next());
		int a[]=new int[n+1];
		for(i=0;i<n;i++){
			a[i]=Integer.parseInt(sc.next());
		}
		
		count=0;
	for(i=0;i<n;i++){
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	}
		
		for(i=0;i<n;i++){
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	} main {
		int i,j,k,n,c,count;
		Scanner sc=new Scanner(System.in);
		n=Integer.parseInt(sc.next());
		int a[]=new int[n+1];
		for(i=0;i<n;i++){
			a[i]=Integer.parseInt(sc.next());
		}
		
		count=0;
	for(i=0;i<n;i++){
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	}
		
		for(i=0;i<n;i++){
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	} int i i j j k k n n c c count; count Scanner sc=new Scanner(System.in); sc new Scanner(System.in) n=Integer.parseInt(sc.next()) n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int a[]=new int[n+1]; a new int[n+1] n+1 n 1 for(i=0;i<n;i++){
			a[i]=Integer.parseInt(sc.next());
		} i=0; i=0 i 0 i<n i n i++ i++ i {
			a[i]=Integer.parseInt(sc.next());
		} {
			a[i]=Integer.parseInt(sc.next());
		} a[i]=Integer.parseInt(sc.next()) a[i] a i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc count=0 count 0 for(i=0;i<n;i++){
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	} i=0; i=0 i 0 i<n i n i++ i++ i {
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	} {
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	} for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		} j=n-1; j=n-1 j n-1 n 1 j>0 j 0 j-- j-- j {
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		} {
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		} if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			} a[j]<a[j-1] a[j] a j a[j-1] a j-1 j 1 {
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			} c=a[j] c a[j] a j a[j]=a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1]=c a[j-1] a j-1 j 1 c count++ count for(i=0;i<n;i++){
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		} i=0; i=0 i 0 i<n i n i++ i++ i {
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		} {
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		} System.out.print(a[i]) System.out.print System.out System System.out a[i] a i if(i==n-1){break;} i==n-1 i n-1 n 1 {break;} break; System.out.print(" ") System.out.print System.out System System.out " " System.out.println("") System.out.println System.out System System.out "" 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[]){
		int i,j,k,n,c,count;
		Scanner sc=new Scanner(System.in);
		n=Integer.parseInt(sc.next());
		int a[]=new int[n+1];
		for(i=0;i<n;i++){
			a[i]=Integer.parseInt(sc.next());
		}
		
		count=0;
	for(i=0;i<n;i++){
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	}
		
		for(i=0;i<n;i++){
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
} public class Main{

	public static void main(String args[]){
		int i,j,k,n,c,count;
		Scanner sc=new Scanner(System.in);
		n=Integer.parseInt(sc.next());
		int a[]=new int[n+1];
		for(i=0;i<n;i++){
			a[i]=Integer.parseInt(sc.next());
		}
		
		count=0;
	for(i=0;i<n;i++){
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	}
		
		for(i=0;i<n;i++){
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		int i,j,k,n,c,count;
		Scanner sc=new Scanner(System.in);
		n=Integer.parseInt(sc.next());
		int a[]=new int[n+1];
		for(i=0;i<n;i++){
			a[i]=Integer.parseInt(sc.next());
		}
		
		count=0;
	for(i=0;i<n;i++){
		
		for(j=n-1;j>0;j--){
			if(a[j]<a[j-1]){
			c=a[j];
			a[j]=a[j-1];
			a[j-1]=c;
			count++;
			}
		}
	}
		
		for(i=0;i<n;i++){
			System.out.print(a[i]);
			if(i==n-1){break;}
			System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
}