import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		List<Integer> list = new ArrayList<Integer>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		int N = Integer.parseInt(br.readLine());
		String[] s_in = br.readLine().split(" ");
		for (int i = 0; i < N; i++)
			list.add(Integer.parseInt(s_in[i]));
		
		int cnt_swap = 0;
		for (int i = 0; i < N; i++) {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for (int n : list) {
			sb.append(n);
			sb.append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		sb.append('\n');
		sb.append(cnt_swap);
		System.out.println(sb.toString());
	}
	
} import java.io.BufferedReader; BufferedReader java.io import java.io.FileReader; FileReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util public class Main {
	public static void main(String[] args) throws Exception {
		List<Integer> list = new ArrayList<Integer>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		int N = Integer.parseInt(br.readLine());
		String[] s_in = br.readLine().split(" ");
		for (int i = 0; i < N; i++)
			list.add(Integer.parseInt(s_in[i]));
		
		int cnt_swap = 0;
		for (int i = 0; i < N; i++) {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for (int n : list) {
			sb.append(n);
			sb.append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		sb.append('\n');
		sb.append(cnt_swap);
		System.out.println(sb.toString());
	}
	
} Main public static void main(String[] args) throws Exception {
		List<Integer> list = new ArrayList<Integer>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		int N = Integer.parseInt(br.readLine());
		String[] s_in = br.readLine().split(" ");
		for (int i = 0; i < N; i++)
			list.add(Integer.parseInt(s_in[i]));
		
		int cnt_swap = 0;
		for (int i = 0; i < N; i++) {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for (int n : list) {
			sb.append(n);
			sb.append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		sb.append('\n');
		sb.append(cnt_swap);
		System.out.println(sb.toString());
	} main {
		List<Integer> list = new ArrayList<Integer>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		int N = Integer.parseInt(br.readLine());
		String[] s_in = br.readLine().split(" ");
		for (int i = 0; i < N; i++)
			list.add(Integer.parseInt(s_in[i]));
		
		int cnt_swap = 0;
		for (int i = 0; i < N; i++) {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for (int n : list) {
			sb.append(n);
			sb.append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		sb.append('\n');
		sb.append(cnt_swap);
		System.out.println(sb.toString());
	} List<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() 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 String[] s_in = br.readLine().split(" "); s_in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int i = 0; i < N; i++)
			list.add(Integer.parseInt(s_in[i])); int i = 0; int i = 0; i 0 i < N i N i++ i++ i list.add(Integer.parseInt(s_in[i])); list.add(Integer.parseInt(s_in[i])) list.add list Integer.parseInt(s_in[i]) Integer.parseInt Integer s_in[i] s_in i int cnt_swap = 0; cnt_swap 0 for (int i = 0; i < N; i++) {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		} {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		} for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			} int j = N - 1; int j = N - 1; j N - 1 N 1 j > 0 j 0 j-- j-- j {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			} {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			} if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				} list.get(j) < list.get(j - 1) list.get(j) list.get list j list.get(j - 1) list.get list j - 1 j 1 {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				} int tmp = list.get(j - 1); tmp list.get(j - 1) list.get list j - 1 j 1 list.set(j - 1, list.get(j)) list.set list j - 1 j 1 list.get(j) list.get list j list.set(j, tmp) list.set list j tmp cnt_swap++ cnt_swap StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int n : list) {
			sb.append(n);
			sb.append(' ');
		} int n list {
			sb.append(n);
			sb.append(' ');
		} {
			sb.append(n);
			sb.append(' ');
		} sb.append(n) sb.append sb n sb.append(' ') sb.append sb ' ' sb.deleteCharAt(sb.length() - 1) sb.deleteCharAt sb sb.length() - 1 sb.length() sb.length sb 1 sb.append('\n') sb.append sb '\n' sb.append(cnt_swap) sb.append sb cnt_swap System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		List<Integer> list = new ArrayList<Integer>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		int N = Integer.parseInt(br.readLine());
		String[] s_in = br.readLine().split(" ");
		for (int i = 0; i < N; i++)
			list.add(Integer.parseInt(s_in[i]));
		
		int cnt_swap = 0;
		for (int i = 0; i < N; i++) {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for (int n : list) {
			sb.append(n);
			sb.append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		sb.append('\n');
		sb.append(cnt_swap);
		System.out.println(sb.toString());
	}
	
} public class Main {
	public static void main(String[] args) throws Exception {
		List<Integer> list = new ArrayList<Integer>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		int N = Integer.parseInt(br.readLine());
		String[] s_in = br.readLine().split(" ");
		for (int i = 0; i < N; i++)
			list.add(Integer.parseInt(s_in[i]));
		
		int cnt_swap = 0;
		for (int i = 0; i < N; i++) {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for (int n : list) {
			sb.append(n);
			sb.append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		sb.append('\n');
		sb.append(cnt_swap);
		System.out.println(sb.toString());
	}
	
} Main
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		List<Integer> list = new ArrayList<Integer>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		// BufferedReader br = new BufferedReader(new FileReader("in2.txt"));
		int N = Integer.parseInt(br.readLine());
		String[] s_in = br.readLine().split(" ");
		for (int i = 0; i < N; i++)
			list.add(Integer.parseInt(s_in[i]));
		
		int cnt_swap = 0;
		for (int i = 0; i < N; i++) {
			// list[0..i-1]??????????????????
			for (int j = N - 1; j > 0; j--) {
				if (list.get(j) < list.get(j - 1)) {
					int tmp = list.get(j - 1);
					list.set(j - 1, list.get(j));
					list.set(j, tmp);
					cnt_swap++;
				}
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for (int n : list) {
			sb.append(n);
			sb.append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		sb.append('\n');
		sb.append(cnt_swap);
		System.out.println(sb.toString());
	}
	
}