import java.util.Scanner;

/**
 * Created by ??\??? on 2016/12/6.
 */
public class Main {
    static int si(String s) {
        return Integer.parseInt(s);
    }
    static int run(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()) {
            int T = Integer.parseInt(scan.nextLine());
            String[] lines = scan.nextLine().split(" ");
            int sum = 0;
            for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            }
            for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            }
            System.out.println();
            System.out.println(sum);

        }
        return 1;
    }

    public static void main(String[] args) {
        run(args);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    static int si(String s) {
        return Integer.parseInt(s);
    }
    static int run(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()) {
            int T = Integer.parseInt(scan.nextLine());
            String[] lines = scan.nextLine().split(" ");
            int sum = 0;
            for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            }
            for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            }
            System.out.println();
            System.out.println(sum);

        }
        return 1;
    }

    public static void main(String[] args) {
        run(args);
    }
} Main static int si(String s) {
        return Integer.parseInt(s);
    } si {
        return Integer.parseInt(s);
    } return Integer.parseInt(s); Integer.parseInt(s) Integer.parseInt Integer s String s s static int run(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()) {
            int T = Integer.parseInt(scan.nextLine());
            String[] lines = scan.nextLine().split(" ");
            int sum = 0;
            for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            }
            for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            }
            System.out.println();
            System.out.println(sum);

        }
        return 1;
    } run {
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()) {
            int T = Integer.parseInt(scan.nextLine());
            String[] lines = scan.nextLine().split(" ");
            int sum = 0;
            for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            }
            for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            }
            System.out.println();
            System.out.println(sum);

        }
        return 1;
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while(scan.hasNext()) {
            int T = Integer.parseInt(scan.nextLine());
            String[] lines = scan.nextLine().split(" ");
            int sum = 0;
            for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            }
            for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            }
            System.out.println();
            System.out.println(sum);

        } scan.hasNext() scan.hasNext scan {
            int T = Integer.parseInt(scan.nextLine());
            String[] lines = scan.nextLine().split(" ");
            int sum = 0;
            for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            }
            for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            }
            System.out.println();
            System.out.println(sum);

        } int T = Integer.parseInt(scan.nextLine()); T Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan String[] lines = scan.nextLine().split(" "); lines scan.nextLine().split(" ") scan.nextLine().split scan.nextLine() scan.nextLine scan " " int sum = 0; sum 0 for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            } int i = 0; int i = 0; i 0 i<lines.length-1 i lines.length-1 lines.length lines lines.length 1 i++ i++ i {
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            } {
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            } for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                } int j = lines.length - 1; int j = lines.length - 1; j lines.length - 1 lines.length lines lines.length 1 j>=i+1 j i+1 i 1 j-- j-- j {
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                } {
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                } if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    } si(lines[j])<si(lines[j-1]) si(lines[j]) si lines[j] lines j si(lines[j-1]) si lines[j-1] lines j-1 j 1 {
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    } String s = lines[j]; s lines[j] lines j lines[j] = lines[j-1] lines[j] lines j lines[j-1] lines j-1 j 1 lines[j-1] = s lines[j-1] lines j-1 j 1 s sum++ sum for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            } int i = 0; int i = 0; i 0 i<lines.length i lines.length lines lines.length i++ i++ i {
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            } {
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            } if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]); i==0 i 0 System.out.print(lines[0]) System.out.print System.out System System.out lines[0] lines 0 System.out.print(" "+lines[i]) System.out.print System.out System System.out " "+lines[i] " " lines[i] lines i System.out.println() System.out.println System.out System System.out System.out.println(sum) System.out.println System.out System System.out sum return 1; 1 String[] args args public static void main(String[] args) {
        run(args);
    } main {
        run(args);
    } run(args) run args String[] args args public class Main {
    static int si(String s) {
        return Integer.parseInt(s);
    }
    static int run(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()) {
            int T = Integer.parseInt(scan.nextLine());
            String[] lines = scan.nextLine().split(" ");
            int sum = 0;
            for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            }
            for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            }
            System.out.println();
            System.out.println(sum);

        }
        return 1;
    }

    public static void main(String[] args) {
        run(args);
    }
} public class Main {
    static int si(String s) {
        return Integer.parseInt(s);
    }
    static int run(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()) {
            int T = Integer.parseInt(scan.nextLine());
            String[] lines = scan.nextLine().split(" ");
            int sum = 0;
            for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            }
            for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            }
            System.out.println();
            System.out.println(sum);

        }
        return 1;
    }

    public static void main(String[] args) {
        run(args);
    }
} Main
import java.util.Scanner;

/**
 * Created by ??\??? on 2016/12/6.
 */
public class Main {
    static int si(String s) {
        return Integer.parseInt(s);
    }
    static int run(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()) {
            int T = Integer.parseInt(scan.nextLine());
            String[] lines = scan.nextLine().split(" ");
            int sum = 0;
            for(int i = 0;i<lines.length-1;i++){
                for(int j = lines.length - 1;j>=i+1;j--){
                    if(si(lines[j])<si(lines[j-1])){
                        String s = lines[j];
                        lines[j] = lines[j-1];
                        lines[j-1] = s;
                        sum++;
                    }
                }
            }
            for(int i = 0;i<lines.length;i++){
                if(i==0)
                    System.out.print(lines[0]);
                else
                    System.out.print(" "+lines[i]);
            }
            System.out.println();
            System.out.println(sum);

        }
        return 1;
    }

    public static void main(String[] args) {
        run(args);
    }
}