import java.util.Scanner;


public class Main{

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int[] values = new int[a];
		for(int i=0 ; i<values.length ; i++) {
			values[i] = s.nextInt();
		}
		solve(values);
	}

	public static void solve(int[] values) {
		boolean flg = true;
		int cnt = 0;
		while(flg) {
			flg = false;
			for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			}
		}
		String disp = "";
		for(int i=0 ; i<values.length ; i++) {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		}
		System.out.print(disp+"\n");
		System.out.println(cnt);
	}
} import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int[] values = new int[a];
		for(int i=0 ; i<values.length ; i++) {
			values[i] = s.nextInt();
		}
		solve(values);
	}

	public static void solve(int[] values) {
		boolean flg = true;
		int cnt = 0;
		while(flg) {
			flg = false;
			for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			}
		}
		String disp = "";
		for(int i=0 ; i<values.length ; i++) {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		}
		System.out.print(disp+"\n");
		System.out.println(cnt);
	}
} Main public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int[] values = new int[a];
		for(int i=0 ; i<values.length ; i++) {
			values[i] = s.nextInt();
		}
		solve(values);
	} main {

		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int[] values = new int[a];
		for(int i=0 ; i<values.length ; i++) {
			values[i] = s.nextInt();
		}
		solve(values);
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int a = s.nextInt(); a s.nextInt() s.nextInt s int[] values = new int[a]; values new int[a] a for(int i=0 ; i<values.length ; i++) {
			values[i] = s.nextInt();
		} int i=0 ; int i=0 ; i 0 i<values.length i values.length values values.length i++ i++ i {
			values[i] = s.nextInt();
		} {
			values[i] = s.nextInt();
		} values[i] = s.nextInt() values[i] values i s.nextInt() s.nextInt s solve(values) solve values String[] args args public static void solve(int[] values) {
		boolean flg = true;
		int cnt = 0;
		while(flg) {
			flg = false;
			for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			}
		}
		String disp = "";
		for(int i=0 ; i<values.length ; i++) {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		}
		System.out.print(disp+"\n");
		System.out.println(cnt);
	} solve {
		boolean flg = true;
		int cnt = 0;
		while(flg) {
			flg = false;
			for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			}
		}
		String disp = "";
		for(int i=0 ; i<values.length ; i++) {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		}
		System.out.print(disp+"\n");
		System.out.println(cnt);
	} boolean flg = true; flg true int cnt = 0; cnt 0 while(flg) {
			flg = false;
			for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			}
		} flg {
			flg = false;
			for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			}
		} flg = false flg false for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			} int i = values.length - 1 ; int i = values.length - 1 ; i values.length - 1 values.length values values.length 1 i > 0 i 0 i-- i-- i {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			} {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			} if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				} values[i] < values[i-1] values[i] values i values[i-1] values i-1 i 1 {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				} int tmp = values[i]; tmp values[i] values i values[i] = values[i-1] values[i] values i values[i-1] values i-1 i 1 values[i-1] = tmp values[i-1] values i-1 i 1 tmp cnt++ cnt flg = true flg true String disp = ""; disp "" for(int i=0 ; i<values.length ; i++) {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		} int i=0 ; int i=0 ; i 0 i<values.length i values.length values values.length i++ i++ i {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		} {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		} disp += values[i] disp values[i] values i if(i+1<values.length)
				disp += " "; i+1<values.length i+1 i 1 values.length values values.length disp += " " disp " " System.out.print(disp+"\n") System.out.print System.out System System.out disp+"\n" disp "\n" System.out.println(cnt) System.out.println System.out System System.out cnt int[] values values public class Main{

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int[] values = new int[a];
		for(int i=0 ; i<values.length ; i++) {
			values[i] = s.nextInt();
		}
		solve(values);
	}

	public static void solve(int[] values) {
		boolean flg = true;
		int cnt = 0;
		while(flg) {
			flg = false;
			for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			}
		}
		String disp = "";
		for(int i=0 ; i<values.length ; i++) {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		}
		System.out.print(disp+"\n");
		System.out.println(cnt);
	}
} public class Main{

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int[] values = new int[a];
		for(int i=0 ; i<values.length ; i++) {
			values[i] = s.nextInt();
		}
		solve(values);
	}

	public static void solve(int[] values) {
		boolean flg = true;
		int cnt = 0;
		while(flg) {
			flg = false;
			for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			}
		}
		String disp = "";
		for(int i=0 ; i<values.length ; i++) {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		}
		System.out.print(disp+"\n");
		System.out.println(cnt);
	}
} Main
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int[] values = new int[a];
		for(int i=0 ; i<values.length ; i++) {
			values[i] = s.nextInt();
		}
		solve(values);
	}

	public static void solve(int[] values) {
		boolean flg = true;
		int cnt = 0;
		while(flg) {
			flg = false;
			for(int i = values.length - 1 ; i > 0 ; i--) {
				if(values[i] < values[i-1]) {
					int tmp = values[i];
					values[i] = values[i-1];
					values[i-1] = tmp;
					cnt++;
					flg = true;
				}
			}
		}
		String disp = "";
		for(int i=0 ; i<values.length ; i++) {
			disp += values[i];
			if(i+1<values.length)
				disp += " ";
		}
		System.out.print(disp+"\n");
		System.out.println(cnt);
	}
}