import java.util.*;
class Main{
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    
    int N = sc.nextInt();
    int[] num = new int[N];
    int suanchang=0;
    
    for (int i = 0,j; i < N; i++) {
             num[i] = sc.nextInt();
        }
    
    for(int i=0;i<num.length-1;i++){
        
        for(int j=0;j<num.length-i-1;j++){
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        }
    }

    
    for(int i=0;i<num.length-1;i++){
        System.out.print(num[i] + " ");
 }
     System.out.print(num[N-1]);
     System.out.println();
     System.out.println(suanchang);
  }
 
   } import java.util.*; util.* java class Main{
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    
    int N = sc.nextInt();
    int[] num = new int[N];
    int suanchang=0;
    
    for (int i = 0,j; i < N; i++) {
             num[i] = sc.nextInt();
        }
    
    for(int i=0;i<num.length-1;i++){
        
        for(int j=0;j<num.length-i-1;j++){
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        }
    }

    
    for(int i=0;i<num.length-1;i++){
        System.out.print(num[i] + " ");
 }
     System.out.print(num[N-1]);
     System.out.println();
     System.out.println(suanchang);
  }
 
   } Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    
    int N = sc.nextInt();
    int[] num = new int[N];
    int suanchang=0;
    
    for (int i = 0,j; i < N; i++) {
             num[i] = sc.nextInt();
        }
    
    for(int i=0;i<num.length-1;i++){
        
        for(int j=0;j<num.length-i-1;j++){
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        }
    }

    
    for(int i=0;i<num.length-1;i++){
        System.out.print(num[i] + " ");
 }
     System.out.print(num[N-1]);
     System.out.println();
     System.out.println(suanchang);
  } main {
    Scanner sc = new Scanner(System.in);
    
    
    int N = sc.nextInt();
    int[] num = new int[N];
    int suanchang=0;
    
    for (int i = 0,j; i < N; i++) {
             num[i] = sc.nextInt();
        }
    
    for(int i=0;i<num.length-1;i++){
        
        for(int j=0;j<num.length-i-1;j++){
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        }
    }

    
    for(int i=0;i<num.length-1;i++){
        System.out.print(num[i] + " ");
 }
     System.out.print(num[N-1]);
     System.out.println();
     System.out.println(suanchang);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] num = new int[N]; num new int[N] N int suanchang=0; suanchang 0 for (int i = 0,j; i < N; i++) {
             num[i] = sc.nextInt();
        } int i = 0,j; int i = 0 i 0 j; j i < N i N i++ i++ i {
             num[i] = sc.nextInt();
        } {
             num[i] = sc.nextInt();
        } num[i] = sc.nextInt() num[i] num i sc.nextInt() sc.nextInt sc for(int i=0;i<num.length-1;i++){
        
        for(int j=0;j<num.length-i-1;j++){
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        }
    } int i=0; int i=0; i 0 i<num.length-1 i num.length-1 num.length num num.length 1 i++ i++ i {
        
        for(int j=0;j<num.length-i-1;j++){
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        }
    } {
        
        for(int j=0;j<num.length-i-1;j++){
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        }
    } for(int j=0;j<num.length-i-1;j++){
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        } int j=0; int j=0; j 0 j<num.length-i-1 j num.length-i-1 num.length-i-1 num.length num num.length i 1 j++ j++ j {
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        } {
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        } if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            } num[j]>num[j+1] num[j] num j num[j+1] num j+1 j 1 {
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            } int temp = num[j]; temp num[j] num j num[j]=num[j+1] num[j] num j num[j+1] num j+1 j 1 num[j+1]=temp num[j+1] num j+1 j 1 temp suanchang++ suanchang for(int i=0;i<num.length-1;i++){
        System.out.print(num[i] + " ");
 } int i=0; int i=0; i 0 i<num.length-1 i num.length-1 num.length num num.length 1 i++ i++ i {
        System.out.print(num[i] + " ");
 } {
        System.out.print(num[i] + " ");
 } System.out.print(num[i] + " ") System.out.print System.out System System.out num[i] + " " num[i] num i " " System.out.print(num[N-1]) System.out.print System.out System System.out num[N-1] num N-1 N 1 System.out.println() System.out.println System.out System System.out System.out.println(suanchang) System.out.println System.out System System.out suanchang String[] args args
import java.util.*;
class Main{
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    
    int N = sc.nextInt();
    int[] num = new int[N];
    int suanchang=0;
    
    for (int i = 0,j; i < N; i++) {
             num[i] = sc.nextInt();
        }
    
    for(int i=0;i<num.length-1;i++){
        
        for(int j=0;j<num.length-i-1;j++){
            
            if(num[j]>num[j+1]){
                int temp = num[j];
                num[j]=num[j+1];
                num[j+1]=temp;
                suanchang++;
            }

        }
    }

    
    for(int i=0;i<num.length-1;i++){
        System.out.print(num[i] + " ");
 }
     System.out.print(num[N-1]);
     System.out.println();
     System.out.println(suanchang);
  }
 
   }
