

import java.io.*;

class Main
{
 
  public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
 
      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      bubbleSort(array, array.length);
 
    }catch(Exception e){
      System.out.println(e);
    }
  }
 
  public static void bubbleSort(int[] A, int N)
  {
	  int swapNum = 0;
    StringBuilder sb = new StringBuilder(); 
    for(int i = 0; i < N - 1; ++i){
    	for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	}
    }
    show(A,sb);
    System.out.println(Integer.toString(swapNum));
    
  }
  
  public static void show(int[] A,StringBuilder sb){
	    for(int i = 0;i < A.length;++i){
	    	sb.append(A[i]);
	    	if(i + 1 < A.length){
	    		sb.append(" ");
	    	}
	    }
	    System.out.println(sb.toString());
	    sb.setLength(0);
  }
} import java.io.*; io.* java class Main
{
 
  public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
 
      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      bubbleSort(array, array.length);
 
    }catch(Exception e){
      System.out.println(e);
    }
  }
 
  public static void bubbleSort(int[] A, int N)
  {
	  int swapNum = 0;
    StringBuilder sb = new StringBuilder(); 
    for(int i = 0; i < N - 1; ++i){
    	for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	}
    }
    show(A,sb);
    System.out.println(Integer.toString(swapNum));
    
  }
  
  public static void show(int[] A,StringBuilder sb){
	    for(int i = 0;i < A.length;++i){
	    	sb.append(A[i]);
	    	if(i + 1 < A.length){
	    		sb.append(" ");
	    	}
	    }
	    System.out.println(sb.toString());
	    sb.setLength(0);
  }
} Main public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
 
      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      bubbleSort(array, array.length);
 
    }catch(Exception e){
      System.out.println(e);
    }
  } main {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
 
      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      bubbleSort(array, array.length);
 
    }catch(Exception e){
      System.out.println(e);
    }
  } try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
 
      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      bubbleSort(array, array.length);
 
    }catch(Exception e){
      System.out.println(e);
    } catch(Exception e){
      System.out.println(e);
    } Exception e {
      System.out.println(e);
    } System.out.println(e) System.out.println System.out System System.out e {
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
 
      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      bubbleSort(array, array.length);
 
    } 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 String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] array = new int[n]; array new int[n] n for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        array[i] = Integer.parseInt(str[i]);
      } {
        array[i] = Integer.parseInt(str[i]);
      } array[i] = Integer.parseInt(str[i]) array[i] array i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i bubbleSort(array, array.length) bubbleSort array array.length array array.length String[] args args public static void bubbleSort(int[] A, int N)
  {
	  int swapNum = 0;
    StringBuilder sb = new StringBuilder(); 
    for(int i = 0; i < N - 1; ++i){
    	for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	}
    }
    show(A,sb);
    System.out.println(Integer.toString(swapNum));
    
  } bubbleSort {
	  int swapNum = 0;
    StringBuilder sb = new StringBuilder(); 
    for(int i = 0; i < N - 1; ++i){
    	for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	}
    }
    show(A,sb);
    System.out.println(Integer.toString(swapNum));
    
  } int swapNum = 0; swapNum 0 StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i = 0; i < N - 1; ++i){
    	for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	}
    } int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 ++i ++i i {
    	for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	}
    } {
    	for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	}
    } for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	} 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 tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	} {
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	} if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		} A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 {
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		} final 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 swapNum++ swapNum show(A,sb) show A sb System.out.println(Integer.toString(swapNum)) System.out.println System.out System System.out Integer.toString(swapNum) Integer.toString Integer swapNum int[] A A int N N public static void show(int[] A,StringBuilder sb){
	    for(int i = 0;i < A.length;++i){
	    	sb.append(A[i]);
	    	if(i + 1 < A.length){
	    		sb.append(" ");
	    	}
	    }
	    System.out.println(sb.toString());
	    sb.setLength(0);
  } show {
	    for(int i = 0;i < A.length;++i){
	    	sb.append(A[i]);
	    	if(i + 1 < A.length){
	    		sb.append(" ");
	    	}
	    }
	    System.out.println(sb.toString());
	    sb.setLength(0);
  } for(int i = 0;i < A.length;++i){
	    	sb.append(A[i]);
	    	if(i + 1 < A.length){
	    		sb.append(" ");
	    	}
	    } int i = 0; int i = 0; i 0 i < A.length i A.length A A.length ++i ++i i {
	    	sb.append(A[i]);
	    	if(i + 1 < A.length){
	    		sb.append(" ");
	    	}
	    } {
	    	sb.append(A[i]);
	    	if(i + 1 < A.length){
	    		sb.append(" ");
	    	}
	    } sb.append(A[i]) sb.append sb A[i] A i if(i + 1 < A.length){
	    		sb.append(" ");
	    	} i + 1 < A.length i + 1 i 1 A.length A A.length {
	    		sb.append(" ");
	    	} sb.append(" ") sb.append sb " " System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb sb.setLength(0) sb.setLength sb 0 int[] A A StringBuilder sb sb


import java.io.*;

class Main
{
 
  public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
 
      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      bubbleSort(array, array.length);
 
    }catch(Exception e){
      System.out.println(e);
    }
  }
 
  public static void bubbleSort(int[] A, int N)
  {
	  int swapNum = 0;
    StringBuilder sb = new StringBuilder(); 
    for(int i = 0; i < N - 1; ++i){
    	for(int j = N - 1;j > i;--j){
    		if(A[j] < A[j - 1]){
    			final int tmp = A[j];
    			A[j] = A[j - 1];
    			A[j - 1] = tmp;
    			swapNum++;
    		}
    	}
    }
    show(A,sb);
    System.out.println(Integer.toString(swapNum));
    
  }
  
  public static void show(int[] A,StringBuilder sb){
	    for(int i = 0;i < A.length;++i){
	    	sb.append(A[i]);
	    	if(i + 1 < A.length){
	    		sb.append(" ");
	    	}
	    }
	    System.out.println(sb.toString());
	    sb.setLength(0);
  }
}