import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String[] input = scan.nextLine().split(" ");
	int[] elements = new int[n];
	for (int i = 0; i < n; i++) {
	    elements[i] = Integer.parseInt(input[i]);
	}
	int cnt = 0;
	boolean flag = true;
	while (flag) {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	}
        for (int i = 0; i < n-1; i++){
	    System.out.print(elements[i] + " ");
	}
	System.out.println(elements[n-1]);
	System.out.println(cnt);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String[] input = scan.nextLine().split(" ");
	int[] elements = new int[n];
	for (int i = 0; i < n; i++) {
	    elements[i] = Integer.parseInt(input[i]);
	}
	int cnt = 0;
	boolean flag = true;
	while (flag) {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	}
        for (int i = 0; i < n-1; i++){
	    System.out.print(elements[i] + " ");
	}
	System.out.println(elements[n-1]);
	System.out.println(cnt);
    }
} Main public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String[] input = scan.nextLine().split(" ");
	int[] elements = new int[n];
	for (int i = 0; i < n; i++) {
	    elements[i] = Integer.parseInt(input[i]);
	}
	int cnt = 0;
	boolean flag = true;
	while (flag) {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	}
        for (int i = 0; i < n-1; i++){
	    System.out.print(elements[i] + " ");
	}
	System.out.println(elements[n-1]);
	System.out.println(cnt);
    } main {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String[] input = scan.nextLine().split(" ");
	int[] elements = new int[n];
	for (int i = 0; i < n; i++) {
	    elements[i] = Integer.parseInt(input[i]);
	}
	int cnt = 0;
	boolean flag = true;
	while (flag) {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	}
        for (int i = 0; i < n-1; i++){
	    System.out.print(elements[i] + " ");
	}
	System.out.println(elements[n-1]);
	System.out.println(cnt);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = Integer.parseInt(scan.nextLine()); n Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan String[] input = scan.nextLine().split(" "); input scan.nextLine().split(" ") scan.nextLine().split scan.nextLine() scan.nextLine scan " " int[] elements = new int[n]; elements new int[n] n for (int i = 0; i < n; i++) {
	    elements[i] = Integer.parseInt(input[i]);
	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	    elements[i] = Integer.parseInt(input[i]);
	} {
	    elements[i] = Integer.parseInt(input[i]);
	} elements[i] = Integer.parseInt(input[i]) elements[i] elements i Integer.parseInt(input[i]) Integer.parseInt Integer input[i] input i int cnt = 0; cnt 0 boolean flag = true; flag true while (flag) {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	} flag {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	} flag = false flag false for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    } int i = n-1; int i = n-1; i n-1 n 1 i > 0 i 0 i-- i-- i {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    } {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    } if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		} elements[i] < elements[i-1] elements[i] elements i elements[i-1] elements i-1 i 1 {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		} int tmp = elements[i]; tmp elements[i] elements i elements[i] = elements[i-1] elements[i] elements i elements[i-1] elements i-1 i 1 elements[i-1] = tmp elements[i-1] elements i-1 i 1 tmp cnt++ cnt flag = true flag true for (int i = 0; i < n-1; i++){
	    System.out.print(elements[i] + " ");
	} int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
	    System.out.print(elements[i] + " ");
	} {
	    System.out.print(elements[i] + " ");
	} System.out.print(elements[i] + " ") System.out.print System.out System System.out elements[i] + " " elements[i] elements i " " System.out.println(elements[n-1]) System.out.println System.out System System.out elements[n-1] elements n-1 n 1 System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String[] input = scan.nextLine().split(" ");
	int[] elements = new int[n];
	for (int i = 0; i < n; i++) {
	    elements[i] = Integer.parseInt(input[i]);
	}
	int cnt = 0;
	boolean flag = true;
	while (flag) {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	}
        for (int i = 0; i < n-1; i++){
	    System.out.print(elements[i] + " ");
	}
	System.out.println(elements[n-1]);
	System.out.println(cnt);
    }
} public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String[] input = scan.nextLine().split(" ");
	int[] elements = new int[n];
	for (int i = 0; i < n; i++) {
	    elements[i] = Integer.parseInt(input[i]);
	}
	int cnt = 0;
	boolean flag = true;
	while (flag) {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	}
        for (int i = 0; i < n-1; i++){
	    System.out.print(elements[i] + " ");
	}
	System.out.println(elements[n-1]);
	System.out.println(cnt);
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String[] input = scan.nextLine().split(" ");
	int[] elements = new int[n];
	for (int i = 0; i < n; i++) {
	    elements[i] = Integer.parseInt(input[i]);
	}
	int cnt = 0;
	boolean flag = true;
	while (flag) {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	}
        for (int i = 0; i < n-1; i++){
	    System.out.print(elements[i] + " ");
	}
	System.out.println(elements[n-1]);
	System.out.println(cnt);
    }
}