import java.util.Arrays;

public class Main {
    // field

    // method
    public static void main(String[] args) {
	//System.out.print("> ");
	java.util.Scanner scan = new java.util.Scanner(System.in);
	int arraySize = scan.nextInt();
	String[] input = new String[arraySize];
	int[] array = new int[arraySize];
	//System.out.print("> ");
	for (int i = 0; i < arraySize; i++){
	    array[i] = scan.nextInt();
	}
	
	BubbleSort bs = new BubbleSort(array.clone()); // バブルソート
	bs.bubbleSort(); // ソート
	bs.display();    // 表示
	System.out.println(bs.getCount());
    }
}
class BubbleSort {
    // -- field
    private int[] sort_array;
    protected int Count;
    
    
    // -- Constructor
    private BubbleSort() {}
    public BubbleSort(int[] sort_array) {
	this.sort_array = sort_array;
    }
    
    // -- Method
    public void display() {
	for (int i = 0; i < this.sort_array.length; i++) {
	    System.out.print(this.sort_array[i]);
	    if(i == this.sort_array.length-1) {
		break;
	    }
	    System.out.print(" ");
	}
	System.out.println();
    }

    public void swap(int x, int y) {
	int temp = this.sort_array[x];
	this.sort_array[x] = this.sort_array[y];
	this.sort_array[y] = temp;
    }

    public void bubbleSort() {
	for (int i = this.sort_array.length - 1; i > 0; i--) {
	    for (int j = 0; j < i; j++) {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    }
	}
    }

