import java.io.*;

class Main{
    
        public static int maxv(int x, int y){
            if(x >= y){
                return x;
            }else{
                return y;
            }
        }

        public static int minv(int x, int y){
            if(x <= y){
                return x;
            }else{
                return y;
            }
        }

    public static void main(String[] args){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                int N = Integer.parseInt(reader.readLine());;
		    	String line = reader.readLine();
			    String[] strAry = line.split(" ");
                
			    int[] a = new int[N];
			
			    for (int i = 0;i < N; i++){
				    a[i] = Integer.parseInt(strAry[i]);
			    }

                int count = 0;

                while(true){
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                }
            
                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(count);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
} import java.io.*; io.* java class Main{
    
        public static int maxv(int x, int y){
            if(x >= y){
                return x;
            }else{
                return y;
            }
        }

        public static int minv(int x, int y){
            if(x <= y){
                return x;
            }else{
                return y;
            }
        }

    public static void main(String[] args){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                int N = Integer.parseInt(reader.readLine());;
		    	String line = reader.readLine();
			    String[] strAry = line.split(" ");
                
			    int[] a = new int[N];
			
			    for (int i = 0;i < N; i++){
				    a[i] = Integer.parseInt(strAry[i]);
			    }

                int count = 0;

                while(true){
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                }
            
                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(count);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
} Main public static int maxv(int x, int y){
            if(x >= y){
                return x;
            }else{
                return y;
            }
        } maxv {
            if(x >= y){
                return x;
            }else{
                return y;
            }
        } if(x >= y){
                return x;
            }else{
                return y;
            } x >= y x y {
                return x;
            } return x; x {
                return y;
            } return y; y int x x int y y public static int minv(int x, int y){
            if(x <= y){
                return x;
            }else{
                return y;
            }
        } minv {
            if(x <= y){
                return x;
            }else{
                return y;
            }
        } if(x <= y){
                return x;
            }else{
                return y;
            } x <= y x y {
                return x;
            } return x; x {
                return y;
            } return y; y int x x int y y public static void main(String[] args){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                int N = Integer.parseInt(reader.readLine());;
		    	String line = reader.readLine();
			    String[] strAry = line.split(" ");
                
			    int[] a = new int[N];
			
			    for (int i = 0;i < N; i++){
				    a[i] = Integer.parseInt(strAry[i]);
			    }

                int count = 0;

                while(true){
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                }
            
                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(count);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    } main {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                int N = Integer.parseInt(reader.readLine());;
		    	String line = reader.readLine();
			    String[] strAry = line.split(" ");
                
			    int[] a = new int[N];
			
			    for (int i = 0;i < N; i++){
				    a[i] = Integer.parseInt(strAry[i]);
			    }

                int count = 0;

                while(true){
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                }
            
                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(count);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) try {       
                int N = Integer.parseInt(reader.readLine());;
		    	String line = reader.readLine();
			    String[] strAry = line.split(" ");
                
			    int[] a = new int[N];
			
			    for (int i = 0;i < N; i++){
				    a[i] = Integer.parseInt(strAry[i]);
			    }

                int count = 0;

                while(true){
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                }
            
                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(count);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        } IOException e {
            //TODO: handle exception
            System.out.println(e);
        } System.out.println(e) System.out.println System.out System System.out e {       
                int N = Integer.parseInt(reader.readLine());;
		    	String line = reader.readLine();
			    String[] strAry = line.split(" ");
                
			    int[] a = new int[N];
			
			    for (int i = 0;i < N; i++){
				    a[i] = Integer.parseInt(strAry[i]);
			    }

                int count = 0;

                while(true){
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                }
            
                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(count);
                            
        } int N = Integer.parseInt(reader.readLine()); N Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader String line = reader.readLine(); line reader.readLine() reader.readLine reader String[] strAry = line.split(" "); strAry line.split(" ") line.split line " " int[] a = new int[N]; a new int[N] N for (int i = 0;i < N; i++){
				    a[i] = Integer.parseInt(strAry[i]);
			    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				    a[i] = Integer.parseInt(strAry[i]);
			    } {
				    a[i] = Integer.parseInt(strAry[i]);
			    } a[i] = Integer.parseInt(strAry[i]) a[i] a i Integer.parseInt(strAry[i]) Integer.parseInt Integer strAry[i] strAry i int count = 0; count 0 while(true){
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                } true {
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                } int v = 0; v 0 for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    } int i = 0; int i = 0; i 0 i < (N -1) i (N -1) N 1 i++ i++ i {
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    } {
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    } if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        } a[i + 1] < a[i] a[i + 1] a i + 1 i 1 a[i] a i {
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        } int k = a[i]; k a[i] a i a[i] = a[i+1] a[i] a i a[i+1] a i+1 i 1 a[i + 1] = k a[i + 1] a i + 1 i 1 k count += 1 count 1 v = 1 v 1 if(v == 0){
                        break;
                    } v == 0 v 0 {
                        break;
                    } break; 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.print System.out System System.out " " 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
import java.io.*;

class Main{
    
        public static int maxv(int x, int y){
            if(x >= y){
                return x;
            }else{
                return y;
            }
        }

        public static int minv(int x, int y){
            if(x <= y){
                return x;
            }else{
                return y;
            }
        }

    public static void main(String[] args){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                int N = Integer.parseInt(reader.readLine());;
		    	String line = reader.readLine();
			    String[] strAry = line.split(" ");
                
			    int[] a = new int[N];
			
			    for (int i = 0;i < N; i++){
				    a[i] = Integer.parseInt(strAry[i]);
			    }

                int count = 0;

                while(true){
                    int v = 0;
                    for(int i = 0; i < (N -1); i++){
                        if(a[i + 1] < a[i]){
                            int k = a[i];
                            a[i] = a[i+1];
                            a[i + 1] = k;
                            count += 1;
                            v = 1;
                        }
                    }

                    if(v == 0){
                        break;
                    }
                }
            
                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(count);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
}