import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i,j,N,tmp,cnt;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
	
		int [] A = new int [N];
		
		for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		}
		cnt =0;
		for(i=0;i<N-1;i++){
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		}
		System.out.print(A[0]);
		for(int r=1; r<N; r++){
			System.out.print(" "+A[r]);
		}
		System.out.println("\r\n"+cnt);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i,j,N,tmp,cnt;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
	
		int [] A = new int [N];
		
		for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		}
		cnt =0;
		for(i=0;i<N-1;i++){
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		}
		System.out.print(A[0]);
		for(int r=1; r<N; r++){
			System.out.print(" "+A[r]);
		}
		System.out.println("\r\n"+cnt);

	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i,j,N,tmp,cnt;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
	
		int [] A = new int [N];
		
		for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		}
		cnt =0;
		for(i=0;i<N-1;i++){
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		}
		System.out.print(A[0]);
		for(int r=1; r<N; r++){
			System.out.print(" "+A[r]);
		}
		System.out.println("\r\n"+cnt);

	} main {
		// TODO Auto-generated method stub
		int i,j,N,tmp,cnt;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
	
		int [] A = new int [N];
		
		for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		}
		cnt =0;
		for(i=0;i<N-1;i++){
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		}
		System.out.print(A[0]);
		for(int r=1; r<N; r++){
			System.out.print(" "+A[r]);
		}
		System.out.println("\r\n"+cnt);

	} int i i j j N N tmp tmp cnt; cnt Scanner sc = new Scanner(System.in); sc new Scanner(System.in) N = sc.nextInt() N sc.nextInt() sc.nextInt sc int [] A = new int [N]; A new int [N] N for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		} i=0; i=0 i 0 i<N i N i++ i++ i {
			A[i] =sc.nextInt();
		} {
			A[i] =sc.nextInt();
		} A[i] =sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc cnt =0 cnt 0 for(i=0;i<N-1;i++){
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		} i=0; i=0 i 0 i<N-1 i N-1 N 1 i++ i++ i {
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		} {
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		} for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			} j=0; j=0 j 0 j<N-(i+1) j N-(i+1) N (i+1) i 1 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++;
				}
			} 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 System.out.print(A[0]) System.out.print System.out System System.out A[0] A 0 for(int r=1; r<N; r++){
			System.out.print(" "+A[r]);
		} int r=1; int r=1; r 1 r<N r N r++ r++ r {
			System.out.print(" "+A[r]);
		} {
			System.out.print(" "+A[r]);
		} System.out.print(" "+A[r]) System.out.print System.out System System.out " "+A[r] " " A[r] A r System.out.println("\r\n"+cnt) System.out.println System.out System System.out "\r\n"+cnt "\r\n" cnt String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i,j,N,tmp,cnt;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
	
		int [] A = new int [N];
		
		for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		}
		cnt =0;
		for(i=0;i<N-1;i++){
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		}
		System.out.print(A[0]);
		for(int r=1; r<N; r++){
			System.out.print(" "+A[r]);
		}
		System.out.println("\r\n"+cnt);

	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i,j,N,tmp,cnt;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
	
		int [] A = new int [N];
		
		for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		}
		cnt =0;
		for(i=0;i<N-1;i++){
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		}
		System.out.print(A[0]);
		for(int r=1; r<N; r++){
			System.out.print(" "+A[r]);
		}
		System.out.println("\r\n"+cnt);

	}

} Main
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int i,j,N,tmp,cnt;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
	
		int [] A = new int [N];
		
		for(i=0; i<N; i++){
			A[i] =sc.nextInt();
		}
		cnt =0;
		for(i=0;i<N-1;i++){
			for(j=0;j<N-(i+1);j++){
				if(A[j] > A[j+1]){
					tmp  = A[j];
					A[j] = A[j+1];
					A[j+1] = tmp;
					cnt++;
				}
			}
		}
		System.out.print(A[0]);
		for(int r=1; r<N; r++){
			System.out.print(" "+A[r]);
		}
		System.out.println("\r\n"+cnt);

	}

}
