import java.util.Scanner;

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

        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]);
        }

        int count = 0;
        int k = 0;
        while(k < n-1){
            for(int i = n-1; i > k; i--){
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            }
            k++;
        }

        StringBuilder sb = new StringBuilder();

        for(int i : array)
            sb.append(i + " ");
        
        sb.deleteCharAt(sb.length()-1);

        System.out.println(sb);
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        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]);
        }

        int count = 0;
        int k = 0;
        while(k < n-1){
            for(int i = n-1; i > k; i--){
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            }
            k++;
        }

        StringBuilder sb = new StringBuilder();

        for(int i : array)
            sb.append(i + " ");
        
        sb.deleteCharAt(sb.length()-1);

        System.out.println(sb);
        System.out.println(count);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        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]);
        }

        int count = 0;
        int k = 0;
        while(k < n-1){
            for(int i = n-1; i > k; i--){
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            }
            k++;
        }

        StringBuilder sb = new StringBuilder();

        for(int i : array)
            sb.append(i + " ");
        
        sb.deleteCharAt(sb.length()-1);

        System.out.println(sb);
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);

        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]);
        }

        int count = 0;
        int k = 0;
        while(k < n-1){
            for(int i = n-1; i > k; i--){
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            }
            k++;
        }

        StringBuilder sb = new StringBuilder();

        for(int i : array)
            sb.append(i + " ");
        
        sb.deleteCharAt(sb.length()-1);

        System.out.println(sb);
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 int count = 0; count 0 int k = 0; k 0 while(k < n-1){
            for(int i = n-1; i > k; i--){
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            }
            k++;
        } k < n-1 k n-1 n 1 {
            for(int i = n-1; i > k; i--){
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            }
            k++;
        } for(int i = n-1; i > k; i--){
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            } int i = n-1; int i = n-1; i n-1 n 1 i > k i k i-- i-- i {
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            } {
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            } if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                } array[i] < array[i-1] array[i] array i array[i-1] array i-1 i 1 {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                } int tmp = array[i]; tmp array[i] array i array[i] = array[i-1] array[i] array i array[i-1] array i-1 i 1 array[i-1] = tmp array[i-1] array i-1 i 1 tmp count++ count k++ k StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i : array)
            sb.append(i + " "); int i array sb.append(i + " "); sb.append(i + " ") sb.append sb i + " " i " " sb.deleteCharAt(sb.length()-1) sb.deleteCharAt sb sb.length()-1 sb.length() sb.length sb 1 System.out.println(sb) System.out.println System.out System System.out sb System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;

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

        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]);
        }

        int count = 0;
        int k = 0;
        while(k < n-1){
            for(int i = n-1; i > k; i--){
                if(array[i] < array[i-1]){
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    count++;
                }
            }
            k++;
        }

        StringBuilder sb = new StringBuilder();

        for(int i : array)
            sb.append(i + " ");
        
        sb.deleteCharAt(sb.length()-1);

        System.out.println(sb);
        System.out.println(count);
    }
}
