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


class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	int n = Integer.parseInt(br.readLine());
  	int[] a = new int[n];
  	String[] elements = br.readLine().split(" ");
  	
	for (int i = 0; i < n; ++i){
		a[i] = Integer.parseInt(elements[i]);
	}
	
	int num = 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;
				num = num + 1;
			}
		}
	}
	
	for(int i = 0; i < n; ++i){
		System.out.print(i == 0 ? a[i] : " " + a[i]);
	}
	System.out.println();
	System.out.println(num);
	
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	int n = Integer.parseInt(br.readLine());
  	int[] a = new int[n];
  	String[] elements = br.readLine().split(" ");
  	
	for (int i = 0; i < n; ++i){
		a[i] = Integer.parseInt(elements[i]);
	}
	
	int num = 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;
				num = num + 1;
			}
		}
	}
	
	for(int i = 0; i < n; ++i){
		System.out.print(i == 0 ? a[i] : " " + a[i]);
	}
	System.out.println();
	System.out.println(num);
	
  }
} Main public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	int n = Integer.parseInt(br.readLine());
  	int[] a = new int[n];
  	String[] elements = br.readLine().split(" ");
  	
	for (int i = 0; i < n; ++i){
		a[i] = Integer.parseInt(elements[i]);
	}
	
	int num = 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;
				num = num + 1;
			}
		}
	}
	
	for(int i = 0; i < n; ++i){
		System.out.print(i == 0 ? a[i] : " " + a[i]);
	}
	System.out.println();
	System.out.println(num);
	
  } main {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	int n = Integer.parseInt(br.readLine());
  	int[] a = new int[n];
  	String[] elements = br.readLine().split(" ");
  	
	for (int i = 0; i < n; ++i){
		a[i] = Integer.parseInt(elements[i]);
	}
	
	int num = 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;
				num = num + 1;
			}
		}
	}
	
	for(int i = 0; i < n; ++i){
		System.out.print(i == 0 ? a[i] : " " + a[i]);
	}
	System.out.println();
	System.out.println(num);
	
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] a = new int[n]; a new int[n] n String[] elements = br.readLine().split(" "); elements br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int i = 0; i < n; ++i){
		a[i] = Integer.parseInt(elements[i]);
	} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
		a[i] = Integer.parseInt(elements[i]);
	} {
		a[i] = Integer.parseInt(elements[i]);
	} a[i] = Integer.parseInt(elements[i]) a[i] a i Integer.parseInt(elements[i]) Integer.parseInt Integer elements[i] elements i int num = 0; num 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;
				num = num + 1;
			}
		}
	} 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;
				num = num + 1;
			}
		}
	} {
		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;
				num = num + 1;
			}
		}
	} 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;
				num = num + 1;
			}
		} 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;
				num = num + 1;
			}
		} {
			if(a[j] < a[j-1]){
				int tmp = a[j-1];
				a[j-1] = a[j];
				a[j] = tmp;
				num = num + 1;
			}
		} if(a[j] < a[j-1]){
				int tmp = a[j-1];
				a[j-1] = a[j];
				a[j] = tmp;
				num = num + 1;
			} 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;
				num = num + 1;
			} 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 num = num + 1 num num + 1 num 1 for(int i = 0; i < n; ++i){
		System.out.print(i == 0 ? a[i] : " " + a[i]);
	} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
		System.out.print(i == 0 ? a[i] : " " + a[i]);
	} {
		System.out.print(i == 0 ? a[i] : " " + a[i]);
	} System.out.print(i == 0 ? a[i] : " " + a[i]) System.out.print System.out System System.out i == 0 ? a[i] : " " + a[i] i == 0 i 0 a[i] a i " " + a[i] " " a[i] a i System.out.println() System.out.println System.out System System.out System.out.println(num) System.out.println System.out System System.out num String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	int n = Integer.parseInt(br.readLine());
  	int[] a = new int[n];
  	String[] elements = br.readLine().split(" ");
  	
	for (int i = 0; i < n; ++i){
		a[i] = Integer.parseInt(elements[i]);
	}
	
	int num = 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;
				num = num + 1;
			}
		}
	}
	
	for(int i = 0; i < n; ++i){
		System.out.print(i == 0 ? a[i] : " " + a[i]);
	}
	System.out.println();
	System.out.println(num);
	
  }
}