import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		int N, k = 0;
		int[] A = new int[100];
		Scanner stdIn = new Scanner(System.in);

		N = stdIn.nextInt();

		for(int i = 0; i < N; i++){
			A[i] = stdIn.nextInt();
		}

		k = bubbleSort(N, A);
		trace(N, A, k);
	}

	public static void trace(int N, int[] A, int k){
		for(int i = 0; i < N; i++){
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(k);
	}

	public static int bubbleSort(int N, int[] A){
		int k = 0;
		for(int i = 0; i < N - 1; i++){
			for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		}
		return k;
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		int N, k = 0;
		int[] A = new int[100];
		Scanner stdIn = new Scanner(System.in);

		N = stdIn.nextInt();

		for(int i = 0; i < N; i++){
			A[i] = stdIn.nextInt();
		}

		k = bubbleSort(N, A);
		trace(N, A, k);
	}

	public static void trace(int N, int[] A, int k){
		for(int i = 0; i < N; i++){
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(k);
	}

	public static int bubbleSort(int N, int[] A){
		int k = 0;
		for(int i = 0; i < N - 1; i++){
			for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		}
		return k;
	}

} Main public static void main(String[] args){
		int N, k = 0;
		int[] A = new int[100];
		Scanner stdIn = new Scanner(System.in);

		N = stdIn.nextInt();

		for(int i = 0; i < N; i++){
			A[i] = stdIn.nextInt();
		}

		k = bubbleSort(N, A);
		trace(N, A, k);
	} main {
		int N, k = 0;
		int[] A = new int[100];
		Scanner stdIn = new Scanner(System.in);

		N = stdIn.nextInt();

		for(int i = 0; i < N; i++){
			A[i] = stdIn.nextInt();
		}

		k = bubbleSort(N, A);
		trace(N, A, k);
	} int N N k = 0; k 0 int[] A = new int[100]; A new int[100] 100 Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) N = stdIn.nextInt() N stdIn.nextInt() stdIn.nextInt stdIn for(int i = 0; i < N; i++){
			A[i] = stdIn.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			A[i] = stdIn.nextInt();
		} {
			A[i] = stdIn.nextInt();
		} A[i] = stdIn.nextInt() A[i] A i stdIn.nextInt() stdIn.nextInt stdIn k = bubbleSort(N, A) k bubbleSort(N, A) bubbleSort N A trace(N, A, k) trace N A k String[] args args public static void trace(int N, int[] A, int k){
		for(int i = 0; i < N; i++){
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(k);
	} trace {
		for(int i = 0; i < N; i++){
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(k);
	} for(int i = 0; i < N; i++){
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		} {
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		} if(i > 0)	System.out.print(" "); i > 0 i 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(A[i]) System.out.print System.out System System.out A[i] A i System.out.println() System.out.println System.out System System.out System.out.println(k) System.out.println System.out System System.out k int N N int[] A A int k k public static int bubbleSort(int N, int[] A){
		int k = 0;
		for(int i = 0; i < N - 1; i++){
			for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		}
		return k;
	} bubbleSort {
		int k = 0;
		for(int i = 0; i < N - 1; i++){
			for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		}
		return k;
	} int k = 0; k 0 for(int i = 0; i < N - 1; i++){
			for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		} 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; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		} {
			for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		} for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			} int j = N - 1; int j = N - 1; j N - 1 N 1 j > i j i j-- j-- j {
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			} {
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			} if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				} A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 {
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				} int tmp = A[j - 1]; tmp A[j - 1] A j - 1 j 1 A[j - 1] = A[j] A[j - 1] A j - 1 j 1 A[j] A j A[j] = tmp A[j] A j tmp k++ k return k; k int N N int[] A A public class Main {
	public static void main(String[] args){
		int N, k = 0;
		int[] A = new int[100];
		Scanner stdIn = new Scanner(System.in);

		N = stdIn.nextInt();

		for(int i = 0; i < N; i++){
			A[i] = stdIn.nextInt();
		}

		k = bubbleSort(N, A);
		trace(N, A, k);
	}

	public static void trace(int N, int[] A, int k){
		for(int i = 0; i < N; i++){
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(k);
	}

	public static int bubbleSort(int N, int[] A){
		int k = 0;
		for(int i = 0; i < N - 1; i++){
			for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		}
		return k;
	}

} public class Main {
	public static void main(String[] args){
		int N, k = 0;
		int[] A = new int[100];
		Scanner stdIn = new Scanner(System.in);

		N = stdIn.nextInt();

		for(int i = 0; i < N; i++){
			A[i] = stdIn.nextInt();
		}

		k = bubbleSort(N, A);
		trace(N, A, k);
	}

	public static void trace(int N, int[] A, int k){
		for(int i = 0; i < N; i++){
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(k);
	}

	public static int bubbleSort(int N, int[] A){
		int k = 0;
		for(int i = 0; i < N - 1; i++){
			for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		}
		return k;
	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		int N, k = 0;
		int[] A = new int[100];
		Scanner stdIn = new Scanner(System.in);

		N = stdIn.nextInt();

		for(int i = 0; i < N; i++){
			A[i] = stdIn.nextInt();
		}

		k = bubbleSort(N, A);
		trace(N, A, k);
	}

	public static void trace(int N, int[] A, int k){
		for(int i = 0; i < N; i++){
			if(i > 0)	System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(k);
	}

	public static int bubbleSort(int N, int[] A){
		int k = 0;
		for(int i = 0; i < N - 1; i++){
			for(int j = N - 1; j > i; j--){
				if(A[j] < A[j - 1]){
					int tmp = A[j - 1];
					A[j - 1] = A[j];
					A[j] = tmp;
					k++;
				}
			}
		}
		return k;
	}

}