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

class Main{
    public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        final String[] in = br.readLine().split(" ");
        final int[] a = new int[n];
        for(int i = 0; i<n; i++){
            a[i] = Integer.parseInt(in[i]);
        }
        int num = 0;
        for(int i = 0; i<n; i++){
            for(int j = n-1; j>i; j--){
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            }
        }
        out.print(a[0]);
        for(int i = 1; i<n; i++)
            out.print(" "+a[i]);
        out.println();
        out.println(num);
        out.flush();
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io class Main{
    public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        final String[] in = br.readLine().split(" ");
        final int[] a = new int[n];
        for(int i = 0; i<n; i++){
            a[i] = Integer.parseInt(in[i]);
        }
        int num = 0;
        for(int i = 0; i<n; i++){
            for(int j = n-1; j>i; j--){
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            }
        }
        out.print(a[0]);
        for(int i = 1; i<n; i++)
            out.print(" "+a[i]);
        out.println();
        out.println(num);
        out.flush();
    }
} Main public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        final String[] in = br.readLine().split(" ");
        final int[] a = new int[n];
        for(int i = 0; i<n; i++){
            a[i] = Integer.parseInt(in[i]);
        }
        int num = 0;
        for(int i = 0; i<n; i++){
            for(int j = n-1; j>i; j--){
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            }
        }
        out.print(a[0]);
        for(int i = 1; i<n; i++)
            out.print(" "+a[i]);
        out.println();
        out.println(num);
        out.flush();
    } main {
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        final String[] in = br.readLine().split(" ");
        final int[] a = new int[n];
        for(int i = 0; i<n; i++){
            a[i] = Integer.parseInt(in[i]);
        }
        int num = 0;
        for(int i = 0; i<n; i++){
            for(int j = n-1; j>i; j--){
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            }
        }
        out.print(a[0]);
        for(int i = 1; i<n; i++)
            out.print(" "+a[i]);
        out.println();
        out.println(num);
        out.flush();
    } final PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) final int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br final String[] in = br.readLine().split(" "); in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " final int[] a = new int[n]; a new int[n] n for(int i = 0; i<n; i++){
            a[i] = Integer.parseInt(in[i]);
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            a[i] = Integer.parseInt(in[i]);
        } {
            a[i] = Integer.parseInt(in[i]);
        } a[i] = Integer.parseInt(in[i]) a[i] a i Integer.parseInt(in[i]) Integer.parseInt Integer in[i] in i int num = 0; num 0 for(int i = 0; i<n; i++){
            for(int j = n-1; j>i; j--){
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            for(int j = n-1; j>i; j--){
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            }
        } {
            for(int j = n-1; j>i; j--){
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            }
        } for(int j = n-1; j>i; j--){
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            } 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]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            } {
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            } if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                } a[j]<a[j-1] a[j] a j a[j-1] a j-1 j 1 {
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                } final int t = a[j]; t a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = t a[j-1] a j-1 j 1 t num++ num out.print(a[0]) out.print out a[0] a 0 for(int i = 1; i<n; i++)
            out.print(" "+a[i]); int i = 1; int i = 1; i 1 i<n i n i++ i++ i out.print(" "+a[i]); out.print(" "+a[i]) out.print out " "+a[i] " " a[i] a i out.println() out.println out out.println(num) out.println out num out.flush() out.flush out String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class Main{
    public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        final String[] in = br.readLine().split(" ");
        final int[] a = new int[n];
        for(int i = 0; i<n; i++){
            a[i] = Integer.parseInt(in[i]);
        }
        int num = 0;
        for(int i = 0; i<n; i++){
            for(int j = n-1; j>i; j--){
                if(a[j]<a[j-1]){
                    final int t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                    num++;
                }
            }
        }
        out.print(a[0]);
        for(int i = 1; i<n; i++)
            out.print(" "+a[i]);
        out.println();
        out.println(num);
        out.flush();
    }
}