import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n = scn.nextInt();
        System.out.println(bubbleSort(createArray(n)));
    }
    
    private static int[] createArray(int n) {
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) {
            ary[i] = scn.nextInt();
        }
        return ary;
    }
    
    private static int bubbleSort(int[] ary) {
        int cnt = 0;
        for(int i = 0; i < ary.length; i++) {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int elm : ary) {
            sb.append(elm + " ");
        }
        System.out.println(sb.toString().trim());
        return cnt;
    }
} import java.util.*; util.* java public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n = scn.nextInt();
        System.out.println(bubbleSort(createArray(n)));
    }
    
    private static int[] createArray(int n) {
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) {
            ary[i] = scn.nextInt();
        }
        return ary;
    }
    
    private static int bubbleSort(int[] ary) {
        int cnt = 0;
        for(int i = 0; i < ary.length; i++) {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int elm : ary) {
            sb.append(elm + " ");
        }
        System.out.println(sb.toString().trim());
        return cnt;
    }
} Main private static final Scanner scn = new Scanner(System.in); scn new Scanner(System.in) public static void main(String[] args) {
        int n = scn.nextInt();
        System.out.println(bubbleSort(createArray(n)));
    } main {
        int n = scn.nextInt();
        System.out.println(bubbleSort(createArray(n)));
    } int n = scn.nextInt(); n scn.nextInt() scn.nextInt scn System.out.println(bubbleSort(createArray(n))) System.out.println System.out System System.out bubbleSort(createArray(n)) bubbleSort createArray(n) createArray n String[] args args private static int[] createArray(int n) {
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) {
            ary[i] = scn.nextInt();
        }
        return ary;
    } createArray {
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) {
            ary[i] = scn.nextInt();
        }
        return ary;
    } int[] ary = new int[n]; ary new int[n] n for(int i = 0; i < n; i++) {
            ary[i] = scn.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            ary[i] = scn.nextInt();
        } {
            ary[i] = scn.nextInt();
        } ary[i] = scn.nextInt() ary[i] ary i scn.nextInt() scn.nextInt scn return ary; ary int n n private static int bubbleSort(int[] ary) {
        int cnt = 0;
        for(int i = 0; i < ary.length; i++) {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int elm : ary) {
            sb.append(elm + " ");
        }
        System.out.println(sb.toString().trim());
        return cnt;
    } bubbleSort {
        int cnt = 0;
        for(int i = 0; i < ary.length; i++) {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int elm : ary) {
            sb.append(elm + " ");
        }
        System.out.println(sb.toString().trim());
        return cnt;
    } int cnt = 0; cnt 0 for(int i = 0; i < ary.length; i++) {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        } int i = 0; int i = 0; i 0 i < ary.length i ary.length ary ary.length i++ i++ i {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        } {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        } for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            } int j = ary.length - 1; int j = ary.length - 1; j ary.length - 1 ary.length ary ary.length 1 j > i j i j-- j-- j {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            } {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            } if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                } ary[j] < ary[j - 1] ary[j] ary j ary[j - 1] ary j - 1 j 1 {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                } ary[j] ^= ary[j - 1] ary[j] ary j ary[j - 1] ary j - 1 j 1 ary[j - 1] ^= ary[j] ary[j - 1] ary j - 1 j 1 ary[j] ary j ary[j] ^= ary[j - 1] ary[j] ary j ary[j - 1] ary j - 1 j 1 cnt++ cnt StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int elm : ary) {
            sb.append(elm + " ");
        } int elm ary {
            sb.append(elm + " ");
        } {
            sb.append(elm + " ");
        } sb.append(elm + " ") sb.append sb elm + " " elm " " System.out.println(sb.toString().trim()) System.out.println System.out System System.out sb.toString().trim() sb.toString().trim sb.toString() sb.toString sb return cnt; cnt int[] ary ary public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n = scn.nextInt();
        System.out.println(bubbleSort(createArray(n)));
    }
    
    private static int[] createArray(int n) {
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) {
            ary[i] = scn.nextInt();
        }
        return ary;
    }
    
    private static int bubbleSort(int[] ary) {
        int cnt = 0;
        for(int i = 0; i < ary.length; i++) {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int elm : ary) {
            sb.append(elm + " ");
        }
        System.out.println(sb.toString().trim());
        return cnt;
    }
} public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n = scn.nextInt();
        System.out.println(bubbleSort(createArray(n)));
    }
    
    private static int[] createArray(int n) {
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) {
            ary[i] = scn.nextInt();
        }
        return ary;
    }
    
    private static int bubbleSort(int[] ary) {
        int cnt = 0;
        for(int i = 0; i < ary.length; i++) {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int elm : ary) {
            sb.append(elm + " ");
        }
        System.out.println(sb.toString().trim());
        return cnt;
    }
} Main
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n = scn.nextInt();
        System.out.println(bubbleSort(createArray(n)));
    }
    
    private static int[] createArray(int n) {
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) {
            ary[i] = scn.nextInt();
        }
        return ary;
    }
    
    private static int bubbleSort(int[] ary) {
        int cnt = 0;
        for(int i = 0; i < ary.length; i++) {
            for(int j = ary.length - 1; j > i; j--) {
                if(ary[j] < ary[j - 1]) {
                    ary[j] ^= ary[j - 1];
                    ary[j - 1] ^= ary[j];
                    ary[j] ^= ary[j - 1];
                    cnt++;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for(int elm : ary) {
            sb.append(elm + " ");
        }
        System.out.println(sb.toString().trim());
        return cnt;
    }
}