import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int N = 0;
		int tre = 0;
		int count = 0;
		int A[];
		
		Boolean flag = true;
		
		N = Integer.parseInt(as.next());
		
		A = new int[N];
		
		for(int i=0;i<N;i++){
			
			A[i] = Integer.parseInt(as.next());
			
		}
		
		while(flag){
			
			flag = false;
			for(int j=N-1;j>=1;j--){
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			}
			
		}
		
		for(int i=0;i<N;i++){
			
			if(i != N-1){
				
				sb.append(A[i]).append(' ');
			
			}
			else{
				
				sb.append(A[i]);
				
			}
		}
		System.out.println(sb.toString());
		sb.setLength(0);
		sb.append(count);
		System.out.println(sb.toString());

	}

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

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int N = 0;
		int tre = 0;
		int count = 0;
		int A[];
		
		Boolean flag = true;
		
		N = Integer.parseInt(as.next());
		
		A = new int[N];
		
		for(int i=0;i<N;i++){
			
			A[i] = Integer.parseInt(as.next());
			
		}
		
		while(flag){
			
			flag = false;
			for(int j=N-1;j>=1;j--){
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			}
			
		}
		
		for(int i=0;i<N;i++){
			
			if(i != N-1){
				
				sb.append(A[i]).append(' ');
			
			}
			else{
				
				sb.append(A[i]);
				
			}
		}
		System.out.println(sb.toString());
		sb.setLength(0);
		sb.append(count);
		System.out.println(sb.toString());

	}

} Main /**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int N = 0;
		int tre = 0;
		int count = 0;
		int A[];
		
		Boolean flag = true;
		
		N = Integer.parseInt(as.next());
		
		A = new int[N];
		
		for(int i=0;i<N;i++){
			
			A[i] = Integer.parseInt(as.next());
			
		}
		
		while(flag){
			
			flag = false;
			for(int j=N-1;j>=1;j--){
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			}
			
		}
		
		for(int i=0;i<N;i++){
			
			if(i != N-1){
				
				sb.append(A[i]).append(' ');
			
			}
			else{
				
				sb.append(A[i]);
				
			}
		}
		System.out.println(sb.toString());
		sb.setLength(0);
		sb.append(count);
		System.out.println(sb.toString());

	} main {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int N = 0;
		int tre = 0;
		int count = 0;
		int A[];
		
		Boolean flag = true;
		
		N = Integer.parseInt(as.next());
		
		A = new int[N];
		
		for(int i=0;i<N;i++){
			
			A[i] = Integer.parseInt(as.next());
			
		}
		
		while(flag){
			
			flag = false;
			for(int j=N-1;j>=1;j--){
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			}
			
		}
		
		for(int i=0;i<N;i++){
			
			if(i != N-1){
				
				sb.append(A[i]).append(' ');
			
			}
			else{
				
				sb.append(A[i]);
				
			}
		}
		System.out.println(sb.toString());
		sb.setLength(0);
		sb.append(count);
		System.out.println(sb.toString());

	} StringBuilder sb = new StringBuilder(); sb new StringBuilder() Scanner as = new Scanner(System.in); as new Scanner(System.in) int N = 0; N 0 int tre = 0; tre 0 int count = 0; count 0 int A[]; A Boolean flag = true; flag true N = Integer.parseInt(as.next()) N Integer.parseInt(as.next()) Integer.parseInt Integer as.next() as.next as A = new int[N] A new int[N] N for(int i=0;i<N;i++){
			
			A[i] = Integer.parseInt(as.next());
			
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			
			A[i] = Integer.parseInt(as.next());
			
		} {
			
			A[i] = Integer.parseInt(as.next());
			
		} A[i] = Integer.parseInt(as.next()) A[i] A i Integer.parseInt(as.next()) Integer.parseInt Integer as.next() as.next as while(flag){
			
			flag = false;
			for(int j=N-1;j>=1;j--){
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			}
			
		} flag {
			
			flag = false;
			for(int j=N-1;j>=1;j--){
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			}
			
		} flag = false flag false for(int j=N-1;j>=1;j--){
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			} int j=N-1; int j=N-1; j N-1 N 1 j>=1 j 1 j-- j-- j {
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			} {
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			} if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				} A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				} tre = A[j] tre A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = tre A[j-1] A j-1 j 1 tre flag = true flag true count++ count for(int i=0;i<N;i++){
			
			if(i != N-1){
				
				sb.append(A[i]).append(' ');
			
			}
			else{
				
				sb.append(A[i]);
				
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			
			if(i != N-1){
				
				sb.append(A[i]).append(' ');
			
			}
			else{
				
				sb.append(A[i]);
				
			}
		} {
			
			if(i != N-1){
				
				sb.append(A[i]).append(' ');
			
			}
			else{
				
				sb.append(A[i]);
				
			}
		} if(i != N-1){
				
				sb.append(A[i]).append(' ');
			
			}
			else{
				
				sb.append(A[i]);
				
			} i != N-1 i N-1 N 1 {
				
				sb.append(A[i]).append(' ');
			
			} sb.append(A[i]).append(' ') sb.append(A[i]).append sb.append(A[i]) sb.append sb A[i] A i ' ' {
				
				sb.append(A[i]);
				
			} sb.append(A[i]) sb.append sb A[i] A i System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb sb.setLength(0) sb.setLength sb 0 sb.append(count) sb.append sb count System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args
import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int N = 0;
		int tre = 0;
		int count = 0;
		int A[];
		
		Boolean flag = true;
		
		N = Integer.parseInt(as.next());
		
		A = new int[N];
		
		for(int i=0;i<N;i++){
			
			A[i] = Integer.parseInt(as.next());
			
		}
		
		while(flag){
			
			flag = false;
			for(int j=N-1;j>=1;j--){
				
				if(A[j] < A[j-1]){
					
					tre = A[j];
					A[j] = A[j-1];
					A[j-1] = tre;
					flag = true;
					count++;
					
				}
				
			}
			
		}
		
		for(int i=0;i<N;i++){
			
			if(i != N-1){
				
				sb.append(A[i]).append(' ');
			
			}
			else{
				
				sb.append(A[i]);
				
			}
		}
		System.out.println(sb.toString());
		sb.setLength(0);
		sb.append(count);
		System.out.println(sb.toString());

	}

}