import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
	Scanner stdin = new Scanner(System.in);
	int n = stdin.nextInt();
	int[] num = new int[100];
	int cnt = 0;

	for ( int i = 0; i < n; i++ ){
	    num[i] = stdin.nextInt();
	}

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

	System.out.print(num[0]);
	for ( int i = 1; i < n; i++ ){
	    System.out.print(" " + num[i]);
	}
	System.out.println();
	System.out.println(cnt);

    }
} import java.util.Scanner; Scanner java.util import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
	Scanner stdin = new Scanner(System.in);
	int n = stdin.nextInt();
	int[] num = new int[100];
	int cnt = 0;

	for ( int i = 0; i < n; i++ ){
	    num[i] = stdin.nextInt();
	}

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

	System.out.print(num[0]);
	for ( int i = 1; i < n; i++ ){
	    System.out.print(" " + num[i]);
	}
	System.out.println();
	System.out.println(cnt);

    }
} Main public static void main(String[] args) {
	Scanner stdin = new Scanner(System.in);
	int n = stdin.nextInt();
	int[] num = new int[100];
	int cnt = 0;

	for ( int i = 0; i < n; i++ ){
	    num[i] = stdin.nextInt();
	}

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

	System.out.print(num[0]);
	for ( int i = 1; i < n; i++ ){
	    System.out.print(" " + num[i]);
	}
	System.out.println();
	System.out.println(cnt);

    } main {
	Scanner stdin = new Scanner(System.in);
	int n = stdin.nextInt();
	int[] num = new int[100];
	int cnt = 0;

	for ( int i = 0; i < n; i++ ){
	    num[i] = stdin.nextInt();
	}

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

	System.out.print(num[0]);
	for ( int i = 1; i < n; i++ ){
	    System.out.print(" " + num[i]);
	}
	System.out.println();
	System.out.println(cnt);

    } Scanner stdin = new Scanner(System.in); stdin new Scanner(System.in) int n = stdin.nextInt(); n stdin.nextInt() stdin.nextInt stdin int[] num = new int[100]; num new int[100] 100 int cnt = 0; cnt 0 for ( int i = 0; i < n; i++ ){
	    num[i] = stdin.nextInt();
	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	    num[i] = stdin.nextInt();
	} {
	    num[i] = stdin.nextInt();
	} num[i] = stdin.nextInt() num[i] num i stdin.nextInt() stdin.nextInt stdin int flag = 1; flag 1 while ( flag == 1 ){
	    flag = 0;
	    for ( int j = n-1; j > 0; j-- ){
		if ( num[j] < num[j-1] ){
		    int tmp = num[j];
		    num[j] = num[j-1];
		    num[j-1] = tmp;
		    flag = 1;
		    cnt++;
		}
	    }
	} flag == 1 flag 1 {
	    flag = 0;
	    for ( int j = n-1; j > 0; j-- ){
		if ( num[j] < num[j-1] ){
		    int tmp = num[j];
		    num[j] = num[j-1];
		    num[j-1] = tmp;
		    flag = 1;
		    cnt++;
		}
	    }
	} flag = 0 flag 0 for ( int j = n-1; j > 0; j-- ){
		if ( num[j] < num[j-1] ){
		    int tmp = num[j];
		    num[j] = num[j-1];
		    num[j-1] = tmp;
		    flag = 1;
		    cnt++;
		}
	    } int j = n-1; int j = n-1; j n-1 n 1 j > 0 j 0 j-- j-- j {
		if ( num[j] < num[j-1] ){
		    int tmp = num[j];
		    num[j] = num[j-1];
		    num[j-1] = tmp;
		    flag = 1;
		    cnt++;
		}
	    } {
		if ( num[j] < num[j-1] ){
		    int tmp = num[j];
		    num[j] = num[j-1];
		    num[j-1] = tmp;
		    flag = 1;
		    cnt++;
		}
	    } if ( num[j] < num[j-1] ){
		    int tmp = num[j];
		    num[j] = num[j-1];
		    num[j-1] = tmp;
		    flag = 1;
		    cnt++;
		} num[j] < num[j-1] num[j] num j num[j-1] num j-1 j 1 {
		    int tmp = num[j];
		    num[j] = num[j-1];
		    num[j-1] = tmp;
		    flag = 1;
		    cnt++;
		} int 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 flag = 1 flag 1 cnt++ cnt System.out.print(num[0]) System.out.print System.out System System.out num[0] num 0 for ( int i = 1; i < n; i++ ){
	    System.out.print(" " + num[i]);
	} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
	    System.out.print(" " + num[i]);
	} {
	    System.out.print(" " + num[i]);
	} System.out.print(" " + num[i]) System.out.print System.out System System.out " " + num[i] " " num[i] num i System.out.println() System.out.println System.out System System.out 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 stdin = new Scanner(System.in);
	int n = stdin.nextInt();
	int[] num = new int[100];
	int cnt = 0;

	for ( int i = 0; i < n; i++ ){
	    num[i] = stdin.nextInt();
	}

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

	System.out.print(num[0]);
	for ( int i = 1; i < n; i++ ){
	    System.out.print(" " + num[i]);
	}
	System.out.println();
	System.out.println(cnt);

    }
} public class Main {
    public static void main(String[] args) {
	Scanner stdin = new Scanner(System.in);
	int n = stdin.nextInt();
	int[] num = new int[100];
	int cnt = 0;

	for ( int i = 0; i < n; i++ ){
	    num[i] = stdin.nextInt();
	}

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

	System.out.print(num[0]);
	for ( int i = 1; i < n; i++ ){
	    System.out.print(" " + num[i]);
	}
	System.out.println();
	System.out.println(cnt);

    }
} Main
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
	Scanner stdin = new Scanner(System.in);
	int n = stdin.nextInt();
	int[] num = new int[100];
	int cnt = 0;

	for ( int i = 0; i < n; i++ ){
	    num[i] = stdin.nextInt();
	}

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

	System.out.print(num[0]);
	for ( int i = 1; i < n; i++ ){
	    System.out.print(" " + num[i]);
	}
	System.out.println();
	System.out.println(cnt);

    }
}