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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];
		
		String[] str = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		}
		
		int count = 0;
		
		for(int i = 1; i < n; i++){
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		}
		System.out.println(count);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];
		
		String[] str = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		}
		
		int count = 0;
		
		for(int i = 1; i < n; i++){
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];
		
		String[] str = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		}
		
		int count = 0;
		
		for(int i = 1; i < n; i++){
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		}
		System.out.println(count);
	} main {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];
		
		String[] str = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		}
		
		int count = 0;
		
		for(int i = 1; i < n; i++){
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		}
		System.out.println(count);
	} 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[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			A[i] = Integer.parseInt(str[i]);
		} {
			A[i] = Integer.parseInt(str[i]);
		} A[i] = Integer.parseInt(str[i]) A[i] A i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i int count = 0; count 0 for(int i = 1; i < n; i++){
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		} {
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		} boolean flag = true; flag true while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			} flag {
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			} flag = false flag false 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;
						flag = true;
						
						count++;
					}
				} 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;
						flag = true;
						
						count++;
					}
				} {
					if(A[j] < A[j - 1]){
						int tmp = A[j];
						A[j] = A[j - 1];
						A[j - 1] = tmp;
						flag = true;
						
						count++;
					}
				} if(A[j] < A[j - 1]){
						int tmp = A[j];
						A[j] = A[j - 1];
						A[j - 1] = tmp;
						flag = true;
						
						count++;
					} 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;
						flag = true;
						
						count++;
					} 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 flag = true flag true count++ count for(int i = 0; i < n; i++){
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		} {
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		} System.out.print(A[i]) System.out.print System.out System System.out A[i] A i if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			} i + 1 == n i + 1 i 1 n {
				System.out.print("\n");
			} System.out.print("\n") System.out.print System.out System System.out "\n" {
				System.out.print(" ");
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];
		
		String[] str = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		}
		
		int count = 0;
		
		for(int i = 1; i < n; i++){
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		}
		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];
		
		String[] str = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		}
		
		int count = 0;
		
		for(int i = 1; i < n; i++){
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		}
		System.out.println(count);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] A = new int[n];
		
		String[] str = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			A[i] = Integer.parseInt(str[i]);
		}
		
		int count = 0;
		
		for(int i = 1; i < n; i++){
			boolean flag = true;
		
			while(flag){
				flag = false;
			
				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;
						flag = true;
						
						count++;
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.print(A[i]);
			
			if(i + 1 == n){
				System.out.print("\n");
			} else {
				System.out.print(" ");
			}
		}
		System.out.println(count);
	}
}