
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i]=scanner.nextInt();
        }
        bubbleSort(A,N);
    }
     
    static void bubbleSort(int[] A,int N){
    	int count = 0;
        for(int i=N-1;i>0;i--){
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        }
    	printList(A,N);
        System.out.println(count);
    }
    static void printList(int[] A,int N){
        StringBuilder builder = new StringBuilder();
        for(int i=0;i<N;i++){
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        System.out.println(builder);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i]=scanner.nextInt();
        }
        bubbleSort(A,N);
    }
     
    static void bubbleSort(int[] A,int N){
    	int count = 0;
        for(int i=N-1;i>0;i--){
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        }
    	printList(A,N);
        System.out.println(count);
    }
    static void printList(int[] A,int N){
        StringBuilder builder = new StringBuilder();
        for(int i=0;i<N;i++){
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        System.out.println(builder);
    }
} Main public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i]=scanner.nextInt();
        }
        bubbleSort(A,N);
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i]=scanner.nextInt();
        }
        bubbleSort(A,N);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] A = new int[N]; A new int[N] N for(int i=0;i<N;i++){
            A[i]=scanner.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            A[i]=scanner.nextInt();
        } {
            A[i]=scanner.nextInt();
        } A[i]=scanner.nextInt() A[i] A i scanner.nextInt() scanner.nextInt scanner bubbleSort(A,N) bubbleSort A N String[] args args static void bubbleSort(int[] A,int N){
    	int count = 0;
        for(int i=N-1;i>0;i--){
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        }
    	printList(A,N);
        System.out.println(count);
    } bubbleSort {
    	int count = 0;
        for(int i=N-1;i>0;i--){
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        }
    	printList(A,N);
        System.out.println(count);
    } int count = 0; count 0 for(int i=N-1;i>0;i--){
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        } int i=N-1; int i=N-1; i N-1 N 1 i>0 i 0 i-- i-- i {
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        } {
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        } for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	} int j=N-1; int j=N-1; j N-1 N 1 j>N-1-i j N-1-i N-1-i N 1 i j-- j-- j {
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	} {
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	} if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		} A[j-1] > A[j] A[j-1] A j-1 j 1 A[j] A j {
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		} int v = A[j]; v A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = v A[j-1] A j-1 j 1 v count++ count printList(A,N) printList A N System.out.println(count) System.out.println System.out System System.out count int[] A A int N N static void printList(int[] A,int N){
        StringBuilder builder = new StringBuilder();
        for(int i=0;i<N;i++){
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        System.out.println(builder);
    } printList {
        StringBuilder builder = new StringBuilder();
        for(int i=0;i<N;i++){
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        System.out.println(builder);
    } StringBuilder builder = new StringBuilder(); builder new StringBuilder() for(int i=0;i<N;i++){
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        } {
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        } if(i>0){
                builder.append(" ");
            } i>0 i 0 {
                builder.append(" ");
            } builder.append(" ") builder.append builder " " builder.append(A[i]) builder.append builder A[i] A i System.out.println(builder) System.out.println System.out System System.out builder int[] A A int N N public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i]=scanner.nextInt();
        }
        bubbleSort(A,N);
    }
     
    static void bubbleSort(int[] A,int N){
    	int count = 0;
        for(int i=N-1;i>0;i--){
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        }
    	printList(A,N);
        System.out.println(count);
    }
    static void printList(int[] A,int N){
        StringBuilder builder = new StringBuilder();
        for(int i=0;i<N;i++){
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        System.out.println(builder);
    }
} public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i]=scanner.nextInt();
        }
        bubbleSort(A,N);
    }
     
    static void bubbleSort(int[] A,int N){
    	int count = 0;
        for(int i=N-1;i>0;i--){
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        }
    	printList(A,N);
        System.out.println(count);
    }
    static void printList(int[] A,int N){
        StringBuilder builder = new StringBuilder();
        for(int i=0;i<N;i++){
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        System.out.println(builder);
    }
} Main

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i]=scanner.nextInt();
        }
        bubbleSort(A,N);
    }
     
    static void bubbleSort(int[] A,int N){
    	int count = 0;
        for(int i=N-1;i>0;i--){
        	//[N-1-i] is better than 0
        	for(int j=N-1;j>N-1-i;j--){
        		if(A[j-1] > A[j]){
        			int v = A[j];
        			A[j] = A[j-1];
        			A[j-1] = v;
        			count++;
        		}
        	}
        }
    	printList(A,N);
        System.out.println(count);
    }
    static void printList(int[] A,int N){
        StringBuilder builder = new StringBuilder();
        for(int i=0;i<N;i++){
            if(i>0){
                builder.append(" ");
            }
            builder.append(A[i]);
        }
        System.out.println(builder);
    }
}