import java.util.Scanner;

class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int A[] = new int[N];
	for(int i = 0;i < N;i++){
	    A[i] = sc.nextInt();
	}
	int flag = 1;
	int tmp, time = 0;
	while(flag == 1){
	    flag = 0;
	    for(int j = N - 1;j >= 1;j--){
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    }
	}
	for(int k = 0;k < N;k++){
	    System.out.print(A[k]);
	    if(k == N - 1) break;
	    System.out.print(" ");
	}
	System.out.println("\n" + time);
    }
}
 import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int A[] = new int[N];
	for(int i = 0;i < N;i++){
	    A[i] = sc.nextInt();
	}
	int flag = 1;
	int tmp, time = 0;
	while(flag == 1){
	    flag = 0;
	    for(int j = N - 1;j >= 1;j--){
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    }
	}
	for(int k = 0;k < N;k++){
	    System.out.print(A[k]);
	    if(k == N - 1) break;
	    System.out.print(" ");
	}
	System.out.println("\n" + time);
    }
} Main public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int A[] = new int[N];
	for(int i = 0;i < N;i++){
	    A[i] = sc.nextInt();
	}
	int flag = 1;
	int tmp, time = 0;
	while(flag == 1){
	    flag = 0;
	    for(int j = N - 1;j >= 1;j--){
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    }
	}
	for(int k = 0;k < N;k++){
	    System.out.print(A[k]);
	    if(k == N - 1) break;
	    System.out.print(" ");
	}
	System.out.println("\n" + time);
    } main {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int A[] = new int[N];
	for(int i = 0;i < N;i++){
	    A[i] = sc.nextInt();
	}
	int flag = 1;
	int tmp, time = 0;
	while(flag == 1){
	    flag = 0;
	    for(int j = N - 1;j >= 1;j--){
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    }
	}
	for(int k = 0;k < N;k++){
	    System.out.print(A[k]);
	    if(k == N - 1) break;
	    System.out.print(" ");
	}
	System.out.println("\n" + time);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int A[] = new int[N]; A new int[N] N for(int i = 0;i < N;i++){
	    A[i] = sc.nextInt();
	} int i = 0; int 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 int flag = 1; flag 1 int tmp tmp time = 0; time 0 while(flag == 1){
	    flag = 0;
	    for(int j = N - 1;j >= 1;j--){
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    }
	} flag == 1 flag 1 {
	    flag = 0;
	    for(int j = N - 1;j >= 1;j--){
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    }
	} flag = 0 flag 0 for(int j = N - 1;j >= 1;j--){
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    } 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]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    } {
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    } if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 } 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;
		    time++;
		    flag = 1;
		 } 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 time++ time flag = 1 flag 1 for(int k = 0;k < N;k++){
	    System.out.print(A[k]);
	    if(k == N - 1) break;
	    System.out.print(" ");
	} int k = 0; int k = 0; k 0 k < N k N k++ k++ k {
	    System.out.print(A[k]);
	    if(k == N - 1) break;
	    System.out.print(" ");
	} {
	    System.out.print(A[k]);
	    if(k == N - 1) break;
	    System.out.print(" ");
	} System.out.print(A[k]) System.out.print System.out System System.out A[k] A k if(k == N - 1) break; k == N - 1 k N - 1 N 1 break; System.out.print(" ") System.out.print System.out System System.out " " System.out.println("\n" + time) System.out.println System.out System System.out "\n" + time "\n" time String[] args args
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int A[] = new int[N];
	for(int i = 0;i < N;i++){
	    A[i] = sc.nextInt();
	}
	int flag = 1;
	int tmp, time = 0;
	while(flag == 1){
	    flag = 0;
	    for(int j = N - 1;j >= 1;j--){
		if(A[j] < A[j - 1]){
		    tmp = A[j];
		    A[j] = A[j - 1];
		    A[j - 1] = tmp;
		    time++;
		    flag = 1;
		 }
	    }
	}
	for(int k = 0;k < N;k++){
	    System.out.print(A[k]);
	    if(k == N - 1) break;
	    System.out.print(" ");
	}
	System.out.println("\n" + time);
    }
}