    public int getCount() {
    return this.Count;
    }
}
 import java.util.Arrays; Arrays java.util public class Main {
    // field

    // method
    public static void main(String[] args) {
	//System.out.print("> ");
	java.util.Scanner scan = new java.util.Scanner(System.in);
	int arraySize = scan.nextInt();
	String[] input = new String[arraySize];
	int[] array = new int[arraySize];
	//System.out.print("> ");
	for (int i = 0; i < arraySize; i++){
	    array[i] = scan.nextInt();
	}
	
	BubbleSort bs = new BubbleSort(array.clone()); // バブルソート
	bs.bubbleSort(); // ソート
	bs.display();    // 表示
	System.out.println(bs.getCount());
    }
} Main // method
    public static void main(String[] args) {
	//System.out.print("> ");
	java.util.Scanner scan = new java.util.Scanner(System.in);
	int arraySize = scan.nextInt();
	String[] input = new String[arraySize];
	int[] array = new int[arraySize];
	//System.out.print("> ");
	for (int i = 0; i < arraySize; i++){
	    array[i] = scan.nextInt();
	}
	
	BubbleSort bs = new BubbleSort(array.clone()); // バブルソート
	bs.bubbleSort(); // ソート
	bs.display();    // 表示
	System.out.println(bs.getCount());
    } main {
	//System.out.print("> ");
	java.util.Scanner scan = new java.util.Scanner(System.in);
	int arraySize = scan.nextInt();
	String[] input = new String[arraySize];
	int[] array = new int[arraySize];
	//System.out.print("> ");
	for (int i = 0; i < arraySize; i++){
	    array[i] = scan.nextInt();
	}
	
	BubbleSort bs = new BubbleSort(array.clone()); // バブルソート
	bs.bubbleSort(); // ソート
	bs.display();    // 表示
	System.out.println(bs.getCount());
    } java.util.Scanner scan = new java.util.Scanner(System.in); scan new java.util.Scanner(System.in) int arraySize = scan.nextInt(); arraySize scan.nextInt() scan.nextInt scan String[] input = new String[arraySize]; input new String[arraySize] arraySize int[] array = new int[arraySize]; array new int[arraySize] arraySize for (int i = 0; i < arraySize; i++){
	    array[i] = scan.nextInt();
	} int i = 0; int i = 0; i 0 i < arraySize i arraySize i++ i++ i {
	    array[i] = scan.nextInt();
	} {
	    array[i] = scan.nextInt();
	} array[i] = scan.nextInt() array[i] array i scan.nextInt() scan.nextInt scan BubbleSort bs = new BubbleSort(array.clone()); bs new BubbleSort(array.clone()) bs.bubbleSort() bs.bubbleSort bs bs.display() bs.display bs System.out.println(bs.getCount()) System.out.println System.out System System.out bs.getCount() bs.getCount bs String[] args args class BubbleSort {
    // -- field
    private int[] sort_array;
    protected int Count;
    
    
    // -- Constructor
    private BubbleSort() {}
    public BubbleSort(int[] sort_array) {
	this.sort_array = sort_array;
    }
    
    // -- Method
    public void display() {
	for (int i = 0; i < this.sort_array.length; i++) {
	    System.out.print(this.sort_array[i]);
	    if(i == this.sort_array.length-1) {
		break;
	    }
	    System.out.print(" ");
	}
	System.out.println();
    }

    public void swap(int x, int y) {
	int temp = this.sort_array[x];
	this.sort_array[x] = this.sort_array[y];
	this.sort_array[y] = temp;
    }

    public void bubbleSort() {
	for (int i = this.sort_array.length - 1; i > 0; i--) {
	    for (int j = 0; j < i; j++) {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    }
	}
    }

    public int getCount() {
    return this.Count;
    }
} BubbleSort // -- field
    private int[] sort_array; sort_array protected int Count; Count // -- Constructor
    private BubbleSort() {} BubbleSort {} public BubbleSort(int[] sort_array) {
	this.sort_array = sort_array;
    } BubbleSort {
	this.sort_array = sort_array;
    } this.sort_array = sort_array this.sort_array this this.sort_array sort_array int[] sort_array sort_array // -- Method
    public void display() {
	for (int i = 0; i < this.sort_array.length; i++) {
	    System.out.print(this.sort_array[i]);
	    if(i == this.sort_array.length-1) {
		break;
	    }
	    System.out.print(" ");
	}
	System.out.println();
    } display {
	for (int i = 0; i < this.sort_array.length; i++) {
	    System.out.print(this.sort_array[i]);
	    if(i == this.sort_array.length-1) {
		break;
	    }
	    System.out.print(" ");
	}
	System.out.println();
    } for (int i = 0; i < this.sort_array.length; i++) {
	    System.out.print(this.sort_array[i]);
	    if(i == this.sort_array.length-1) {
		break;
	    }
	    System.out.print(" ");
	} int i = 0; int i = 0; i 0 i < this.sort_array.length i this.sort_array.length this.sort_array this this.sort_array this.sort_array.length i++ i++ i {
	    System.out.print(this.sort_array[i]);
	    if(i == this.sort_array.length-1) {
		break;
	    }
	    System.out.print(" ");
	} {
	    System.out.print(this.sort_array[i]);
	    if(i == this.sort_array.length-1) {
		break;
	    }
	    System.out.print(" ");
	} System.out.print(this.sort_array[i]) System.out.print System.out System System.out this.sort_array[i] this.sort_array this this.sort_array i if(i == this.sort_array.length-1) {
		break;
	    } i == this.sort_array.length-1 i this.sort_array.length-1 this.sort_array.length this.sort_array this this.sort_array this.sort_array.length 1 {
		break;
	    } break; System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out public void swap(int x, int y) {
	int temp = this.sort_array[x];
	this.sort_array[x] = this.sort_array[y];
	this.sort_array[y] = temp;
    } swap {
	int temp = this.sort_array[x];
	this.sort_array[x] = this.sort_array[y];
	this.sort_array[y] = temp;
    } int temp = this.sort_array[x]; temp this.sort_array[x] this.sort_array this this.sort_array x this.sort_array[x] = this.sort_array[y] this.sort_array[x] this.sort_array this this.sort_array x this.sort_array[y] this.sort_array this this.sort_array y this.sort_array[y] = temp this.sort_array[y] this.sort_array this this.sort_array y temp int x x int y y public void bubbleSort() {
	for (int i = this.sort_array.length - 1; i > 0; i--) {
	    for (int j = 0; j < i; j++) {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    }
	}
    } bubbleSort {
	for (int i = this.sort_array.length - 1; i > 0; i--) {
	    for (int j = 0; j < i; j++) {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    }
	}
    } for (int i = this.sort_array.length - 1; i > 0; i--) {
	    for (int j = 0; j < i; j++) {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    }
	} int i = this.sort_array.length - 1; int i = this.sort_array.length - 1; i this.sort_array.length - 1 this.sort_array.length this.sort_array this this.sort_array this.sort_array.length 1 i > 0 i 0 i-- i-- i {
	    for (int j = 0; j < i; j++) {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    }
	} {
	    for (int j = 0; j < i; j++) {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    }
	} for (int j = 0; j < i; j++) {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    } int j = 0; int j = 0; j 0 j < i j i j++ j++ j {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    } {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    } if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		} this.sort_array[j] > this.sort_array[j + 1] this.sort_array[j] this.sort_array this this.sort_array j this.sort_array[j + 1] this.sort_array this this.sort_array j + 1 j 1 {
		    swap(j, j + 1);
		    this.Count++;
		} swap(j, j + 1) swap j j + 1 j 1 this.Count++ this.Count this this.Count public int getCount() {
    return this.Count;
    } getCount {
    return this.Count;
    } return this.Count; this.Count this this.Count public class Main {
    // field

    // method
    public static void main(String[] args) {
	//System.out.print("> ");
	java.util.Scanner scan = new java.util.Scanner(System.in);
	int arraySize = scan.nextInt();
	String[] input = new String[arraySize];
	int[] array = new int[arraySize];
	//System.out.print("> ");
	for (int i = 0; i < arraySize; i++){
	    array[i] = scan.nextInt();
	}
	
	BubbleSort bs = new BubbleSort(array.clone()); // バブルソート
	bs.bubbleSort(); // ソート
	bs.display();    // 表示
	System.out.println(bs.getCount());
    }
} public class Main {
    // field

    // method
    public static void main(String[] args) {
	//System.out.print("> ");
	java.util.Scanner scan = new java.util.Scanner(System.in);
	int arraySize = scan.nextInt();
	String[] input = new String[arraySize];
	int[] array = new int[arraySize];
	//System.out.print("> ");
	for (int i = 0; i < arraySize; i++){
	    array[i] = scan.nextInt();
	}
	
	BubbleSort bs = new BubbleSort(array.clone()); // バブルソート
	bs.bubbleSort(); // ソート
	bs.display();    // 表示
	System.out.println(bs.getCount());
    }
} Main
import java.util.Arrays;

