import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int array[] = new int[N];
		int count = 0;
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++){
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		}
		System.out.println(count);
		sc.close();

	}
}
 import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int array[] = new int[N];
		int count = 0;
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++){
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		}
		System.out.println(count);
		sc.close();

	}
} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int array[] = new int[N];
		int count = 0;
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++){
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		}
		System.out.println(count);
		sc.close();

	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int array[] = new int[N];
		int count = 0;
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++){
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		}
		System.out.println(count);
		sc.close();

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int array[] = new int[N]; array new int[N] N int count = 0; count 0 for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			array[i] = sc.nextInt();
		} {
			array[i] = sc.nextInt();
		} array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc for(int i = 0; i < N; i++){
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		} {
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		} for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			} int j = N-1; int j = N-1; j N-1 N 1 j >=1 j 1 j-- j-- j {
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			} {
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			} if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				} array[j]< array[j-1] array[j] array j array[j-1] array j-1 j 1 {
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				} int tmp = array[j]; tmp array[j] array j array[j] = array[j-1] array[j] array j array[j-1] array j-1 j 1 array[j-1] = tmp array[j-1] array j-1 j 1 tmp count++ count for(int i = 0; i < N; i++){
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		} {
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		} if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			} i == N-1 i N-1 N 1 {
				System.out.println(array[i]);
			} System.out.println(array[i]) System.out.println System.out System System.out array[i] array i {
				System.out.print(array[i] + " ");
			} System.out.print(array[i] + " ") System.out.print System.out System System.out array[i] + " " array[i] array i " " System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int array[] = new int[N];
		int count = 0;
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++){
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		}
		System.out.println(count);
		sc.close();

	}
} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int array[] = new int[N];
		int count = 0;
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++){
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		}
		System.out.println(count);
		sc.close();

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int array[] = new int[N];
		int count = 0;
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++){
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		}
		System.out.println(count);
		sc.close();

	}
}

