import java.util.*;

public class Main{
    private int n, cnt, tmp;
    private int[] a;

    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	}
    }

    public static void main(String[] args){
	new Main();
    }
} import java.util.*; util.* java public class Main{
    private int n, cnt, tmp;
    private int[] a;

    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	}
    }

    public static void main(String[] args){
	new Main();
    }
} Main private int n n cnt cnt tmp; tmp private int[] a; a Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	}
    } Main {
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	}
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	} sc.hasNext() sc.hasNext sc {
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	} n = sc.nextInt() n sc.nextInt() sc.nextInt sc a = new int[n] a new int[n] n cnt = 0 cnt 0 for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n ++i ++i i a[i] = sc.nextInt(); a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    } int i = 0; int i = 0; i 0 i < n i n ++i ++i i for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    } for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    } 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]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    } if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    } a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    } tmp = a[j] tmp a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = tmp a[j-1] a j-1 j 1 tmp ++cnt cnt for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]); int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 ++i ++i i System.out.printf("%d ", a[i]); System.out.printf("%d ", a[i]) System.out.printf System.out System System.out "%d " a[i] a i System.out.println(a[n-1]) System.out.println System.out System System.out a[n-1] a n-1 n 1 System.out.printf("%d\n", cnt) System.out.printf System.out System System.out "%d\n" cnt public static void main(String[] args){
	new Main();
    } main {
	new Main();
    } new Main() String[] args args public class Main{
    private int n, cnt, tmp;
    private int[] a;

    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	}
    }

    public static void main(String[] args){
	new Main();
    }
} public class Main{
    private int n, cnt, tmp;
    private int[] a;

    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	}
    }

    public static void main(String[] args){
	new Main();
    }
} Main
import java.util.*;

public class Main{
    private int n, cnt, tmp;
    private int[] a;

    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    n = sc.nextInt();

	    a = new int[n];
	    cnt = 0;
	    for(int i = 0; i < n; ++i)
		a[i] = sc.nextInt();

	    for(int i = 0; i < n; ++i)
		for(int j = n-1; j > i; --j)
		    if(a[j] < a[j-1]){
			tmp = a[j];
			a[j] = a[j-1];
			a[j-1] = tmp;
			++cnt;
		    }

	    for(int i = 0; i < n-1; ++i)
		System.out.printf("%d ", a[i]);
	    System.out.println(a[n-1]);
	    System.out.printf("%d\n", cnt);
	}
    }

    public static void main(String[] args){
	new Main();
    }
}