import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int tmp;
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int change = 0;
        for(int i=N;i>=1;i--){
            for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            }
        }
        for(int i=0;i<N;i++){
            System.out.print(A[i]);
            if(i<N-1) System.out.print(" ");
        }
        System.out.println();
        System.out.println(change);
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int tmp;
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int change = 0;
        for(int i=N;i>=1;i--){
            for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            }
        }
        for(int i=0;i<N;i++){
            System.out.print(A[i]);
            if(i<N-1) System.out.print(" ");
        }
        System.out.println();
        System.out.println(change);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int tmp;
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int change = 0;
        for(int i=N;i>=1;i--){
            for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            }
        }
        for(int i=0;i<N;i++){
            System.out.print(A[i]);
            if(i<N-1) System.out.print(" ");
        }
        System.out.println();
        System.out.println(change);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int tmp;
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int change = 0;
        for(int i=N;i>=1;i--){
            for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            }
        }
        for(int i=0;i<N;i++){
            System.out.print(A[i]);
            if(i<N-1) System.out.print(" ");
        }
        System.out.println();
        System.out.println(change);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int tmp; tmp 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 change = 0; change 0 for(int i=N;i>=1;i--){
            for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            }
        } int i=N; int i=N; i N i>=1 i 1 i-- i-- i {
            for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            }
        } {
            for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            }
        } for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            } int j=0; int j=0; j 0 j<i-1 j i-1 i 1 j++ j++ j {
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            } {
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            } if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                } A[j] > A[j+1] A[j] A j A[j+1] A j+1 j 1 {
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                } tmp = A[j] tmp A[j] A j A[j] = A[j+1] A[j] A j A[j+1] A j+1 j 1 A[j+1] = tmp A[j+1] A j+1 j 1 tmp change++ change for(int i=0;i<N;i++){
            System.out.print(A[i]);
            if(i<N-1) System.out.print(" ");
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            System.out.print(A[i]);
            if(i<N-1) System.out.print(" ");
        } {
            System.out.print(A[i]);
            if(i<N-1) System.out.print(" ");
        } System.out.print(A[i]) System.out.print System.out System System.out A[i] A i if(i<N-1) System.out.print(" "); i<N-1 i N-1 N 1 System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out System.out.println(change) System.out.println System.out System System.out change String[] args args
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int tmp;
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int change = 0;
        for(int i=N;i>=1;i--){
            for(int j=0;j<i-1;j++){
                if(A[j] > A[j+1]){
                    tmp = A[j];
                    A[j] = A[j+1];
                    A[j+1] = tmp;
                    change++;
                }
            }
        }
        for(int i=0;i<N;i++){
            System.out.print(A[i]);
            if(i<N-1) System.out.print(" ");
        }
        System.out.println();
        System.out.println(change);
    }
}
