import java.util.Scanner;

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

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