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

public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");

        int[] A = new int[n];
        int chageBox = 0;
        int count = 0;

//      n????????´??°?????????A???????´?
        for (int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        }
        System.out.println();
        System.out.println(count);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");

        int[] A = new int[n];
        int chageBox = 0;
        int count = 0;

//      n????????´??°?????????A???????´?
        for (int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        }
        System.out.println();
        System.out.println(count);
    }
} Main public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");

        int[] A = new int[n];
        int chageBox = 0;
        int count = 0;

//      n????????´??°?????????A???????´?
        for (int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        }
        System.out.println();
        System.out.println(count);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");

        int[] A = new int[n];
        int chageBox = 0;
        int count = 0;

//      n????????´??°?????????A???????´?
        for (int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        }
        System.out.println();
        System.out.println(count);
    } 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 String[] input = br.readLine().split(" "); input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] A = new int[n]; A new int[n] n int chageBox = 0; chageBox 0 int count = 0; count 0 for (int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            A[i] = Integer.parseInt(input[i]);
        } {
            A[i] = Integer.parseInt(input[i]);
        } A[i] = Integer.parseInt(input[i]) A[i] A i Integer.parseInt(input[i]) Integer.parseInt Integer input[i] input i for(int i = 0; i < n - 1; i++){
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        } {
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        } for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            } int j = n - 1; int j = n - 1; j n - 1 n 1 j > i j i j-- j-- j {
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            } {
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            } if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                } A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                } chageBox = A[j-1] chageBox A[j-1] A j-1 j 1 A[j-1] = A[j] A[j-1] A j-1 j 1 A[j] A j A[j] = chageBox A[j] A j chageBox count++ count for(int i = 0; i < n; i++){
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        } {
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        } if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            } i == 0 i 0 {
                System.out.print(A[i]);
            } System.out.print(A[i]) System.out.print System.out System System.out A[i] A i {
                System.out.print(" " + A[i]);
            } System.out.print(" " + A[i]) System.out.print System.out System System.out " " + A[i] " " A[i] A i System.out.println() System.out.println System.out System System.out 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) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");

        int[] A = new int[n];
        int chageBox = 0;
        int count = 0;

//      n????????´??°?????????A???????´?
        for (int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        }
        System.out.println();
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");

        int[] A = new int[n];
        int chageBox = 0;
        int count = 0;

//      n????????´??°?????????A???????´?
        for (int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        }
        System.out.println();
        System.out.println(count);
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");

        int[] A = new int[n];
        int chageBox = 0;
        int count = 0;

//      n????????´??°?????????A???????´?
        for (int i = 0; i < n; i++){
            A[i] = Integer.parseInt(input[i]);
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = n - 1; j > i; j--){
                if(A[j] < A[j-1]){
                    chageBox = A[j-1];
                    A[j-1] = A[j];
                    A[j] = chageBox;
                    count++;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == 0){
                System.out.print(A[i]);
            }else{
                System.out.print(" " + A[i]);
            }
        }
        System.out.println();
        System.out.println(count);
    }
}