

import java.util.Scanner;

/**
 * Created by sd on 2016/11/22.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        }

        int count = 0;
        boolean flag = true;
        while (flag){
            flag = false;
            for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            }
        }
        for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        }
        System.out.println(a[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 N = sc.nextInt();
        int a[] = new int[N];
        for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        }

        int count = 0;
        boolean flag = true;
        while (flag){
            flag = false;
            for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            }
        }
        for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        }
        System.out.println(a[N-1]);
        System.out.println(count);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        }

        int count = 0;
        boolean flag = true;
        while (flag){
            flag = false;
            for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            }
        }
        for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        }
        System.out.println(a[N-1]);
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        }

        int count = 0;
        boolean flag = true;
        while (flag){
            flag = false;
            for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            }
        }
        for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        }
        System.out.println(a[N-1]);
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int a[] = new int[N]; a new int[N] N for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        } int I=0; int I=0; I 0 I<N I N I++ I++ I {
            a[I] = sc.nextInt();
        } {
            a[I] = sc.nextInt();
        } a[I] = sc.nextInt() a[I] a I sc.nextInt() sc.nextInt sc int count = 0; count 0 boolean flag = true; flag true while (flag){
            flag = false;
            for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            }
        } flag {
            flag = false;
            for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            }
        } flag = false flag false for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            } int j=N-1; int j=N-1; j N-1 N 1 j>=1 j 1 j-- j-- j {
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            } {
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            } if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                } a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                } int t = a[j]; t a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = t a[j-1] a j-1 j 1 t flag = true flag true count ++ count for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        } int ii=0; int ii=0; ii 0 ii<N-1 ii N-1 N 1 ii++ ii++ ii {
            System.out.print(a[ii]+" ");
        } {
            System.out.print(a[ii]+" ");
        } System.out.print(a[ii]+" ") System.out.print System.out System System.out a[ii]+" " a[ii] a ii " " System.out.println(a[N-1]) System.out.println System.out System System.out a[N-1] a 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 N = sc.nextInt();
        int a[] = new int[N];
        for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        }

        int count = 0;
        boolean flag = true;
        while (flag){
            flag = false;
            for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            }
        }
        for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        }
        System.out.println(a[N-1]);
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        }

        int count = 0;
        boolean flag = true;
        while (flag){
            flag = false;
            for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            }
        }
        for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        }
        System.out.println(a[N-1]);
        System.out.println(count);
    }
} Main


import java.util.Scanner;

/**
 * Created by sd on 2016/11/22.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int I=0;I<N;I++){
            a[I] = sc.nextInt();
        }

        int count = 0;
        boolean flag = true;
        while (flag){
            flag = false;
            for (int j=N-1; j>=1; j--){
                if(a[j] < a[j-1]){
                    int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    flag = true;
                    count ++;
                }
            }
        }
        for(int ii=0; ii<N-1; ii++){
            System.out.print(a[ii]+" ");
        }
        System.out.println(a[N-1]);
        System.out.println(count);
    }
}