import java.io.*;
import java.util.*;
  
class Main{
      public static void main(String[] args) {
       int narabi =0;
       int count =0;
       Scanner sc = new Scanner(System.in);
           int n = sc.nextInt();
           int [] array = new int[n];
         for(int i=0; i<n; i++){
             array[i] = sc.nextInt();
           }
           
          for(int i=0; i<array.length-1; i++){
            for(int j=array.length-1; j>0; j--){
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              }
           }
            for(int k =0; k<array.length-1; k++){
            int number = array[k];
            System.out.print(number + " ");
             }
             System.out.println(array[array.length-1]);
             System.out.println(count);
        }

     } import java.io.*; io.* java import java.util.*; util.* java class Main{
      public static void main(String[] args) {
       int narabi =0;
       int count =0;
       Scanner sc = new Scanner(System.in);
           int n = sc.nextInt();
           int [] array = new int[n];
         for(int i=0; i<n; i++){
             array[i] = sc.nextInt();
           }
           
          for(int i=0; i<array.length-1; i++){
            for(int j=array.length-1; j>0; j--){
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              }
           }
            for(int k =0; k<array.length-1; k++){
            int number = array[k];
            System.out.print(number + " ");
             }
             System.out.println(array[array.length-1]);
             System.out.println(count);
        }

     } Main public static void main(String[] args) {
       int narabi =0;
       int count =0;
       Scanner sc = new Scanner(System.in);
           int n = sc.nextInt();
           int [] array = new int[n];
         for(int i=0; i<n; i++){
             array[i] = sc.nextInt();
           }
           
          for(int i=0; i<array.length-1; i++){
            for(int j=array.length-1; j>0; j--){
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              }
           }
            for(int k =0; k<array.length-1; k++){
            int number = array[k];
            System.out.print(number + " ");
             }
             System.out.println(array[array.length-1]);
             System.out.println(count);
        } main {
       int narabi =0;
       int count =0;
       Scanner sc = new Scanner(System.in);
           int n = sc.nextInt();
           int [] array = new int[n];
         for(int i=0; i<n; i++){
             array[i] = sc.nextInt();
           }
           
          for(int i=0; i<array.length-1; i++){
            for(int j=array.length-1; j>0; j--){
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              }
           }
            for(int k =0; k<array.length-1; k++){
            int number = array[k];
            System.out.print(number + " ");
             }
             System.out.println(array[array.length-1]);
             System.out.println(count);
        } int narabi =0; narabi 0 int count =0; count 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int [] array = new int[n]; array new int[n] n for(int i=0; i<n; i++){
             array[i] = sc.nextInt();
           } int i=0; int i=0; i 0 i<n i n i++ i++ i {
             array[i] = sc.nextInt();
           } {
             array[i] = sc.nextInt();
           } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc for(int i=0; i<array.length-1; i++){
            for(int j=array.length-1; j>0; j--){
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              }
           } int i=0; int i=0; i 0 i<array.length-1 i array.length-1 array.length array array.length 1 i++ i++ i {
            for(int j=array.length-1; j>0; j--){
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              }
           } {
            for(int j=array.length-1; j>0; j--){
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              }
           } for(int j=array.length-1; j>0; j--){
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              } int j=array.length-1; int j=array.length-1; j array.length-1 array.length array array.length 1 j>0 j 0 j-- j-- j {
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              } {
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              } if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                } array[j] < array[j-1] array[j] array j array[j-1] array j-1 j 1 {
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                } int a = array[j]; a array[j] array j int b = array[j-1]; b array[j-1] array j-1 j 1 array[j] = b array[j] array j b array[j-1]= a array[j-1] array j-1 j 1 a count++ count for(int k =0; k<array.length-1; k++){
            int number = array[k];
            System.out.print(number + " ");
             } int k =0; int k =0; k 0 k<array.length-1 k array.length-1 array.length array array.length 1 k++ k++ k {
            int number = array[k];
            System.out.print(number + " ");
             } {
            int number = array[k];
            System.out.print(number + " ");
             } int number = array[k]; number array[k] array k System.out.print(number + " ") System.out.print System.out System System.out number + " " number " " System.out.println(array[array.length-1]) System.out.println System.out System System.out array[array.length-1] array array.length-1 array.length array array.length 1 System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.io.*;
import java.util.*;
  
class Main{
      public static void main(String[] args) {
       int narabi =0;
       int count =0;
       Scanner sc = new Scanner(System.in);
           int n = sc.nextInt();
           int [] array = new int[n];
         for(int i=0; i<n; i++){
             array[i] = sc.nextInt();
           }
           
          for(int i=0; i<array.length-1; i++){
            for(int j=array.length-1; j>0; j--){
                if(array[j] < array[j-1]){
                    int a = array[j];
                    int b = array[j-1];
                    array[j] = b;
                    array[j-1]= a;
                    count++;
                }
              }
           }
            for(int k =0; k<array.length-1; k++){
            int number = array[k];
            System.out.print(number + " ");
             }
             System.out.println(array[array.length-1]);
             System.out.println(count);
        }

     }