import java.util.Scanner;

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

        int count = 0;
        int[] x;
        x = new int[100];
        int N = sc.nextInt();

        for(int i = 0;i<N;i++){
            x[i] = sc.nextInt();
        }

        for(int i = N-1;i>0;i--){
            for(int j = 0;j<i;j++){
                if(x[j]>x[j+1]){
                    int temp = x[j];
                    x[j] = x[j+1];
                    x[j+1] = temp;
                    count++;
                }
            }
        }

        for(int i = 0;i<N-1;i++){
            System.out.print(x[i] + " ");
        }
        System.out.println(x[N-1]);
        System.out.println(count);
    }
}
 import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int count = 0;
        int[] x;
        x = new int[100];
        int N = sc.nextInt();

        for(int i = 0;i<N;i++){
            x[i] = sc.nextInt();
        }

        for(int i = N-1;i>0;i--){
            for(int j = 0;j<i;j++){
                if(x[j]>x[j+1]){
                    int temp = x[j];
                    x[j] = x[j+1];
                    x[j+1] = temp;
                    count++;
                }
            }
        }

        for(int i = 0;i<N-1;i++){
            System.out.print(x[i] + " ");
        }
        System.out.println(x[N-1]);
        System.out.println(count);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int count = 0;
        int[] x;
        x = new int[100];
        int N = sc.nextInt();

        for(int i = 0;i<N;i++){
            x[i] = sc.nextInt();
        }

        for(int i = N-1;i>0;i--){
            for(int j = 0;j<i;j++){
                if(x[j]>x[j+1]){
                    int temp = x[j];
                    x[j] = x[j+1];
                    x[j+1] = temp;
                    count++;
                }
            }
        }

        for(int i = 0;i<N-1;i++){
            System.out.print(x[i] + " ");
        }
        System.out.println(x[N-1]);
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);

        int count = 0;
        int[] x;
        x = new int[100];
        int N = sc.nextInt();

        for(int i = 0;i<N;i++){
            x[i] = sc.nextInt();
        }

        for(int i = N-1;i>0;i--){
            for(int j = 0;j<i;j++){
                if(x[j]>x[j+1]){
                    int temp = x[j];
                    x[j] = x[j+1];
                    x[j+1] = temp;
                    count++;
                }
            }
        }

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

        int count = 0;
        int[] x;
        x = new int[100];
        int N = sc.nextInt();

        for(int i = 0;i<N;i++){
            x[i] = sc.nextInt();
        }

        for(int i = N-1;i>0;i--){
            for(int j = 0;j<i;j++){
                if(x[j]>x[j+1]){
                    int temp = x[j];
                    x[j] = x[j+1];
                    x[j+1] = temp;
                    count++;
                }
            }
        }

        for(int i = 0;i<N-1;i++){
            System.out.print(x[i] + " ");
        }
        System.out.println(x[N-1]);
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int count = 0;
        int[] x;
        x = new int[100];
        int N = sc.nextInt();

        for(int i = 0;i<N;i++){
            x[i] = sc.nextInt();
        }

        for(int i = N-1;i>0;i--){
            for(int j = 0;j<i;j++){
                if(x[j]>x[j+1]){
                    int temp = x[j];
                    x[j] = x[j+1];
                    x[j+1] = temp;
                    count++;
                }
            }
        }

        for(int i = 0;i<N-1;i++){
            System.out.print(x[i] + " ");
        }
        System.out.println(x[N-1]);
        System.out.println(count);
    }
} Main
import java.util.Scanner;

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

        int count = 0;
        int[] x;
        x = new int[100];
        int N = sc.nextInt();

        for(int i = 0;i<N;i++){
            x[i] = sc.nextInt();
        }

        for(int i = N-1;i>0;i--){
            for(int j = 0;j<i;j++){
                if(x[j]>x[j+1]){
                    int temp = x[j];
                    x[j] = x[j+1];
                    x[j+1] = temp;
                    count++;
                }
            }
        }

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

