import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int line[] = new int[n];
		int temp = 0;
		int exchange = 0;

		for(int i=0; i<n; i++){
			line[i] = Integer.parseInt(std.next());
		}
		boolean flag = true;
		while (flag){
			flag = false;
			for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			}
		}
		String outsd = Integer.toString(line[0]);
		for(int i=1; i<n; i++){
			outsd += " "+line[i];
		}
		System.out.println(outsd);
		System.out.println(exchange);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int line[] = new int[n];
		int temp = 0;
		int exchange = 0;

		for(int i=0; i<n; i++){
			line[i] = Integer.parseInt(std.next());
		}
		boolean flag = true;
		while (flag){
			flag = false;
			for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			}
		}
		String outsd = Integer.toString(line[0]);
		for(int i=1; i<n; i++){
			outsd += " "+line[i];
		}
		System.out.println(outsd);
		System.out.println(exchange);
	}
} Main public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int line[] = new int[n];
		int temp = 0;
		int exchange = 0;

		for(int i=0; i<n; i++){
			line[i] = Integer.parseInt(std.next());
		}
		boolean flag = true;
		while (flag){
			flag = false;
			for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			}
		}
		String outsd = Integer.toString(line[0]);
		for(int i=1; i<n; i++){
			outsd += " "+line[i];
		}
		System.out.println(outsd);
		System.out.println(exchange);
	} main {
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int line[] = new int[n];
		int temp = 0;
		int exchange = 0;

		for(int i=0; i<n; i++){
			line[i] = Integer.parseInt(std.next());
		}
		boolean flag = true;
		while (flag){
			flag = false;
			for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			}
		}
		String outsd = Integer.toString(line[0]);
		for(int i=1; i<n; i++){
			outsd += " "+line[i];
		}
		System.out.println(outsd);
		System.out.println(exchange);
	} Scanner std = new Scanner(System.in); std new Scanner(System.in) int n = Integer.parseInt(std.next()); n Integer.parseInt(std.next()) Integer.parseInt Integer std.next() std.next std int line[] = new int[n]; line new int[n] n int temp = 0; temp 0 int exchange = 0; exchange 0 for(int i=0; i<n; i++){
			line[i] = Integer.parseInt(std.next());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			line[i] = Integer.parseInt(std.next());
		} {
			line[i] = Integer.parseInt(std.next());
		} line[i] = Integer.parseInt(std.next()) line[i] line i Integer.parseInt(std.next()) Integer.parseInt Integer std.next() std.next std boolean flag = true; flag true while (flag){
			flag = false;
			for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			}
		} flag {
			flag = false;
			for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			}
		} flag = false flag false for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			} int j=(n-1); int j=(n-1); j (n-1) n 1 j>0 j 0 j-- j-- j {
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			} {
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			} if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				} line[j] < line[j-1] line[j] line j line[j-1] line j-1 j 1 {
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				} temp = line[j] temp line[j] line j line[j] = line[j-1] line[j] line j line[j-1] line j-1 j 1 line[j-1] = temp line[j-1] line j-1 j 1 temp exchange++ exchange flag = true flag true String outsd = Integer.toString(line[0]); outsd Integer.toString(line[0]) Integer.toString Integer line[0] line 0 for(int i=1; i<n; i++){
			outsd += " "+line[i];
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			outsd += " "+line[i];
		} {
			outsd += " "+line[i];
		} outsd += " "+line[i] outsd " "+line[i] " " line[i] line i System.out.println(outsd) System.out.println System.out System System.out outsd System.out.println(exchange) System.out.println System.out System System.out exchange String[] args args public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int line[] = new int[n];
		int temp = 0;
		int exchange = 0;

		for(int i=0; i<n; i++){
			line[i] = Integer.parseInt(std.next());
		}
		boolean flag = true;
		while (flag){
			flag = false;
			for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			}
		}
		String outsd = Integer.toString(line[0]);
		for(int i=1; i<n; i++){
			outsd += " "+line[i];
		}
		System.out.println(outsd);
		System.out.println(exchange);
	}
} public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int line[] = new int[n];
		int temp = 0;
		int exchange = 0;

		for(int i=0; i<n; i++){
			line[i] = Integer.parseInt(std.next());
		}
		boolean flag = true;
		while (flag){
			flag = false;
			for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			}
		}
		String outsd = Integer.toString(line[0]);
		for(int i=1; i<n; i++){
			outsd += " "+line[i];
		}
		System.out.println(outsd);
		System.out.println(exchange);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int line[] = new int[n];
		int temp = 0;
		int exchange = 0;

		for(int i=0; i<n; i++){
			line[i] = Integer.parseInt(std.next());
		}
		boolean flag = true;
		while (flag){
			flag = false;
			for(int j=(n-1); j>0; j--){
				if (line[j] < line[j-1]){
					temp = line[j]; line[j] = line[j-1]; line[j-1] = temp;
					exchange++;
					flag = true;
				}
			}
		}
		String outsd = Integer.toString(line[0]);
		for(int i=1; i<n; i++){
			outsd += " "+line[i];
		}
		System.out.println(outsd);
		System.out.println(exchange);
	}
}