import java.io.*;
import java.util.*;



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        
        String[] strs = str.split("\\s");
        int[] line = new int[N];
        for(int i=0;i<N;i++){
            line[i] = Integer.parseInt(strs[i]);
        }

        int ans =0;

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

        StringBuilder sb = new StringBuilder();
        for(int i =0;i<N;i++){
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        }
        sb.append("\n");
        sb.append(String.valueOf(ans));
        System.out.println(sb.toString());
        br.close();
    }

    
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        
        String[] strs = str.split("\\s");
        int[] line = new int[N];
        for(int i=0;i<N;i++){
            line[i] = Integer.parseInt(strs[i]);
        }

        int ans =0;

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

        StringBuilder sb = new StringBuilder();
        for(int i =0;i<N;i++){
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        }
        sb.append("\n");
        sb.append(String.valueOf(ans));
        System.out.println(sb.toString());
        br.close();
    }

    
} Main public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        
        String[] strs = str.split("\\s");
        int[] line = new int[N];
        for(int i=0;i<N;i++){
            line[i] = Integer.parseInt(strs[i]);
        }

        int ans =0;

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

        StringBuilder sb = new StringBuilder();
        for(int i =0;i<N;i++){
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        }
        sb.append("\n");
        sb.append(String.valueOf(ans));
        System.out.println(sb.toString());
        br.close();
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        
        String[] strs = str.split("\\s");
        int[] line = new int[N];
        for(int i=0;i<N;i++){
            line[i] = Integer.parseInt(strs[i]);
        }

        int ans =0;

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

        StringBuilder sb = new StringBuilder();
        for(int i =0;i<N;i++){
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        }
        sb.append("\n");
        sb.append(String.valueOf(ans));
        System.out.println(sb.toString());
        br.close();
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str; str str = br.readLine() str br.readLine() br.readLine br int N = Integer.parseInt(str); N Integer.parseInt(str) Integer.parseInt Integer str str = br.readLine() str br.readLine() br.readLine br String[] strs = str.split("\\s"); strs str.split("\\s") str.split str "\\s" int[] line = new int[N]; line new int[N] N for(int i=0;i<N;i++){
            line[i] = Integer.parseInt(strs[i]);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            line[i] = Integer.parseInt(strs[i]);
        } {
            line[i] = Integer.parseInt(strs[i]);
        } line[i] = Integer.parseInt(strs[i]) line[i] line i Integer.parseInt(strs[i]) Integer.parseInt Integer strs[i] strs i int ans =0; ans 0 for(int i=0;i<N;i++){
            for(int j = N-1;j >= 1; j--){
                if(line[j] < line[j -1]){
                    ans++;
                    int temp = line[j-1];
                    line[j -1] = line[j];
                    line[j] = temp;
                }
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            for(int j = N-1;j >= 1; j--){
                if(line[j] < line[j -1]){
                    ans++;
                    int temp = line[j-1];
                    line[j -1] = line[j];
                    line[j] = temp;
                }
            }
        } {
            for(int j = N-1;j >= 1; j--){
                if(line[j] < line[j -1]){
                    ans++;
                    int temp = line[j-1];
                    line[j -1] = line[j];
                    line[j] = temp;
                }
            }
        } for(int j = N-1;j >= 1; j--){
                if(line[j] < line[j -1]){
                    ans++;
                    int temp = line[j-1];
                    line[j -1] = line[j];
                    line[j] = temp;
                }
            } int j = N-1; int j = N-1; j N-1 N 1 j >= 1 j 1 j-- j-- j {
                if(line[j] < line[j -1]){
                    ans++;
                    int temp = line[j-1];
                    line[j -1] = line[j];
                    line[j] = temp;
                }
            } {
                if(line[j] < line[j -1]){
                    ans++;
                    int temp = line[j-1];
                    line[j -1] = line[j];
                    line[j] = temp;
                }
            } if(line[j] < line[j -1]){
                    ans++;
                    int temp = line[j-1];
                    line[j -1] = line[j];
                    line[j] = temp;
                } line[j] < line[j -1] line[j] line j line[j -1] line j -1 j 1 {
                    ans++;
                    int temp = line[j-1];
                    line[j -1] = line[j];
                    line[j] = temp;
                } ans++ ans int temp = line[j-1]; temp line[j-1] line j-1 j 1 line[j -1] = line[j] line[j -1] line j -1 j 1 line[j] line j line[j] = temp line[j] line j temp StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i =0;i<N;i++){
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        } int i =0; int i =0; i 0 i<N i N i++ i++ i {
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        } {
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        } if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            } i != N -1 i N -1 N 1 {
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            } sb.append(String.valueOf(line[i])) sb.append sb String.valueOf(line[i]) String.valueOf String line[i] line i sb.append(" ") sb.append sb " " {
                sb.append(String.valueOf(line[i]));
            } sb.append(String.valueOf(line[i])) sb.append sb String.valueOf(line[i]) String.valueOf String line[i] line i sb.append("\n") sb.append sb "\n" sb.append(String.valueOf(ans)) sb.append sb String.valueOf(ans) String.valueOf String ans System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb br.close() br.close br String[] args args public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        
        String[] strs = str.split("\\s");
        int[] line = new int[N];
        for(int i=0;i<N;i++){
            line[i] = Integer.parseInt(strs[i]);
        }

        int ans =0;

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

        StringBuilder sb = new StringBuilder();
        for(int i =0;i<N;i++){
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        }
        sb.append("\n");
        sb.append(String.valueOf(ans));
        System.out.println(sb.toString());
        br.close();
    }

    
} public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        
        String[] strs = str.split("\\s");
        int[] line = new int[N];
        for(int i=0;i<N;i++){
            line[i] = Integer.parseInt(strs[i]);
        }

        int ans =0;

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

        StringBuilder sb = new StringBuilder();
        for(int i =0;i<N;i++){
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        }
        sb.append("\n");
        sb.append(String.valueOf(ans));
        System.out.println(sb.toString());
        br.close();
    }

    
} Main
import java.io.*;
import java.util.*;



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        
        String[] strs = str.split("\\s");
        int[] line = new int[N];
        for(int i=0;i<N;i++){
            line[i] = Integer.parseInt(strs[i]);
        }

        int ans =0;

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

        StringBuilder sb = new StringBuilder();
        for(int i =0;i<N;i++){
            if(i != N -1){
            sb.append(String.valueOf(line[i]));
            sb.append(" ");
            }else{
                sb.append(String.valueOf(line[i]));
            }
        }
        sb.append("\n");
        sb.append(String.valueOf(ans));
        System.out.println(sb.toString());
        br.close();
    }

    
}
