import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(buf.readLine());
        int[] h=new int[num];
        String[] str=buf.readLine().split(" ");
        
        for(int i=0;i<num;i++){
            h[i]=Integer.parseInt(str[i]);
        }
        
        int cnt=0;
        for(int i=0;i<h.length-1;i++){
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        }
        System.out.print(h[0]);
        for(int i=1;i<h.length;i++){
            System.out.print(" "+h[i]);
        }
        System.out.println();
        System.out.println(cnt);
    }
} import java.io.*; io.* java public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(buf.readLine());
        int[] h=new int[num];
        String[] str=buf.readLine().split(" ");
        
        for(int i=0;i<num;i++){
            h[i]=Integer.parseInt(str[i]);
        }
        
        int cnt=0;
        for(int i=0;i<h.length-1;i++){
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        }
        System.out.print(h[0]);
        for(int i=1;i<h.length;i++){
            System.out.print(" "+h[i]);
        }
        System.out.println();
        System.out.println(cnt);
    }
} Main public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(buf.readLine());
        int[] h=new int[num];
        String[] str=buf.readLine().split(" ");
        
        for(int i=0;i<num;i++){
            h[i]=Integer.parseInt(str[i]);
        }
        
        int cnt=0;
        for(int i=0;i<h.length-1;i++){
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        }
        System.out.print(h[0]);
        for(int i=1;i<h.length;i++){
            System.out.print(" "+h[i]);
        }
        System.out.println();
        System.out.println(cnt);
    } main {
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(buf.readLine());
        int[] h=new int[num];
        String[] str=buf.readLine().split(" ");
        
        for(int i=0;i<num;i++){
            h[i]=Integer.parseInt(str[i]);
        }
        
        int cnt=0;
        for(int i=0;i<h.length-1;i++){
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        }
        System.out.print(h[0]);
        for(int i=1;i<h.length;i++){
            System.out.print(" "+h[i]);
        }
        System.out.println();
        System.out.println(cnt);
    } BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); buf new BufferedReader(new InputStreamReader(System.in)) int num=Integer.parseInt(buf.readLine()); num Integer.parseInt(buf.readLine()) Integer.parseInt Integer buf.readLine() buf.readLine buf int[] h=new int[num]; h new int[num] num String[] str=buf.readLine().split(" "); str buf.readLine().split(" ") buf.readLine().split buf.readLine() buf.readLine buf " " for(int i=0;i<num;i++){
            h[i]=Integer.parseInt(str[i]);
        } int i=0; int i=0; i 0 i<num i num i++ i++ i {
            h[i]=Integer.parseInt(str[i]);
        } {
            h[i]=Integer.parseInt(str[i]);
        } h[i]=Integer.parseInt(str[i]) h[i] h i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i int cnt=0; cnt 0 for(int i=0;i<h.length-1;i++){
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        } int i=0; int i=0; i 0 i<h.length-1 i h.length-1 h.length h h.length 1 i++ i++ i {
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        } {
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        } for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            } int j=h.length-1; int j=h.length-1; j h.length-1 h.length h h.length 1 j>i j i j-- j-- j {
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            } {
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            } if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                } h[j-1]>h[j] h[j-1] h j-1 j 1 h[j] h j {
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                } int tmp=h[j]; tmp h[j] h j h[j]=h[j-1] h[j] h j h[j-1] h j-1 j 1 h[j-1]=tmp h[j-1] h j-1 j 1 tmp cnt=cnt+1 cnt cnt+1 cnt 1 System.out.print(h[0]) System.out.print System.out System System.out h[0] h 0 for(int i=1;i<h.length;i++){
            System.out.print(" "+h[i]);
        } int i=1; int i=1; i 1 i<h.length i h.length h h.length i++ i++ i {
            System.out.print(" "+h[i]);
        } {
            System.out.print(" "+h[i]);
        } System.out.print(" "+h[i]) System.out.print System.out System System.out " "+h[i] " " h[i] h i System.out.println() System.out.println System.out System System.out System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(buf.readLine());
        int[] h=new int[num];
        String[] str=buf.readLine().split(" ");
        
        for(int i=0;i<num;i++){
            h[i]=Integer.parseInt(str[i]);
        }
        
        int cnt=0;
        for(int i=0;i<h.length-1;i++){
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        }
        System.out.print(h[0]);
        for(int i=1;i<h.length;i++){
            System.out.print(" "+h[i]);
        }
        System.out.println();
        System.out.println(cnt);
    }
} public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(buf.readLine());
        int[] h=new int[num];
        String[] str=buf.readLine().split(" ");
        
        for(int i=0;i<num;i++){
            h[i]=Integer.parseInt(str[i]);
        }
        
        int cnt=0;
        for(int i=0;i<h.length-1;i++){
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        }
        System.out.print(h[0]);
        for(int i=1;i<h.length;i++){
            System.out.print(" "+h[i]);
        }
        System.out.println();
        System.out.println(cnt);
    }
} Main
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
        int num=Integer.parseInt(buf.readLine());
        int[] h=new int[num];
        String[] str=buf.readLine().split(" ");
        
        for(int i=0;i<num;i++){
            h[i]=Integer.parseInt(str[i]);
        }
        
        int cnt=0;
        for(int i=0;i<h.length-1;i++){
            for(int j=h.length-1;j>i;j--){
                if(h[j-1]>h[j]){
                    int tmp=h[j];
                    h[j]=h[j-1];
                    h[j-1]=tmp;
                    cnt=cnt+1;
                }
            }
        }
        System.out.print(h[0]);
        for(int i=1;i<h.length;i++){
            System.out.print(" "+h[i]);
        }
        System.out.println();
        System.out.println(cnt);
    }
}