import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int num = 0;
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
	for(int i = 1; i < n+1; i++){
    	for(int j = 0; j < n-i; j++){
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	}
	}
    for(int i = 0; i < n-1; i++){
      System.out.print(a[i] + " ");
    }
    System.out.println(a[n-1] + "\n" + num);
  }
}
 import java.util.*; util.* java class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int num = 0;
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
	for(int i = 1; i < n+1; i++){
    	for(int j = 0; j < n-i; j++){
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	}
	}
    for(int i = 0; i < n-1; i++){
      System.out.print(a[i] + " ");
    }
    System.out.println(a[n-1] + "\n" + num);
  }
} Main public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int num = 0;
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
	for(int i = 1; i < n+1; i++){
    	for(int j = 0; j < n-i; j++){
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	}
	}
    for(int i = 0; i < n-1; i++){
      System.out.print(a[i] + " ");
    }
    System.out.println(a[n-1] + "\n" + num);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int num = 0;
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
	for(int i = 1; i < n+1; i++){
    	for(int j = 0; j < n-i; j++){
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	}
	}
    for(int i = 0; i < n-1; i++){
      System.out.print(a[i] + " ");
    }
    System.out.println(a[n-1] + "\n" + num);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int a[] = new int[n]; a new int[n] n int num = 0; num 0 for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      a[i] = sc.nextInt();
    } {
      a[i] = sc.nextInt();
    } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc for(int i = 1; i < n+1; i++){
    	for(int j = 0; j < n-i; j++){
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	}
	} int i = 1; int i = 1; i 1 i < n+1 i n+1 n 1 i++ i++ i {
    	for(int j = 0; j < n-i; j++){
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	}
	} {
    	for(int j = 0; j < n-i; j++){
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	}
	} for(int j = 0; j < n-i; j++){
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	} int j = 0; int j = 0; j 0 j < n-i j n-i n i j++ j++ j {
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	} {
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	} if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		} a[j] > a[j+1] a[j] a j a[j+1] a j+1 j 1 {
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		} int work = a[j]; work a[j] a j a[j] = a[j+1] a[j] a j a[j+1] a j+1 j 1 a[j+1] = work a[j+1] a j+1 j 1 work num++ num 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] + "\n" + num) System.out.println System.out System System.out a[n-1] + "\n" + num a[n-1] + "\n" + num a[n-1] a n-1 n 1 "\n" num String args[] args
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int num = 0;
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
	for(int i = 1; i < n+1; i++){
    	for(int j = 0; j < n-i; j++){
      		if(a[j] > a[j+1]){
        		int work = a[j];
        		a[j] = a[j+1];
        		a[j+1] = work;
       			num++;
      		}
    	}
	}
    for(int i = 0; i < n-1; i++){
      System.out.print(a[i] + " ");
    }
    System.out.println(a[n-1] + "\n" + num);
  }
}

