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

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] s = reader.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(s[i]);
		}
		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		}
		StringBuilder builder = new StringBuilder();
		for (int k = 0; k < n; k++) {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		}
		builder.append("\n").append(sum);
		System.out.println(builder);

	}
} 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) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] s = reader.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(s[i]);
		}
		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		}
		StringBuilder builder = new StringBuilder();
		for (int k = 0; k < n; k++) {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		}
		builder.append("\n").append(sum);
		System.out.println(builder);

	}
} Main public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] s = reader.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(s[i]);
		}
		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		}
		StringBuilder builder = new StringBuilder();
		for (int k = 0; k < n; k++) {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		}
		builder.append("\n").append(sum);
		System.out.println(builder);

	} main {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] s = reader.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(s[i]);
		}
		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		}
		StringBuilder builder = new StringBuilder();
		for (int k = 0; k < n; k++) {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		}
		builder.append("\n").append(sum);
		System.out.println(builder);

	} BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in)); reader new BufferedReader(new InputStreamReader(
				System.in)) int n = Integer.parseInt(reader.readLine()); n Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader String[] s = reader.readLine().split(" "); s reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(s[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = Integer.parseInt(s[i]);
		} {
			a[i] = Integer.parseInt(s[i]);
		} a[i] = Integer.parseInt(s[i]) a[i] a i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i int sum = 0; sum 0 for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		} {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		} for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			} int j = n - 1; int j = n - 1; j n - 1 n 1 j >= i + 1 j i + 1 i 1 j-- j-- j {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			} {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			} if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				} a[j] < a[j - 1] a[j] a j a[j - 1] a j - 1 j 1 {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				} sum++ sum int temp = a[j]; temp a[j] a j a[j] = a[j - 1] a[j] a j a[j - 1] a j - 1 j 1 a[j - 1] = temp a[j - 1] a j - 1 j 1 temp StringBuilder builder = new StringBuilder(); builder new StringBuilder() for (int k = 0; k < n; k++) {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		} int k = 0; int k = 0; k 0 k < n k n k++ k++ k {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		} {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		} if (k > 0)
				builder.append(" "); k > 0 k 0 builder.append(" ") builder.append builder " " builder.append(a[k]) builder.append builder a[k] a k builder.append("\n").append(sum) builder.append("\n").append builder.append("\n") builder.append builder "\n" sum System.out.println(builder) System.out.println System.out System System.out builder String[] args args public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] s = reader.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(s[i]);
		}
		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		}
		StringBuilder builder = new StringBuilder();
		for (int k = 0; k < n; k++) {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		}
		builder.append("\n").append(sum);
		System.out.println(builder);

	}
} public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] s = reader.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(s[i]);
		}
		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		}
		StringBuilder builder = new StringBuilder();
		for (int k = 0; k < n; k++) {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		}
		builder.append("\n").append(sum);
		System.out.println(builder);

	}
} Main

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

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] s = reader.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(s[i]);
		}
		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (a[j] < a[j - 1]) {
					sum++;
					int temp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = temp;
				}
			}
		}
		StringBuilder builder = new StringBuilder();
		for (int k = 0; k < n; k++) {
			if (k > 0)
				builder.append(" ");
			builder.append(a[k]);
		}
		builder.append("\n").append(sum);
		System.out.println(builder);

	}
}