import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    int count = 0;
    for(int i = 0; i < n; i++) {
      arr.add(sc.nextInt());
    }
    for(int i = 0; i < n; i++) {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    }
  }
}
 import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    int count = 0;
    for(int i = 0; i < n; i++) {
      arr.add(sc.nextInt());
    }
    for(int i = 0; i < n; i++) {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    int count = 0;
    for(int i = 0; i < n; i++) {
      arr.add(sc.nextInt());
    }
    for(int i = 0; i < n; i++) {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    int count = 0;
    for(int i = 0; i < n; i++) {
      arr.add(sc.nextInt());
    }
    for(int i = 0; i < n; i++) {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> arr = new ArrayList<>(); arr new ArrayList<>() int count = 0; count 0 for(int i = 0; i < n; i++) {
      arr.add(sc.nextInt());
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      arr.add(sc.nextInt());
    } {
      arr.add(sc.nextInt());
    } arr.add(sc.nextInt()) arr.add arr sc.nextInt() sc.nextInt sc for(int i = 0; i < n; i++) {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    } {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    } for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      } int j = n - 1; int j = n - 1; j n - 1 n 1 j > i j i j-- j-- j {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      } {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      } if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        } arr.get(j) < arr.get(j - 1) arr.get(j) arr.get arr j arr.get(j - 1) arr.get arr j - 1 j 1 {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        } int v = arr.get(j); v arr.get(j) arr.get arr j arr.set(j, arr.get(j - 1)) arr.set arr j arr.get(j - 1) arr.get arr j - 1 j 1 arr.set(j - 1, v) arr.set arr j - 1 j 1 v count++ count if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      } i == n - 1 i n - 1 n 1 {
        System.out.println(arr.get(i));
        System.out.println(count);
      } System.out.println(arr.get(i)) System.out.println System.out System System.out arr.get(i) arr.get arr i System.out.println(count) System.out.println System.out System System.out count {
        System.out.print(arr.get(i) + " ");
      } System.out.print(arr.get(i) + " ") System.out.print System.out System System.out arr.get(i) + " " arr.get(i) arr.get arr i " " String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    int count = 0;
    for(int i = 0; i < n; i++) {
      arr.add(sc.nextInt());
    }
    for(int i = 0; i < n; i++) {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    int count = 0;
    for(int i = 0; i < n; i++) {
      arr.add(sc.nextInt());
    }
    for(int i = 0; i < n; i++) {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    }
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    int count = 0;
    for(int i = 0; i < n; i++) {
      arr.add(sc.nextInt());
    }
    for(int i = 0; i < n; i++) {
      for(int j = n - 1; j > i; j--) {
        if(arr.get(j) < arr.get(j - 1)) {
          int v = arr.get(j);
          arr.set(j, arr.get(j - 1));
          arr.set(j - 1, v);
          count++;
        }
      }
      if(i == n - 1) {
        System.out.println(arr.get(i));
        System.out.println(count);
      } else {
        System.out.print(arr.get(i) + " ");
      }
    }
  }
}

