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

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		int n = readInt(r);
		String[] numArrayStr = r.readLine().split(" ");

		int[] numArrayInt = convertToInt(numArrayStr);

		bubbleSort(numArrayInt);
	}

	public static void bubbleSort(int[] numArrayInt){
		int temp = 0;
		int count = 0;
		boolean flag = true;
		while(flag){
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		}
		printBlank(numArrayInt);
		System.out.println(count);
	}

	public static int readInt(BufferedReader r) throws Exception{
        return Integer.parseInt(r.readLine());
    }

	public static int[] convertToInt(String[] numArrayStr){
		int[] numArrayInt = new int[numArrayStr.length];
		for(int i = 0; i < numArrayStr.length; i++){
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		}
		return numArrayInt;
	}

	public static void printBlank(int[] numArrayInt){
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < numArrayInt.length; i++){
			builder.append(numArrayInt[i]);
			builder.append(" ");
		}

		System.out.println(builder.toString().trim());
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		int n = readInt(r);
		String[] numArrayStr = r.readLine().split(" ");

		int[] numArrayInt = convertToInt(numArrayStr);

		bubbleSort(numArrayInt);
	}

	public static void bubbleSort(int[] numArrayInt){
		int temp = 0;
		int count = 0;
		boolean flag = true;
		while(flag){
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		}
		printBlank(numArrayInt);
		System.out.println(count);
	}

	public static int readInt(BufferedReader r) throws Exception{
        return Integer.parseInt(r.readLine());
    }

	public static int[] convertToInt(String[] numArrayStr){
		int[] numArrayInt = new int[numArrayStr.length];
		for(int i = 0; i < numArrayStr.length; i++){
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		}
		return numArrayInt;
	}

	public static void printBlank(int[] numArrayInt){
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < numArrayInt.length; i++){
			builder.append(numArrayInt[i]);
			builder.append(" ");
		}

		System.out.println(builder.toString().trim());
	}

} Main public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		int n = readInt(r);
		String[] numArrayStr = r.readLine().split(" ");

		int[] numArrayInt = convertToInt(numArrayStr);

		bubbleSort(numArrayInt);
	} main {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		int n = readInt(r);
		String[] numArrayStr = r.readLine().split(" ");

		int[] numArrayInt = convertToInt(numArrayStr);

		bubbleSort(numArrayInt);
	} BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); r new BufferedReader(new InputStreamReader(System.in)) int n = readInt(r); n readInt(r) readInt r String[] numArrayStr = r.readLine().split(" "); numArrayStr r.readLine().split(" ") r.readLine().split r.readLine() r.readLine r " " int[] numArrayInt = convertToInt(numArrayStr); numArrayInt convertToInt(numArrayStr) convertToInt numArrayStr bubbleSort(numArrayInt) bubbleSort numArrayInt String[] args args public static void bubbleSort(int[] numArrayInt){
		int temp = 0;
		int count = 0;
		boolean flag = true;
		while(flag){
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		}
		printBlank(numArrayInt);
		System.out.println(count);
	} bubbleSort {
		int temp = 0;
		int count = 0;
		boolean flag = true;
		while(flag){
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		}
		printBlank(numArrayInt);
		System.out.println(count);
	} int temp = 0; temp 0 int count = 0; count 0 boolean flag = true; flag true while(flag){
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		} flag {
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		} flag = false flag false for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			} int i = numArrayInt.length - 1; int i = numArrayInt.length - 1; i numArrayInt.length - 1 numArrayInt.length numArrayInt numArrayInt.length 1 i > 0 i 0 i-- i-- i {
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			} {
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			} if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				} numArrayInt[i] < numArrayInt[i - 1] numArrayInt[i] numArrayInt i numArrayInt[i - 1] numArrayInt i - 1 i 1 {
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				} temp = numArrayInt[i] temp numArrayInt[i] numArrayInt i numArrayInt[i] = numArrayInt[i - 1] numArrayInt[i] numArrayInt i numArrayInt[i - 1] numArrayInt i - 1 i 1 numArrayInt[i - 1] = temp numArrayInt[i - 1] numArrayInt i - 1 i 1 temp flag = true flag true count++ count printBlank(numArrayInt) printBlank numArrayInt System.out.println(count) System.out.println System.out System System.out count int[] numArrayInt numArrayInt public static int readInt(BufferedReader r) throws Exception{
        return Integer.parseInt(r.readLine());
    } readInt {
        return Integer.parseInt(r.readLine());
    } return Integer.parseInt(r.readLine()); Integer.parseInt(r.readLine()) Integer.parseInt Integer r.readLine() r.readLine r BufferedReader r r public static int[] convertToInt(String[] numArrayStr){
		int[] numArrayInt = new int[numArrayStr.length];
		for(int i = 0; i < numArrayStr.length; i++){
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		}
		return numArrayInt;
	} convertToInt {
		int[] numArrayInt = new int[numArrayStr.length];
		for(int i = 0; i < numArrayStr.length; i++){
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		}
		return numArrayInt;
	} int[] numArrayInt = new int[numArrayStr.length]; numArrayInt new int[numArrayStr.length] numArrayStr.length numArrayStr numArrayStr.length for(int i = 0; i < numArrayStr.length; i++){
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		} int i = 0; int i = 0; i 0 i < numArrayStr.length i numArrayStr.length numArrayStr numArrayStr.length i++ i++ i {
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		} {
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		} numArrayInt[i] = Integer.parseInt(numArrayStr[i]) numArrayInt[i] numArrayInt i Integer.parseInt(numArrayStr[i]) Integer.parseInt Integer numArrayStr[i] numArrayStr i return numArrayInt; numArrayInt String[] numArrayStr numArrayStr public static void printBlank(int[] numArrayInt){
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < numArrayInt.length; i++){
			builder.append(numArrayInt[i]);
			builder.append(" ");
		}

		System.out.println(builder.toString().trim());
	} printBlank {
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < numArrayInt.length; i++){
			builder.append(numArrayInt[i]);
			builder.append(" ");
		}

		System.out.println(builder.toString().trim());
	} StringBuilder builder = new StringBuilder(); builder new StringBuilder() for(int i = 0; i < numArrayInt.length; i++){
			builder.append(numArrayInt[i]);
			builder.append(" ");
		} int i = 0; int i = 0; i 0 i < numArrayInt.length i numArrayInt.length numArrayInt numArrayInt.length i++ i++ i {
			builder.append(numArrayInt[i]);
			builder.append(" ");
		} {
			builder.append(numArrayInt[i]);
			builder.append(" ");
		} builder.append(numArrayInt[i]) builder.append builder numArrayInt[i] numArrayInt i builder.append(" ") builder.append builder " " System.out.println(builder.toString().trim()) System.out.println System.out System System.out builder.toString().trim() builder.toString().trim builder.toString() builder.toString builder int[] numArrayInt numArrayInt public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		int n = readInt(r);
		String[] numArrayStr = r.readLine().split(" ");

		int[] numArrayInt = convertToInt(numArrayStr);

		bubbleSort(numArrayInt);
	}

	public static void bubbleSort(int[] numArrayInt){
		int temp = 0;
		int count = 0;
		boolean flag = true;
		while(flag){
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		}
		printBlank(numArrayInt);
		System.out.println(count);
	}

	public static int readInt(BufferedReader r) throws Exception{
        return Integer.parseInt(r.readLine());
    }

	public static int[] convertToInt(String[] numArrayStr){
		int[] numArrayInt = new int[numArrayStr.length];
		for(int i = 0; i < numArrayStr.length; i++){
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		}
		return numArrayInt;
	}

	public static void printBlank(int[] numArrayInt){
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < numArrayInt.length; i++){
			builder.append(numArrayInt[i]);
			builder.append(" ");
		}

		System.out.println(builder.toString().trim());
	}

} public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		int n = readInt(r);
		String[] numArrayStr = r.readLine().split(" ");

		int[] numArrayInt = convertToInt(numArrayStr);

		bubbleSort(numArrayInt);
	}

	public static void bubbleSort(int[] numArrayInt){
		int temp = 0;
		int count = 0;
		boolean flag = true;
		while(flag){
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		}
		printBlank(numArrayInt);
		System.out.println(count);
	}

	public static int readInt(BufferedReader r) throws Exception{
        return Integer.parseInt(r.readLine());
    }

	public static int[] convertToInt(String[] numArrayStr){
		int[] numArrayInt = new int[numArrayStr.length];
		for(int i = 0; i < numArrayStr.length; i++){
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		}
		return numArrayInt;
	}

	public static void printBlank(int[] numArrayInt){
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < numArrayInt.length; i++){
			builder.append(numArrayInt[i]);
			builder.append(" ");
		}

		System.out.println(builder.toString().trim());
	}

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

		int n = readInt(r);
		String[] numArrayStr = r.readLine().split(" ");

		int[] numArrayInt = convertToInt(numArrayStr);

		bubbleSort(numArrayInt);
	}

	public static void bubbleSort(int[] numArrayInt){
		int temp = 0;
		int count = 0;
		boolean flag = true;
		while(flag){
			flag = false;
			for(int i = numArrayInt.length - 1; i > 0; i--){
				if(numArrayInt[i] < numArrayInt[i - 1]){
					temp = numArrayInt[i];
					numArrayInt[i] = numArrayInt[i - 1];
					numArrayInt[i - 1] = temp;
					flag = true;
					count++;
				}
			}
		}
		printBlank(numArrayInt);
		System.out.println(count);
	}

	public static int readInt(BufferedReader r) throws Exception{
        return Integer.parseInt(r.readLine());
    }

	public static int[] convertToInt(String[] numArrayStr){
		int[] numArrayInt = new int[numArrayStr.length];
		for(int i = 0; i < numArrayStr.length; i++){
			numArrayInt[i] = Integer.parseInt(numArrayStr[i]);
		}
		return numArrayInt;
	}

	public static void printBlank(int[] numArrayInt){
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < numArrayInt.length; i++){
			builder.append(numArrayInt[i]);
			builder.append(" ");
		}

		System.out.println(builder.toString().trim());
	}

}