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

/**
 *
 * @author Y
 */
public class Main {
    public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] a = new int[N];
        String[] s = br.readLine().split(" ");
        for(int i = 0;i<N;i++){
            a[i] = Integer.parseInt(s[i]);
        }
        
        int Nswap = 0;
        for(int i=0;i<N;i++){
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        }
        
        for(int i=0;i<N-1;i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[N-1]);
        System.out.println(Nswap);
        
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main {
    public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] a = new int[N];
        String[] s = br.readLine().split(" ");
        for(int i = 0;i<N;i++){
            a[i] = Integer.parseInt(s[i]);
        }
        
        int Nswap = 0;
        for(int i=0;i<N;i++){
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        }
        
        for(int i=0;i<N-1;i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[N-1]);
        System.out.println(Nswap);
        
    }
} Main public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] a = new int[N];
        String[] s = br.readLine().split(" ");
        for(int i = 0;i<N;i++){
            a[i] = Integer.parseInt(s[i]);
        }
        
        int Nswap = 0;
        for(int i=0;i<N;i++){
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        }
        
        for(int i=0;i<N-1;i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[N-1]);
        System.out.println(Nswap);
        
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] a = new int[N];
        String[] s = br.readLine().split(" ");
        for(int i = 0;i<N;i++){
            a[i] = Integer.parseInt(s[i]);
        }
        
        int Nswap = 0;
        for(int i=0;i<N;i++){
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        }
        
        for(int i=0;i<N-1;i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[N-1]);
        System.out.println(Nswap);
        
    } 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 int[] a = new int[N]; a new int[N] N String[] s = br.readLine().split(" "); s br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int i = 0;i<N;i++){
            a[i] = Integer.parseInt(s[i]);
        } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
            a[i] = Integer.parseInt(s[i]);
        } {
            a[i] = Integer.parseInt(s[i]);
        } a[i] = Integer.parseInt(s[i]) a[i] a i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i int Nswap = 0; Nswap 0 for(int i=0;i<N;i++){
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        } {
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        } for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            } int j = N-1; int j = N-1; j N-1 N 1 j>=i+1 j i+1 i 1 j-- j-- j {
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            } {
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            } if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                } a[j]<a[j-1] a[j] a j a[j-1] a j-1 j 1 {
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                } int 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 Nswap++ Nswap for(int i=0;i<N-1;i++){
            System.out.print(a[i] + " ");
        } int i=0; int i=0; i 0 i<N-1 i N-1 N 1 i++ i++ i {
            System.out.print(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(a[N-1]) System.out.println System.out System System.out a[N-1] a N-1 N 1 System.out.println(Nswap) System.out.println System.out System System.out Nswap String[]args args public class Main {
    public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] a = new int[N];
        String[] s = br.readLine().split(" ");
        for(int i = 0;i<N;i++){
            a[i] = Integer.parseInt(s[i]);
        }
        
        int Nswap = 0;
        for(int i=0;i<N;i++){
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        }
        
        for(int i=0;i<N-1;i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[N-1]);
        System.out.println(Nswap);
        
    }
} public class Main {
    public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] a = new int[N];
        String[] s = br.readLine().split(" ");
        for(int i = 0;i<N;i++){
            a[i] = Integer.parseInt(s[i]);
        }
        
        int Nswap = 0;
        for(int i=0;i<N;i++){
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        }
        
        for(int i=0;i<N-1;i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[N-1]);
        System.out.println(Nswap);
        
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

/**
 *
 * @author Y
 */
public class Main {
    public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int[] a = new int[N];
        String[] s = br.readLine().split(" ");
        for(int i = 0;i<N;i++){
            a[i] = Integer.parseInt(s[i]);
        }
        
        int Nswap = 0;
        for(int i=0;i<N;i++){
            for(int j = N-1;j>=i+1;j--){
                if(a[j]<a[j-1]){
                    int tmp = a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                    
                    Nswap++;
                }
            }
        }
        
        for(int i=0;i<N-1;i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[N-1]);
        System.out.println(Nswap);
        
    }
}