import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int count = 0;
        int n = Integer.parseInt(sc.nextLine());
        int[] array = new int[n];
        String[] input = sc.nextLine().split(" ");
        
        for(int i = 0; i < n; i++){
            array[i] = Integer.parseInt(input[i]);
        }
        for(int i = 0; i < n-1; i++){
            for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < n; i++){
            System.out.print(" "+array[i]);
        }
        System.out.println("\n"+count);
        
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int count = 0;
        int n = Integer.parseInt(sc.nextLine());
        int[] array = new int[n];
        String[] input = sc.nextLine().split(" ");
        
        for(int i = 0; i < n; i++){
            array[i] = Integer.parseInt(input[i]);
        }
        for(int i = 0; i < n-1; i++){
            for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < n; i++){
            System.out.print(" "+array[i]);
        }
        System.out.println("\n"+count);
        
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int count = 0;
        int n = Integer.parseInt(sc.nextLine());
        int[] array = new int[n];
        String[] input = sc.nextLine().split(" ");
        
        for(int i = 0; i < n; i++){
            array[i] = Integer.parseInt(input[i]);
        }
        for(int i = 0; i < n-1; i++){
            for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < n; i++){
            System.out.print(" "+array[i]);
        }
        System.out.println("\n"+count);
        
    } main {
        Scanner sc = new Scanner(System.in);

        int count = 0;
        int n = Integer.parseInt(sc.nextLine());
        int[] array = new int[n];
        String[] input = sc.nextLine().split(" ");
        
        for(int i = 0; i < n; i++){
            array[i] = Integer.parseInt(input[i]);
        }
        for(int i = 0; i < n-1; i++){
            for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < n; i++){
            System.out.print(" "+array[i]);
        }
        System.out.println("\n"+count);
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int count = 0; count 0 int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int[] array = new int[n]; array new int[n] n String[] input = sc.nextLine().split(" "); input sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " for(int i = 0; i < n; i++){
            array[i] = Integer.parseInt(input[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            array[i] = Integer.parseInt(input[i]);
        } {
            array[i] = Integer.parseInt(input[i]);
        } array[i] = Integer.parseInt(input[i]) array[i] array i Integer.parseInt(input[i]) Integer.parseInt Integer input[i] input i for(int i = 0; i < n-1; i++){
            for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
            for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            }
        } {
            for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            }
        } for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            } int j = 0; int j = 0; j 0 j < n-1 j n-1 n 1 j++ j++ j {
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            } {
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            } if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                } array[j] > array[j+1] array[j] array j array[j+1] array j+1 j 1 {
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                } int tmp = array[j]; tmp array[j] array j array[j] = array[j+1] array[j] array j array[j+1] array j+1 j 1 array[j+1] = tmp array[j+1] array j+1 j 1 tmp count++ count System.out.print(array[0]) System.out.print System.out System System.out array[0] array 0 for(int i = 1; i < n; i++){
            System.out.print(" "+array[i]);
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            System.out.print(" "+array[i]);
        } {
            System.out.print(" "+array[i]);
        } System.out.print(" "+array[i]) System.out.print System.out System System.out " "+array[i] " " array[i] array i System.out.println("\n"+count) System.out.println System.out System System.out "\n"+count "\n" count String[] args args
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int count = 0;
        int n = Integer.parseInt(sc.nextLine());
        int[] array = new int[n];
        String[] input = sc.nextLine().split(" ");
        
        for(int i = 0; i < n; i++){
            array[i] = Integer.parseInt(input[i]);
        }
        for(int i = 0; i < n-1; i++){
            for(int j = 0; j < n-1; j++){
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < n; i++){
            System.out.print(" "+array[i]);
        }
        System.out.println("\n"+count);
        
    }
}
