import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        babbleSort(a, n);
    }

    public static void babbleSort(int[] a, int n){
        int flag = 1;
        int temp, count = 0;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int j = 0; j < n; j++){
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        }
        sb.append("\n").append(count);
        System.out.println(sb);
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        babbleSort(a, n);
    }

    public static void babbleSort(int[] a, int n){
        int flag = 1;
        int temp, count = 0;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int j = 0; j < n; j++){
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        }
        sb.append("\n").append(count);
        System.out.println(sb);
    }

} Main public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        babbleSort(a, n);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        babbleSort(a, n);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] a = new int[n]; a new int[n] n String[] t = br.readLine().split(" "); t br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = Integer.parseInt(t[i]);
        } {
            a[i] = Integer.parseInt(t[i]);
        } a[i] = Integer.parseInt(t[i]) a[i] a i Integer.parseInt(t[i]) Integer.parseInt Integer t[i] t i babbleSort(a, n) babbleSort a n String[] args args public static void babbleSort(int[] a, int n){
        int flag = 1;
        int temp, count = 0;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int j = 0; j < n; j++){
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        }
        sb.append("\n").append(count);
        System.out.println(sb);
    } babbleSort {
        int flag = 1;
        int temp, count = 0;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int j = 0; j < n; j++){
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        }
        sb.append("\n").append(count);
        System.out.println(sb);
    } int flag = 1; flag 1 int temp temp count = 0; count 0 while(flag == 1){
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        } flag == 1 flag 1 {
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        } flag = 0 flag 0 for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            } int i = n - 1; int i = n - 1; i n - 1 n 1 i > 0 i 0 i-- i-- i {
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            } {
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            } if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                } a[i-1] > a[i] a[i-1] a i-1 i 1 a[i] a i {
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                } temp = a[i-1] temp a[i-1] a i-1 i 1 a[i-1] = a[i] a[i-1] a i-1 i 1 a[i] a i a[i] = temp a[i] a i temp flag = 1 flag 1 count++ count StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int j = 0; j < n; j++){
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        } {
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        } if(j != 0) sb.append(" "); j != 0 j 0 sb.append(" ") sb.append sb " " sb.append(a[j]) sb.append sb a[j] a j sb.append("\n").append(count) sb.append("\n").append sb.append("\n") sb.append sb "\n" count System.out.println(sb) System.out.println System.out System System.out sb int[] a a int n n public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        babbleSort(a, n);
    }

    public static void babbleSort(int[] a, int n){
        int flag = 1;
        int temp, count = 0;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int j = 0; j < n; j++){
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        }
        sb.append("\n").append(count);
        System.out.println(sb);
    }

} public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        babbleSort(a, n);
    }

    public static void babbleSort(int[] a, int n){
        int flag = 1;
        int temp, count = 0;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int j = 0; j < n; j++){
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        }
        sb.append("\n").append(count);
        System.out.println(sb);
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        babbleSort(a, n);
    }

    public static void babbleSort(int[] a, int n){
        int flag = 1;
        int temp, count = 0;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1; i > 0; i--){
                if(a[i-1] > a[i]){
                    temp = a[i-1];
                    a[i-1] = a[i];
                    a[i] = temp;
                    flag = 1;
                    count++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int j = 0; j < n; j++){
            if(j != 0) sb.append(" ");
            sb.append(a[j]);
        }
        sb.append("\n").append(count);
        System.out.println(sb);
    }

}