import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      }

      for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      }

      StringBuilder s = new StringBuilder();
      for (int i : seq) { s.append(i).append(" "); }
      s.setLength(s.length()-1);
      s.append("\n").append(count);
      System.out.println(s);
    }
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      }

      for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      }

      StringBuilder s = new StringBuilder();
      for (int i : seq) { s.append(i).append(" "); }
      s.setLength(s.length()-1);
      s.append("\n").append(count);
      System.out.println(s);
    }
  }
} Main public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      }

      for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      }

      StringBuilder s = new StringBuilder();
      for (int i : seq) { s.append(i).append(" "); }
      s.setLength(s.length()-1);
      s.append("\n").append(count);
      System.out.println(s);
    }
  } main {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      }

      for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      }

      StringBuilder s = new StringBuilder();
      for (int i : seq) { s.append(i).append(" "); }
      s.setLength(s.length()-1);
      s.append("\n").append(count);
      System.out.println(s);
    }
  } try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      }

      for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      }

      StringBuilder s = new StringBuilder();
      for (int i : seq) { s.append(i).append(" "); }
      s.setLength(s.length()-1);
      s.append("\n").append(count);
      System.out.println(s);
    } {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      }

      for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      }

      StringBuilder s = new StringBuilder();
      for (int i : seq) { s.append(i).append(" "); }
      s.setLength(s.length()-1);
      s.append("\n").append(count);
      System.out.println(s);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int count=0; count 0 int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] seq = new int[n]; seq new int[n] n String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      } int i=0; int i=0; i 0 i < n i n i++ i++ i {
        seq[i] = Integer.parseInt(line[i]);
      } {
        seq[i] = Integer.parseInt(line[i]);
      } seq[i] = Integer.parseInt(line[i]) seq[i] seq i Integer.parseInt(line[i]) Integer.parseInt Integer line[i] line i for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      } int i=0,f=1,t; int i=0 i 0 f=1 f 1 t; t i<n || f==1 i<n i n f==1 f 1 i++ i++ i {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      } {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      } f=0 f 0 for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        } int j=n-1; int j=n-1; j n-1 n 1 j>0 j 0 j-- j-- j {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        } {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        } if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          } seq[j] < seq[j-1] seq[j] seq j seq[j-1] seq j-1 j 1 {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          } t = seq[j] t seq[j] seq j seq[j] = seq[j-1] seq[j] seq j seq[j-1] seq j-1 j 1 seq[j-1] = t seq[j-1] seq j-1 j 1 t count++ count f=1 f 1 StringBuilder s = new StringBuilder(); s new StringBuilder() for (int i : seq) { s.append(i).append(" "); } int i seq { s.append(i).append(" "); } { s.append(i).append(" "); } s.append(i).append(" ") s.append(i).append s.append(i) s.append s i " " s.setLength(s.length()-1) s.setLength s s.length()-1 s.length() s.length s 1 s.append("\n").append(count) s.append("\n").append s.append("\n") s.append s "\n" count System.out.println(s) System.out.println System.out System System.out s String[] args args public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      }

      for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      }

      StringBuilder s = new StringBuilder();
      for (int i : seq) { s.append(i).append(" "); }
      s.setLength(s.length()-1);
      s.append("\n").append(count);
      System.out.println(s);
    }
  }
} public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      }

      for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      }

      StringBuilder s = new StringBuilder();
      for (int i : seq) { s.append(i).append(" "); }
      s.setLength(s.length()-1);
      s.append("\n").append(count);
      System.out.println(s);
    }
  }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        seq[i] = Integer.parseInt(line[i]);
      }

      for(int i=0,f=1,t; i<n || f==1; i++ ) {
        f=0;
        for(int j=n-1; j>0; j-- ) {
          if( seq[j] < seq[j-1]) {
            t = seq[j];
            seq[j] = seq[j-1];
            seq[j-1] = t;
            count++;
            f=1;
          }
        }
      }

      StringBuilder s = new StringBuilder();
      for (int i : seq) { s.append(i).append(" "); }
      s.setLength(s.length()-1);
      s.append("\n").append(count);
      System.out.println(s);
    }
  }
}
