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

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> lines = new ArrayList<String>();
		while (br.ready()){
			lines.add(br.readLine());
		}
		String[] tmp = lines.get(1).split(" ");
		int[] num = new int[tmp.length];
		for(int i=0; i<tmp.length; i++){
			num[i] = Integer.parseInt(tmp[i]);
		}
		int N= sort(num);
		print(num, N);


	}
	static void print(int[] num, int cnt){
		for(int i=0;i<num.length-1;i++){
			System.out.print(num[i]);
			System.out.print(" ");
		}
		System.out.println(num[num.length-1]);
		System.out.println(cnt);
	}
	static int sort(int[] num){
		int tmp;
		int cnt=0;
		for(int i=0; i<num.length;i++){
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		}
		return cnt;
		
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io import java.util.ArrayList; ArrayList java.util public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> lines = new ArrayList<String>();
		while (br.ready()){
			lines.add(br.readLine());
		}
		String[] tmp = lines.get(1).split(" ");
		int[] num = new int[tmp.length];
		for(int i=0; i<tmp.length; i++){
			num[i] = Integer.parseInt(tmp[i]);
		}
		int N= sort(num);
		print(num, N);


	}
	static void print(int[] num, int cnt){
		for(int i=0;i<num.length-1;i++){
			System.out.print(num[i]);
			System.out.print(" ");
		}
		System.out.println(num[num.length-1]);
		System.out.println(cnt);
	}
	static int sort(int[] num){
		int tmp;
		int cnt=0;
		for(int i=0; i<num.length;i++){
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		}
		return cnt;
		
	}
} Main public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> lines = new ArrayList<String>();
		while (br.ready()){
			lines.add(br.readLine());
		}
		String[] tmp = lines.get(1).split(" ");
		int[] num = new int[tmp.length];
		for(int i=0; i<tmp.length; i++){
			num[i] = Integer.parseInt(tmp[i]);
		}
		int N= sort(num);
		print(num, N);


	} main {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> lines = new ArrayList<String>();
		while (br.ready()){
			lines.add(br.readLine());
		}
		String[] tmp = lines.get(1).split(" ");
		int[] num = new int[tmp.length];
		for(int i=0; i<tmp.length; i++){
			num[i] = Integer.parseInt(tmp[i]);
		}
		int N= sort(num);
		print(num, N);


	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) ArrayList<String> lines = new ArrayList<String>(); lines new ArrayList<String>() while (br.ready()){
			lines.add(br.readLine());
		} br.ready() br.ready br {
			lines.add(br.readLine());
		} lines.add(br.readLine()) lines.add lines br.readLine() br.readLine br String[] tmp = lines.get(1).split(" "); tmp lines.get(1).split(" ") lines.get(1).split lines.get(1) lines.get lines 1 " " int[] num = new int[tmp.length]; num new int[tmp.length] tmp.length tmp tmp.length for(int i=0; i<tmp.length; i++){
			num[i] = Integer.parseInt(tmp[i]);
		} int i=0; int i=0; i 0 i<tmp.length i tmp.length tmp tmp.length i++ i++ i {
			num[i] = Integer.parseInt(tmp[i]);
		} {
			num[i] = Integer.parseInt(tmp[i]);
		} num[i] = Integer.parseInt(tmp[i]) num[i] num i Integer.parseInt(tmp[i]) Integer.parseInt Integer tmp[i] tmp i int N= sort(num); N sort(num) sort num print(num, N) print num N String[] args args static void print(int[] num, int cnt){
		for(int i=0;i<num.length-1;i++){
			System.out.print(num[i]);
			System.out.print(" ");
		}
		System.out.println(num[num.length-1]);
		System.out.println(cnt);
	} print {
		for(int i=0;i<num.length-1;i++){
			System.out.print(num[i]);
			System.out.print(" ");
		}
		System.out.println(num[num.length-1]);
		System.out.println(cnt);
	} for(int i=0;i<num.length-1;i++){
			System.out.print(num[i]);
			System.out.print(" ");
		} int i=0; int i=0; i 0 i<num.length-1 i num.length-1 num.length num num.length 1 i++ i++ i {
			System.out.print(num[i]);
			System.out.print(" ");
		} {
			System.out.print(num[i]);
			System.out.print(" ");
		} System.out.print(num[i]) System.out.print System.out System System.out num[i] num i System.out.print(" ") System.out.print System.out System System.out " " System.out.println(num[num.length-1]) System.out.println System.out System System.out num[num.length-1] num num.length-1 num.length num num.length 1 System.out.println(cnt) System.out.println System.out System System.out cnt int[] num num int cnt cnt static int sort(int[] num){
		int tmp;
		int cnt=0;
		for(int i=0; i<num.length;i++){
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		}
		return cnt;
		
	} sort {
		int tmp;
		int cnt=0;
		for(int i=0; i<num.length;i++){
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		}
		return cnt;
		
	} int tmp; tmp int cnt=0; cnt 0 for(int i=0; i<num.length;i++){
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		} int i=0; int i=0; i 0 i<num.length i num.length num num.length i++ i++ i {
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		} {
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		} for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			} int j=num.length-1; int j=num.length-1; j num.length-1 num.length num num.length 1 i<j i j j-- j-- j {
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			} {
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			} if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				} num[j-1]>num[j] num[j-1] num j-1 j 1 num[j] num j {
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				} tmp = num[j] tmp num[j] num j num[j] = num[j-1] num[j] num j num[j-1] num j-1 j 1 num[j-1] = tmp num[j-1] num j-1 j 1 tmp cnt++ cnt return cnt; cnt int[] num num public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> lines = new ArrayList<String>();
		while (br.ready()){
			lines.add(br.readLine());
		}
		String[] tmp = lines.get(1).split(" ");
		int[] num = new int[tmp.length];
		for(int i=0; i<tmp.length; i++){
			num[i] = Integer.parseInt(tmp[i]);
		}
		int N= sort(num);
		print(num, N);


	}
	static void print(int[] num, int cnt){
		for(int i=0;i<num.length-1;i++){
			System.out.print(num[i]);
			System.out.print(" ");
		}
		System.out.println(num[num.length-1]);
		System.out.println(cnt);
	}
	static int sort(int[] num){
		int tmp;
		int cnt=0;
		for(int i=0; i<num.length;i++){
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		}
		return cnt;
		
	}
} public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> lines = new ArrayList<String>();
		while (br.ready()){
			lines.add(br.readLine());
		}
		String[] tmp = lines.get(1).split(" ");
		int[] num = new int[tmp.length];
		for(int i=0; i<tmp.length; i++){
			num[i] = Integer.parseInt(tmp[i]);
		}
		int N= sort(num);
		print(num, N);


	}
	static void print(int[] num, int cnt){
		for(int i=0;i<num.length-1;i++){
			System.out.print(num[i]);
			System.out.print(" ");
		}
		System.out.println(num[num.length-1]);
		System.out.println(cnt);
	}
	static int sort(int[] num){
		int tmp;
		int cnt=0;
		for(int i=0; i<num.length;i++){
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		}
		return cnt;
		
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> lines = new ArrayList<String>();
		while (br.ready()){
			lines.add(br.readLine());
		}
		String[] tmp = lines.get(1).split(" ");
		int[] num = new int[tmp.length];
		for(int i=0; i<tmp.length; i++){
			num[i] = Integer.parseInt(tmp[i]);
		}
		int N= sort(num);
		print(num, N);


	}
	static void print(int[] num, int cnt){
		for(int i=0;i<num.length-1;i++){
			System.out.print(num[i]);
			System.out.print(" ");
		}
		System.out.println(num[num.length-1]);
		System.out.println(cnt);
	}
	static int sort(int[] num){
		int tmp;
		int cnt=0;
		for(int i=0; i<num.length;i++){
			for(int j=num.length-1;i<j;j--){
				if(num[j-1]>num[j]){
					tmp = num[j];
					num[j] = num[j-1];
					num[j-1] = tmp;
					cnt++;
				}
			}
		}
		return cnt;
		
	}
}