import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int a  = number.nextInt();
		int[] b = new int[a];
		int c = 0,count = 0;
		double d;

		for(int i = 0;i < a;i++) {
			b[i] = number.nextInt();
		}
		for(int i = 0;i < b.length - 1;i++) {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		}
		for(int i = 0;i < b.length;i++) {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		}
		System.out.println(count);
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int a  = number.nextInt();
		int[] b = new int[a];
		int c = 0,count = 0;
		double d;

		for(int i = 0;i < a;i++) {
			b[i] = number.nextInt();
		}
		for(int i = 0;i < b.length - 1;i++) {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		}
		for(int i = 0;i < b.length;i++) {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int a  = number.nextInt();
		int[] b = new int[a];
		int c = 0,count = 0;
		double d;

		for(int i = 0;i < a;i++) {
			b[i] = number.nextInt();
		}
		for(int i = 0;i < b.length - 1;i++) {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		}
		for(int i = 0;i < b.length;i++) {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		}
		System.out.println(count);
	} main {
		Scanner number = new Scanner(System.in);
		int a  = number.nextInt();
		int[] b = new int[a];
		int c = 0,count = 0;
		double d;

		for(int i = 0;i < a;i++) {
			b[i] = number.nextInt();
		}
		for(int i = 0;i < b.length - 1;i++) {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		}
		for(int i = 0;i < b.length;i++) {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		}
		System.out.println(count);
	} Scanner number = new Scanner(System.in); number new Scanner(System.in) int a  = number.nextInt(); a number.nextInt() number.nextInt number int[] b = new int[a]; b new int[a] a int c = 0 c 0 count = 0; count 0 double d; d for(int i = 0;i < a;i++) {
			b[i] = number.nextInt();
		} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
			b[i] = number.nextInt();
		} {
			b[i] = number.nextInt();
		} b[i] = number.nextInt() b[i] b i number.nextInt() number.nextInt number for(int i = 0;i < b.length - 1;i++) {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		} int i = 0; int i = 0; i 0 i < b.length - 1 i b.length - 1 b.length b b.length 1 i++ i++ i {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		} {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		} for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			} int j = 0; int j = 0; j 0 j < a - 1 j a - 1 a 1 j++ j++ j {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			} {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			} if(j + 1 > b.length) break; j + 1 > b.length j + 1 j 1 b.length b b.length break; if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				} b[j] > b[j + 1] b[j] b j b[j + 1] b j + 1 j 1 {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				} c = b[j] c b[j] b j b[j] = b[j + 1] b[j] b j b[j + 1] b j + 1 j 1 b[j + 1] = c b[j + 1] b j + 1 j 1 c count++ count a-- a for(int i = 0;i < b.length;i++) {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		} int i = 0; int i = 0; i 0 i < b.length i b.length b b.length i++ i++ i {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		} {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		} System.out.print(b[i]) System.out.print System.out System System.out b[i] b i if(i != b.length - 1) System.out.print(" ");
			else System.out.println(""); i != b.length - 1 i b.length - 1 b.length b b.length 1 System.out.print(" ") System.out.print System.out System System.out " " 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 public class Main {
	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int a  = number.nextInt();
		int[] b = new int[a];
		int c = 0,count = 0;
		double d;

		for(int i = 0;i < a;i++) {
			b[i] = number.nextInt();
		}
		for(int i = 0;i < b.length - 1;i++) {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		}
		for(int i = 0;i < b.length;i++) {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		}
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int a  = number.nextInt();
		int[] b = new int[a];
		int c = 0,count = 0;
		double d;

		for(int i = 0;i < a;i++) {
			b[i] = number.nextInt();
		}
		for(int i = 0;i < b.length - 1;i++) {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		}
		for(int i = 0;i < b.length;i++) {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		}
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner number = new Scanner(System.in);
		int a  = number.nextInt();
		int[] b = new int[a];
		int c = 0,count = 0;
		double d;

		for(int i = 0;i < a;i++) {
			b[i] = number.nextInt();
		}
		for(int i = 0;i < b.length - 1;i++) {
			for(int j = 0;j < a - 1;j++) {
				if(j + 1 > b.length) break;
				if(b[j] > b[j + 1]) {
					c = b[j];
					b[j] = b[j + 1];
					b[j + 1] = c;
					count++;
				}
				
				
			}
			
			a--;
		}
		for(int i = 0;i < b.length;i++) {
			System.out.print(b[i]);
			if(i != b.length - 1) System.out.print(" ");
			else System.out.println("");
		}
		System.out.println(count);
	}
}

