import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static int BubbleSort(final int N, int[] A){
		
		int count = 0;
		while(true){
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		}
		
		return count;
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		final int times = BubbleSort(N, A);
		
		for(int i = 0; i < N; i++){
			if(i != 0){
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.println();
		
		System.out.println(times);
	}
} import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {
	
	public static int BubbleSort(final int N, int[] A){
		
		int count = 0;
		while(true){
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		}
		
		return count;
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		final int times = BubbleSort(N, A);
		
		for(int i = 0; i < N; i++){
			if(i != 0){
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.println();
		
		System.out.println(times);
	}
} Main public static int BubbleSort(final int N, int[] A){
		
		int count = 0;
		while(true){
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		}
		
		return count;
	} BubbleSort {
		
		int count = 0;
		while(true){
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		}
		
		return count;
	} int count = 0; count 0 while(true){
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		} true {
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		} boolean update = false; update false for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			} int i = N - 1; int i = N - 1; i N - 1 N 1 i >= 1 i 1 i-- i-- i {
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			} {
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			} if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				} A[i] < A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 {
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				} int tmp = A[i]; tmp A[i] A i A[i] = A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 A[i - 1] = tmp A[i - 1] A i - 1 i 1 tmp count++ count update = true update true if(!update){
				break;
			} !update update {
				break;
			} break; return count; count final int N N int[] A A public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		final int times = BubbleSort(N, A);
		
		for(int i = 0; i < N; i++){
			if(i != 0){
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.println();
		
		System.out.println(times);
	} main {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		final int times = BubbleSort(N, A);
		
		for(int i = 0; i < N; i++){
			if(i != 0){
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.println();
		
		System.out.println(times);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = new int[N]; A new int[N] N 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 final int times = BubbleSort(N, A); times BubbleSort(N, A) BubbleSort N A 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.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(times) System.out.println System.out System System.out times String args[] args public class Main {
	
	public static int BubbleSort(final int N, int[] A){
		
		int count = 0;
		while(true){
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		}
		
		return count;
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		final int times = BubbleSort(N, A);
		
		for(int i = 0; i < N; i++){
			if(i != 0){
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.println();
		
		System.out.println(times);
	}
} public class Main {
	
	public static int BubbleSort(final int N, int[] A){
		
		int count = 0;
		while(true){
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		}
		
		return count;
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		final int times = BubbleSort(N, A);
		
		for(int i = 0; i < N; i++){
			if(i != 0){
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.println();
		
		System.out.println(times);
	}
} Main
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static int BubbleSort(final int N, int[] A){
		
		int count = 0;
		while(true){
			boolean update = false;
			
			for(int i = N - 1; i >= 1; i--){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					
					count++;
					update = true;
				}
			}
			
			if(!update){
				break;
			}
		}
		
		return count;
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		final int times = BubbleSort(N, A);
		
		for(int i = 0; i < N; i++){
			if(i != 0){
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.println();
		
		System.out.println(times);
	}
}