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

public class Main {
	
	public static void main(String[] args) {
		int[] seq = null;
		
		try {
			seq = getSequence();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		seq = bubbleSort(seq);
	}
	
	public static int[] bubbleSort(int[] seq) {
		int count = 0;
		for (int i = 0; i < seq.length; i++) {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		}
		
		printArray(seq);
		System.out.println(count);
		return seq;
	}
	
	public static void printArray(int[] seq) {
		StringBuilder p = new StringBuilder();
		String lb = System.getProperty("line.separator");
		
		for (int i = 0; i < seq.length; i++) {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		}
		System.out.print(p);
	}
	
	public static int[] getSequence() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final int n = Integer.parseInt(reader.readLine());
		final String[] line = reader.readLine().split(" ");
		reader.close();
		
		final int[] seq = new int[n];
		for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
		}
		
		return seq;
	}
} 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) {
		int[] seq = null;
		
		try {
			seq = getSequence();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		seq = bubbleSort(seq);
	}
	
	public static int[] bubbleSort(int[] seq) {
		int count = 0;
		for (int i = 0; i < seq.length; i++) {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		}
		
		printArray(seq);
		System.out.println(count);
		return seq;
	}
	
	public static void printArray(int[] seq) {
		StringBuilder p = new StringBuilder();
		String lb = System.getProperty("line.separator");
		
		for (int i = 0; i < seq.length; i++) {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		}
		System.out.print(p);
	}
	
	public static int[] getSequence() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final int n = Integer.parseInt(reader.readLine());
		final String[] line = reader.readLine().split(" ");
		reader.close();
		
		final int[] seq = new int[n];
		for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
		}
		
		return seq;
	}
} Main public static void main(String[] args) {
		int[] seq = null;
		
		try {
			seq = getSequence();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		seq = bubbleSort(seq);
	} main {
		int[] seq = null;
		
		try {
			seq = getSequence();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		seq = bubbleSort(seq);
	} int[] seq = null; seq null try {
			seq = getSequence();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			seq = getSequence();
		} seq = getSequence() seq getSequence() getSequence seq = bubbleSort(seq) seq bubbleSort(seq) bubbleSort seq String[] args args public static int[] bubbleSort(int[] seq) {
		int count = 0;
		for (int i = 0; i < seq.length; i++) {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		}
		
		printArray(seq);
		System.out.println(count);
		return seq;
	} bubbleSort {
		int count = 0;
		for (int i = 0; i < seq.length; i++) {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		}
		
		printArray(seq);
		System.out.println(count);
		return seq;
	} int count = 0; count 0 for (int i = 0; i < seq.length; i++) {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		} int i = 0; int i = 0; i 0 i < seq.length i seq.length seq seq.length i++ i++ i {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		} {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		} final int check = count; check count int key = seq[0]; key seq[0] seq 0 for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			} int j = 1; int j = 1; j 1 j < seq.length-i j seq.length-i seq.length seq seq.length i j++ j++ j {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			} {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			} if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				} key <= seq[j] key seq[j] seq j {
					key = seq[j];
				} key = seq[j] key seq[j] seq j {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				} seq[j-1] = seq[j] seq[j-1] seq j-1 j 1 seq[j] seq j seq[j] = key seq[j] seq j key count++ count if (check == count) break; check == count check count break; printArray(seq) printArray seq System.out.println(count) System.out.println System.out System System.out count return seq; seq int[] seq seq public static void printArray(int[] seq) {
		StringBuilder p = new StringBuilder();
		String lb = System.getProperty("line.separator");
		
		for (int i = 0; i < seq.length; i++) {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		}
		System.out.print(p);
	} printArray {
		StringBuilder p = new StringBuilder();
		String lb = System.getProperty("line.separator");
		
		for (int i = 0; i < seq.length; i++) {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		}
		System.out.print(p);
	} StringBuilder p = new StringBuilder(); p new StringBuilder() String lb = System.getProperty("line.separator"); lb System.getProperty("line.separator") System.getProperty System "line.separator" for (int i = 0; i < seq.length; i++) {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		} int i = 0; int i = 0; i 0 i < seq.length i seq.length seq seq.length i++ i++ i {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		} {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		} p.append(seq[i]).append(i < seq.length-1 ? " " : lb) p.append(seq[i]).append p.append(seq[i]) p.append p seq[i] seq i i < seq.length-1 ? " " : lb i < seq.length-1 i seq.length-1 seq.length seq seq.length 1 " " lb System.out.print(p) System.out.print System.out System System.out p int[] seq seq public static int[] getSequence() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final int n = Integer.parseInt(reader.readLine());
		final String[] line = reader.readLine().split(" ");
		reader.close();
		
		final int[] seq = new int[n];
		for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
		}
		
		return seq;
	} getSequence {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final int n = Integer.parseInt(reader.readLine());
		final String[] line = reader.readLine().split(" ");
		reader.close();
		
		final int[] seq = new int[n];
		for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
		}
		
		return seq;
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) final int n = Integer.parseInt(reader.readLine()); n Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader final String[] line = reader.readLine().split(" "); line reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " reader.close() reader.close reader final int[] seq = new int[n]; seq new int[n] n for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
		} int i = 0; int i = 0; i 0 i < seq.length i seq.length seq seq.length i++ i++ i {
			seq[i] = Integer.parseInt(line[i]);
		} {
			seq[i] = Integer.parseInt(line[i]);
		} seq[i] = Integer.parseInt(line[i]) seq[i] seq i Integer.parseInt(line[i]) Integer.parseInt Integer line[i] line i return seq; seq public class Main {
	
	public static void main(String[] args) {
		int[] seq = null;
		
		try {
			seq = getSequence();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		seq = bubbleSort(seq);
	}
	
	public static int[] bubbleSort(int[] seq) {
		int count = 0;
		for (int i = 0; i < seq.length; i++) {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		}
		
		printArray(seq);
		System.out.println(count);
		return seq;
	}
	
	public static void printArray(int[] seq) {
		StringBuilder p = new StringBuilder();
		String lb = System.getProperty("line.separator");
		
		for (int i = 0; i < seq.length; i++) {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		}
		System.out.print(p);
	}
	
	public static int[] getSequence() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final int n = Integer.parseInt(reader.readLine());
		final String[] line = reader.readLine().split(" ");
		reader.close();
		
		final int[] seq = new int[n];
		for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
		}
		
		return seq;
	}
} public class Main {
	
	public static void main(String[] args) {
		int[] seq = null;
		
		try {
			seq = getSequence();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		seq = bubbleSort(seq);
	}
	
	public static int[] bubbleSort(int[] seq) {
		int count = 0;
		for (int i = 0; i < seq.length; i++) {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		}
		
		printArray(seq);
		System.out.println(count);
		return seq;
	}
	
	public static void printArray(int[] seq) {
		StringBuilder p = new StringBuilder();
		String lb = System.getProperty("line.separator");
		
		for (int i = 0; i < seq.length; i++) {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		}
		System.out.print(p);
	}
	
	public static int[] getSequence() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final int n = Integer.parseInt(reader.readLine());
		final String[] line = reader.readLine().split(" ");
		reader.close();
		
		final int[] seq = new int[n];
		for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
		}
		
		return seq;
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) {
		int[] seq = null;
		
		try {
			seq = getSequence();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		seq = bubbleSort(seq);
	}
	
	public static int[] bubbleSort(int[] seq) {
		int count = 0;
		for (int i = 0; i < seq.length; i++) {
			final int check = count;
			int key = seq[0];
			for (int j = 1; j < seq.length-i; j++) {
				if (key <= seq[j]) {
					key = seq[j];
				} else {
					seq[j-1] = seq[j];
					seq[j] = key;
					count++;
				}
			}
			
			if (check == count) break;
		}
		
		printArray(seq);
		System.out.println(count);
		return seq;
	}
	
	public static void printArray(int[] seq) {
		StringBuilder p = new StringBuilder();
		String lb = System.getProperty("line.separator");
		
		for (int i = 0; i < seq.length; i++) {
			p.append(seq[i]).append(i < seq.length-1 ? " " : lb);
		}
		System.out.print(p);
	}
	
	public static int[] getSequence() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		final int n = Integer.parseInt(reader.readLine());
		final String[] line = reader.readLine().split(" ");
		reader.close();
		
		final int[] seq = new int[n];
		for (int i = 0; i < seq.length; i++) {
			seq[i] = Integer.parseInt(line[i]);
		}
		
		return seq;
	}
}