import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;

public class Main{
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException{
        //キー入力
        getLine();
        List<String> strings = getStrOnLine();
        //計算
        int n = bubbleSort(strings);
        //出力
        String out = String.join(" ",strings);
        System.out.println(out);
        System.out.println(n);
    }

    private static int bubbleSort(List<String> list){ 
        boolean flag = true;
        int n = 0;
        while (flag){
            flag = false;
            for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            }
        }
        return n;
    }
    

    //キー入力メソッド
    public static String getLine() throws IOException {
        String str = br.readLine();
        return str;
    }
    
    //キー入力メソッド
    public static List<String> getStrOnLine() throws IOException {
        List<String> list = new ArrayList<>();
        String line = getLine();
        
        list.addAll(Arrays.asList(line.split(" ")));
        return list;
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.*; io.* java import java.util.*; util.* java public class Main{
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException{
        //キー入力
        getLine();
        List<String> strings = getStrOnLine();
        //計算
        int n = bubbleSort(strings);
        //出力
        String out = String.join(" ",strings);
        System.out.println(out);
        System.out.println(n);
    }

    private static int bubbleSort(List<String> list){ 
        boolean flag = true;
        int n = 0;
        while (flag){
            flag = false;
            for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            }
        }
        return n;
    }
    

    //キー入力メソッド
    public static String getLine() throws IOException {
        String str = br.readLine();
        return str;
    }
    
    //キー入力メソッド
    public static List<String> getStrOnLine() throws IOException {
        List<String> list = new ArrayList<>();
        String line = getLine();
        
        list.addAll(Arrays.asList(line.split(" ")));
        return list;
    }
} Main private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) public static void main(String[] args) throws IOException{
        //キー入力
        getLine();
        List<String> strings = getStrOnLine();
        //計算
        int n = bubbleSort(strings);
        //出力
        String out = String.join(" ",strings);
        System.out.println(out);
        System.out.println(n);
    } main {
        //キー入力
        getLine();
        List<String> strings = getStrOnLine();
        //計算
        int n = bubbleSort(strings);
        //出力
        String out = String.join(" ",strings);
        System.out.println(out);
        System.out.println(n);
    } getLine() getLine List<String> strings = getStrOnLine(); strings getStrOnLine() getStrOnLine int n = bubbleSort(strings); n bubbleSort(strings) bubbleSort strings String out = String.join(" ",strings); out String.join(" ",strings) String.join String " " strings System.out.println(out) System.out.println System.out System System.out out System.out.println(n) System.out.println System.out System System.out n String[] args args private static int bubbleSort(List<String> list){ 
        boolean flag = true;
        int n = 0;
        while (flag){
            flag = false;
            for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            }
        }
        return n;
    } bubbleSort { 
        boolean flag = true;
        int n = 0;
        while (flag){
            flag = false;
            for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            }
        }
        return n;
    } boolean flag = true; flag true int n = 0; n 0 while (flag){
            flag = false;
            for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            }
        } flag {
            flag = false;
            for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            }
        } flag = false flag false for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            } int j = list.size() - 1 ; int j = list.size() - 1 ; j list.size() - 1 list.size() list.size list 1 j >= 1 j 1 j-- j-- j {
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            } {
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            } int a = Integer.parseInt(list.get(j)); a Integer.parseInt(list.get(j)) Integer.parseInt Integer list.get(j) list.get list j int b = Integer.parseInt(list.get(j - 1)); b Integer.parseInt(list.get(j - 1)) Integer.parseInt Integer list.get(j - 1) list.get list j - 1 j 1 if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                } a < b a b {
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                } String tmp = list.get(j); tmp list.get(j) list.get list j list.set(j, list.get(j-1)) list.set list j list.get(j-1) list.get list j-1 j 1 list.set(j - 1, tmp) list.set list j - 1 j 1 tmp n++ n flag = true flag true return n; n List<String> list list //キー入力メソッド
    public static String getLine() throws IOException {
        String str = br.readLine();
        return str;
    } getLine {
        String str = br.readLine();
        return str;
    } String str = br.readLine(); str br.readLine() br.readLine br return str; str //キー入力メソッド
    public static List<String> getStrOnLine() throws IOException {
        List<String> list = new ArrayList<>();
        String line = getLine();
        
        list.addAll(Arrays.asList(line.split(" ")));
        return list;
    } getStrOnLine {
        List<String> list = new ArrayList<>();
        String line = getLine();
        
        list.addAll(Arrays.asList(line.split(" ")));
        return list;
    } List<String> list = new ArrayList<>(); list new ArrayList<>() String line = getLine(); line getLine() getLine list.addAll(Arrays.asList(line.split(" "))) list.addAll list Arrays.asList(line.split(" ")) Arrays.asList Arrays line.split(" ") line.split line " " return list; list public class Main{
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException{
        //キー入力
        getLine();
        List<String> strings = getStrOnLine();
        //計算
        int n = bubbleSort(strings);
        //出力
        String out = String.join(" ",strings);
        System.out.println(out);
        System.out.println(n);
    }

    private static int bubbleSort(List<String> list){ 
        boolean flag = true;
        int n = 0;
        while (flag){
            flag = false;
            for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            }
        }
        return n;
    }
    

    //キー入力メソッド
    public static String getLine() throws IOException {
        String str = br.readLine();
        return str;
    }
    
    //キー入力メソッド
    public static List<String> getStrOnLine() throws IOException {
        List<String> list = new ArrayList<>();
        String line = getLine();
        
        list.addAll(Arrays.asList(line.split(" ")));
        return list;
    }
} public class Main{
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException{
        //キー入力
        getLine();
        List<String> strings = getStrOnLine();
        //計算
        int n = bubbleSort(strings);
        //出力
        String out = String.join(" ",strings);
        System.out.println(out);
        System.out.println(n);
    }

    private static int bubbleSort(List<String> list){ 
        boolean flag = true;
        int n = 0;
        while (flag){
            flag = false;
            for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            }
        }
        return n;
    }
    

    //キー入力メソッド
    public static String getLine() throws IOException {
        String str = br.readLine();
        return str;
    }
    
    //キー入力メソッド
    public static List<String> getStrOnLine() throws IOException {
        List<String> list = new ArrayList<>();
        String line = getLine();
        
        list.addAll(Arrays.asList(line.split(" ")));
        return list;
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;

public class Main{
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException{
        //キー入力
        getLine();
        List<String> strings = getStrOnLine();
        //計算
        int n = bubbleSort(strings);
        //出力
        String out = String.join(" ",strings);
        System.out.println(out);
        System.out.println(n);
    }

    private static int bubbleSort(List<String> list){ 
        boolean flag = true;
        int n = 0;
        while (flag){
            flag = false;
            for (int j = list.size() - 1 ; j >= 1; j--){
                int a = Integer.parseInt(list.get(j));
                int b = Integer.parseInt(list.get(j - 1));
                if (a < b){
                    String tmp = list.get(j);
                    list.set(j, list.get(j-1));
                    list.set(j - 1, tmp);
                    n++;
                    flag = true;
                }
            }
        }
        return n;
    }
    

    //キー入力メソッド
    public static String getLine() throws IOException {
        String str = br.readLine();
        return str;
    }
    
    //キー入力メソッド
    public static List<String> getStrOnLine() throws IOException {
        List<String> list = new ArrayList<>();
        String line = getLine();
        
        list.addAll(Arrays.asList(line.split(" ")));
        return list;
    }
}
