import java.util.Scanner;
class Main{
    public static void main(String[] args){
	int array[] = new int[101];
	int i,j,count=0,flag=1,temp;

	Scanner scan = new Scanner(System.in);
	array[0] = scan.nextInt();

	for(i=1;i<=array[0];i++){
	    array[i] = scan.nextInt();
	}
	
	while(flag!=0){
	    flag=0;
	    for(j=array[0];j>1;j--){
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    }
	}
	for(i=1;i<=array[0];i++){
	    if(i==array[0]){System.out.println(array[i]+"\n"+count);}
	    else System.out.print(array[i]+" ");
	}
    }
}
 import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
	int array[] = new int[101];
	int i,j,count=0,flag=1,temp;

	Scanner scan = new Scanner(System.in);
	array[0] = scan.nextInt();

	for(i=1;i<=array[0];i++){
	    array[i] = scan.nextInt();
	}
	
	while(flag!=0){
	    flag=0;
	    for(j=array[0];j>1;j--){
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    }
	}
	for(i=1;i<=array[0];i++){
	    if(i==array[0]){System.out.println(array[i]+"\n"+count);}
	    else System.out.print(array[i]+" ");
	}
    }
} Main public static void main(String[] args){
	int array[] = new int[101];
	int i,j,count=0,flag=1,temp;

	Scanner scan = new Scanner(System.in);
	array[0] = scan.nextInt();

	for(i=1;i<=array[0];i++){
	    array[i] = scan.nextInt();
	}
	
	while(flag!=0){
	    flag=0;
	    for(j=array[0];j>1;j--){
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    }
	}
	for(i=1;i<=array[0];i++){
	    if(i==array[0]){System.out.println(array[i]+"\n"+count);}
	    else System.out.print(array[i]+" ");
	}
    } main {
	int array[] = new int[101];
	int i,j,count=0,flag=1,temp;

	Scanner scan = new Scanner(System.in);
	array[0] = scan.nextInt();

	for(i=1;i<=array[0];i++){
	    array[i] = scan.nextInt();
	}
	
	while(flag!=0){
	    flag=0;
	    for(j=array[0];j>1;j--){
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    }
	}
	for(i=1;i<=array[0];i++){
	    if(i==array[0]){System.out.println(array[i]+"\n"+count);}
	    else System.out.print(array[i]+" ");
	}
    } int array[] = new int[101]; array new int[101] 101 int i i j j count=0 count 0 flag=1 flag 1 temp; temp Scanner scan = new Scanner(System.in); scan new Scanner(System.in) array[0] = scan.nextInt() array[0] array 0 scan.nextInt() scan.nextInt scan for(i=1;i<=array[0];i++){
	    array[i] = scan.nextInt();
	} i=1; i=1 i 1 i<=array[0] i array[0] array 0 i++ i++ i {
	    array[i] = scan.nextInt();
	} {
	    array[i] = scan.nextInt();
	} array[i] = scan.nextInt() array[i] array i scan.nextInt() scan.nextInt scan while(flag!=0){
	    flag=0;
	    for(j=array[0];j>1;j--){
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    }
	} flag!=0 flag 0 {
	    flag=0;
	    for(j=array[0];j>1;j--){
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    }
	} flag=0 flag 0 for(j=array[0];j>1;j--){
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    } j=array[0]; j=array[0] j array[0] array 0 j>1 j 1 j-- j-- j {
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    } {
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    } if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		} array[j] < array[j-1] array[j] array j array[j-1] array j-1 j 1 {
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		} temp = array[j] temp array[j] array j array[j] = array[j-1] array[j] array j array[j-1] array j-1 j 1 array[j-1] = temp array[j-1] array j-1 j 1 temp flag = 1 flag 1 count++ count for(i=1;i<=array[0];i++){
	    if(i==array[0]){System.out.println(array[i]+"\n"+count);}
	    else System.out.print(array[i]+" ");
	} i=1; i=1 i 1 i<=array[0] i array[0] array 0 i++ i++ i {
	    if(i==array[0]){System.out.println(array[i]+"\n"+count);}
	    else System.out.print(array[i]+" ");
	} {
	    if(i==array[0]){System.out.println(array[i]+"\n"+count);}
	    else System.out.print(array[i]+" ");
	} if(i==array[0]){System.out.println(array[i]+"\n"+count);}
	    else System.out.print(array[i]+" "); i==array[0] i array[0] array 0 {System.out.println(array[i]+"\n"+count);} System.out.println(array[i]+"\n"+count) System.out.println System.out System System.out array[i]+"\n"+count array[i]+"\n"+count array[i] array i "\n" count System.out.print(array[i]+" ") System.out.print System.out System System.out array[i]+" " array[i] array i " " String[] args args
import java.util.Scanner;
class Main{
    public static void main(String[] args){
	int array[] = new int[101];
	int i,j,count=0,flag=1,temp;

	Scanner scan = new Scanner(System.in);
	array[0] = scan.nextInt();

	for(i=1;i<=array[0];i++){
	    array[i] = scan.nextInt();
	}
	
	while(flag!=0){
	    flag=0;
	    for(j=array[0];j>1;j--){
		if(array[j] < array[j-1]){
		    temp = array[j];
		    array[j] = array[j-1];
		    array[j-1] = temp;
		    flag = 1;
		    count++;
		}
	    }
	}
	for(i=1;i<=array[0];i++){
	    if(i==array[0]){System.out.println(array[i]+"\n"+count);}
	    else System.out.print(array[i]+" ");
	}
    }
}