public class Main {
    // field

    // method
    public static void main(String[] args) {
	//System.out.print("> ");
	java.util.Scanner scan = new java.util.Scanner(System.in);
	int arraySize = scan.nextInt();
	String[] input = new String[arraySize];
	int[] array = new int[arraySize];
	//System.out.print("> ");
	for (int i = 0; i < arraySize; i++){
	    array[i] = scan.nextInt();
	}
	
	BubbleSort bs = new BubbleSort(array.clone()); // バブルソート
	bs.bubbleSort(); // ソート
	bs.display();    // 表示
	System.out.println(bs.getCount());
    }
}
class BubbleSort {
    // -- field
    private int[] sort_array;
    protected int Count;
    
    
    // -- Constructor
    private BubbleSort() {}
    public BubbleSort(int[] sort_array) {
	this.sort_array = sort_array;
    }
    
    // -- Method
    public void display() {
	for (int i = 0; i < this.sort_array.length; i++) {
	    System.out.print(this.sort_array[i]);
	    if(i == this.sort_array.length-1) {
		break;
	    }
	    System.out.print(" ");
	}
	System.out.println();
    }

    public void swap(int x, int y) {
	int temp = this.sort_array[x];
	this.sort_array[x] = this.sort_array[y];
	this.sort_array[y] = temp;
    }

    public void bubbleSort() {
	for (int i = this.sort_array.length - 1; i > 0; i--) {
	    for (int j = 0; j < i; j++) {
		if (this.sort_array[j] > this.sort_array[j + 1]) {
		    swap(j, j + 1);
		    this.Count++;
		}
	    }
	}
    }

    public int getCount() {
    return this.Count;
    }
}

