
import java.io.*;
import java.util.*;

public class Main {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));    
    private static StringTokenizer st;

    public static void main ( String [] args ) throws IOException
    {
	new Main().cal();
    }

 
    private void cal() throws IOException 
    {
	int N = Integer.parseInt(br.readLine());
	int [] nums = new int[N];

	st = new StringTokenizer(br.readLine());
	for(int i = 0; i < N; i++)
	    nums[i] = Integer.parseInt(st.nextToken());

	int count = 0;
	for(int i = 0; i < nums.length; i++)
	    for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    }
	
	for(int i = 0; i < nums.length; i++){
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	}
	System.out.println("");
	    
	System.out.println(count);
    }

    private void swap(int [] nums, final int i, final int j) {
	int temp = nums[j];
	nums[j] = nums[i];
	nums[i] = temp;
    }

} import java.io.*; io.* java import java.util.*; util.* java public class Main {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));    
    private static StringTokenizer st;

    public static void main ( String [] args ) throws IOException
    {
	new Main().cal();
    }

 
    private void cal() throws IOException 
    {
	int N = Integer.parseInt(br.readLine());
	int [] nums = new int[N];

	st = new StringTokenizer(br.readLine());
	for(int i = 0; i < N; i++)
	    nums[i] = Integer.parseInt(st.nextToken());

	int count = 0;
	for(int i = 0; i < nums.length; i++)
	    for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    }
	
	for(int i = 0; i < nums.length; i++){
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	}
	System.out.println("");
	    
	System.out.println(count);
    }

    private void swap(int [] nums, final int i, final int j) {
	int temp = nums[j];
	nums[j] = nums[i];
	nums[i] = temp;
    }

} Main private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) private static StringTokenizer st; st public static void main ( String [] args ) throws IOException
    {
	new Main().cal();
    } main {
	new Main().cal();
    } new Main().cal() new Main().cal new Main() String [] args args private void cal() throws IOException 
    {
	int N = Integer.parseInt(br.readLine());
	int [] nums = new int[N];

	st = new StringTokenizer(br.readLine());
	for(int i = 0; i < N; i++)
	    nums[i] = Integer.parseInt(st.nextToken());

	int count = 0;
	for(int i = 0; i < nums.length; i++)
	    for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    }
	
	for(int i = 0; i < nums.length; i++){
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	}
	System.out.println("");
	    
	System.out.println(count);
    } cal {
	int N = Integer.parseInt(br.readLine());
	int [] nums = new int[N];

	st = new StringTokenizer(br.readLine());
	for(int i = 0; i < N; i++)
	    nums[i] = Integer.parseInt(st.nextToken());

	int count = 0;
	for(int i = 0; i < nums.length; i++)
	    for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    }
	
	for(int i = 0; i < nums.length; i++){
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	}
	System.out.println("");
	    
	System.out.println(count);
    } int N = Integer.parseInt(br.readLine()); N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int [] nums = new int[N]; nums new int[N] N st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) for(int i = 0; i < N; i++)
	    nums[i] = Integer.parseInt(st.nextToken()); int i = 0; int i = 0; i 0 i < N i N i++ i++ i nums[i] = Integer.parseInt(st.nextToken()); nums[i] = Integer.parseInt(st.nextToken()) nums[i] nums i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int count = 0; count 0 for(int i = 0; i < nums.length; i++)
	    for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    } int i = 0; int i = 0; i 0 i < nums.length i nums.length nums nums.length i++ i++ i for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    } for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    } int j = nums.length-1; int j = nums.length-1; j nums.length-1 nums.length nums nums.length 1 j > i j i j-- j-- j {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    } {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    } if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		} nums[j] < nums[j-1] nums[j] nums j nums[j-1] nums j-1 j 1 {
		    count++;
		    swap(nums, j, j-1);
		} count++ count swap(nums, j, j-1) swap nums j j-1 j 1 for(int i = 0; i < nums.length; i++){
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	} int i = 0; int i = 0; i 0 i < nums.length i nums.length nums nums.length i++ i++ i {
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	} {
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	} if ( i > 0 ) System.out.print(" "); i > 0 i 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(nums[i]) System.out.print System.out System System.out nums[i] nums i System.out.println("") System.out.println System.out System System.out "" System.out.println(count) System.out.println System.out System System.out count private void swap(int [] nums, final int i, final int j) {
	int temp = nums[j];
	nums[j] = nums[i];
	nums[i] = temp;
    } swap {
	int temp = nums[j];
	nums[j] = nums[i];
	nums[i] = temp;
    } int temp = nums[j]; temp nums[j] nums j nums[j] = nums[i] nums[j] nums j nums[i] nums i nums[i] = temp nums[i] nums i temp int [] nums nums final int i i final int j j public class Main {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));    
    private static StringTokenizer st;

    public static void main ( String [] args ) throws IOException
    {
	new Main().cal();
    }

 
    private void cal() throws IOException 
    {
	int N = Integer.parseInt(br.readLine());
	int [] nums = new int[N];

	st = new StringTokenizer(br.readLine());
	for(int i = 0; i < N; i++)
	    nums[i] = Integer.parseInt(st.nextToken());

	int count = 0;
	for(int i = 0; i < nums.length; i++)
	    for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    }
	
	for(int i = 0; i < nums.length; i++){
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	}
	System.out.println("");
	    
	System.out.println(count);
    }

    private void swap(int [] nums, final int i, final int j) {
	int temp = nums[j];
	nums[j] = nums[i];
	nums[i] = temp;
    }

} public class Main {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));    
    private static StringTokenizer st;

    public static void main ( String [] args ) throws IOException
    {
	new Main().cal();
    }

 
    private void cal() throws IOException 
    {
	int N = Integer.parseInt(br.readLine());
	int [] nums = new int[N];

	st = new StringTokenizer(br.readLine());
	for(int i = 0; i < N; i++)
	    nums[i] = Integer.parseInt(st.nextToken());

	int count = 0;
	for(int i = 0; i < nums.length; i++)
	    for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    }
	
	for(int i = 0; i < nums.length; i++){
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	}
	System.out.println("");
	    
	System.out.println(count);
    }

    private void swap(int [] nums, final int i, final int j) {
	int temp = nums[j];
	nums[j] = nums[i];
	nums[i] = temp;
    }

} Main

import java.io.*;
import java.util.*;

public class Main {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));    
    private static StringTokenizer st;

    public static void main ( String [] args ) throws IOException
    {
	new Main().cal();
    }

 
    private void cal() throws IOException 
    {
	int N = Integer.parseInt(br.readLine());
	int [] nums = new int[N];

	st = new StringTokenizer(br.readLine());
	for(int i = 0; i < N; i++)
	    nums[i] = Integer.parseInt(st.nextToken());

	int count = 0;
	for(int i = 0; i < nums.length; i++)
	    for( int j = nums.length-1; j > i; j--) {
		if ( nums[j] < nums[j-1] ) {
		    count++;
		    swap(nums, j, j-1);
		}

	    }
	
	for(int i = 0; i < nums.length; i++){
	    if ( i > 0 ) System.out.print(" ");
	    System.out.print(nums[i]);
	}
	System.out.println("");
	    
	System.out.println(count);
    }

    private void swap(int [] nums, final int i, final int j) {
	int temp = nums[j];
	nums[j] = nums[i];
	nums[i] = temp;
    }

}