import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }
        int count = 0;
        boolean flag = true;
        for(int i = 0; flag; i++){
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < num; i++){
            System.out.print(" " + array[i]);
        }
        System.out.println("\n" + count);
        
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }
        int count = 0;
        boolean flag = true;
        for(int i = 0; flag; i++){
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < num; 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 num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }
        int count = 0;
        boolean flag = true;
        for(int i = 0; flag; i++){
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < num; i++){
            System.out.print(" " + array[i]);
        }
        System.out.println("\n" + count);
        
    } main {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }
        int count = 0;
        boolean flag = true;
        for(int i = 0; flag; i++){
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < num; i++){
            System.out.print(" " + array[i]);
        }
        System.out.println("\n" + count);
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int[] array = new int[num]; array new int[num] num for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
            array[i] = sc.nextInt();
        } {
            array[i] = sc.nextInt();
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int count = 0; count 0 boolean flag = true; flag true for(int i = 0; flag; i++){
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 flag i++ i++ i {
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        } {
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        } flag = false flag false for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            } int j = num - 1; int j = num - 1; j num - 1 num 1 j >= i + 1 j i + 1 i 1 j-- j-- j {
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            } {
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            } if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                } array[j - 1] > array[j] array[j - 1] array j - 1 j 1 array[j] array j {
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                } int temp = array[j - 1]; temp array[j - 1] array j - 1 j 1 array[j - 1] = array[j] array[j - 1] array j - 1 j 1 array[j] array j array[j] = temp array[j] array j temp flag = true flag true count++ count System.out.print(array[0]) System.out.print System.out System System.out array[0] array 0 for(int i = 1; i < num; i++){
            System.out.print(" " + array[i]);
        } int i = 1; int i = 1; i 1 i < num i num 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 public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }
        int count = 0;
        boolean flag = true;
        for(int i = 0; flag; i++){
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < num; i++){
            System.out.print(" " + array[i]);
        }
        System.out.println("\n" + count);
        
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }
        int count = 0;
        boolean flag = true;
        for(int i = 0; flag; i++){
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < num; i++){
            System.out.print(" " + array[i]);
        }
        System.out.println("\n" + count);
        
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }
        int count = 0;
        boolean flag = true;
        for(int i = 0; flag; i++){
            flag = false;
            for(int j = num - 1; j >= i + 1; j--){
                if(array[j - 1] > array[j]){
                    int temp = array[j - 1];
                    array[j - 1] = array[j];
                    array[j] = temp;
                    flag = true;
                    count++;
                }
            }
        }
        System.out.print(array[0]);
        for(int i = 1; i < num; i++){
            System.out.print(" " + array[i]);
        }
        System.out.println("\n" + count);
        
    }
}
