import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        boolean fg = true;
        int change = 0;
        int cnt=0;
        while(fg) {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	}
        }
        for(int i=0;i<n-1;i++) {
        	System.out.print(ns[i]+" ");
        }
        System.out.println(ns[n-1]);
        System.out.println(cnt);
        scan.close();
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        boolean fg = true;
        int change = 0;
        int cnt=0;
        while(fg) {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	}
        }
        for(int i=0;i<n-1;i++) {
        	System.out.print(ns[i]+" ");
        }
        System.out.println(ns[n-1]);
        System.out.println(cnt);
        scan.close();
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        boolean fg = true;
        int change = 0;
        int cnt=0;
        while(fg) {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	}
        }
        for(int i=0;i<n-1;i++) {
        	System.out.print(ns[i]+" ");
        }
        System.out.println(ns[n-1]);
        System.out.println(cnt);
        scan.close();
    } main {
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        boolean fg = true;
        int change = 0;
        int cnt=0;
        while(fg) {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	}
        }
        for(int i=0;i<n-1;i++) {
        	System.out.print(ns[i]+" ");
        }
        System.out.println(ns[n-1]);
        System.out.println(cnt);
        scan.close();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = Integer.valueOf(scan.next()); n Integer.valueOf(scan.next()) Integer.valueOf Integer scan.next() scan.next scan int[] ns = new int[n]; ns new int[n] n for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
        	ns[i] = Integer.valueOf(scan.next());
        } {
        	ns[i] = Integer.valueOf(scan.next());
        } ns[i] = Integer.valueOf(scan.next()) ns[i] ns i Integer.valueOf(scan.next()) Integer.valueOf Integer scan.next() scan.next scan boolean fg = true; fg true int change = 0; change 0 int cnt=0; cnt 0 while(fg) {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	}
        } fg {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	}
        } fg = false fg false for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	} int i=n-1; int i=n-1; i n-1 n 1 i>0 i 0 i-- i-- i {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	} {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	} if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		} ns[i] < ns[i-1] ns[i] ns i ns[i-1] ns i-1 i 1 {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		} change =  ns[i] change ns[i] ns i ns[i] = ns[i-1] ns[i] ns i ns[i-1] ns i-1 i 1 ns[i-1] = change ns[i-1] ns i-1 i 1 change cnt++ cnt fg=true fg true for(int i=0;i<n-1;i++) {
        	System.out.print(ns[i]+" ");
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
        	System.out.print(ns[i]+" ");
        } {
        	System.out.print(ns[i]+" ");
        } System.out.print(ns[i]+" ") System.out.print System.out System System.out ns[i]+" " ns[i] ns i " " System.out.println(ns[n-1]) System.out.println System.out System System.out ns[n-1] ns n-1 n 1 System.out.println(cnt) System.out.println System.out System System.out cnt scan.close() scan.close scan String[] args args public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        boolean fg = true;
        int change = 0;
        int cnt=0;
        while(fg) {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	}
        }
        for(int i=0;i<n-1;i++) {
        	System.out.print(ns[i]+" ");
        }
        System.out.println(ns[n-1]);
        System.out.println(cnt);
        scan.close();
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        boolean fg = true;
        int change = 0;
        int cnt=0;
        while(fg) {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	}
        }
        for(int i=0;i<n-1;i++) {
        	System.out.print(ns[i]+" ");
        }
        System.out.println(ns[n-1]);
        System.out.println(cnt);
        scan.close();
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = Integer.valueOf(scan.next());
        int[] ns = new int[n];
        for(int i=0;i<n;i++) {
        	ns[i] = Integer.valueOf(scan.next());
        }
        boolean fg = true;
        int change = 0;
        int cnt=0;
        while(fg) {
        	fg = false;
        	for(int i=n-1;i>0;i--) {
        		if(ns[i] < ns[i-1]) {
        			change =  ns[i];
        			ns[i] = ns[i-1];
        			ns[i-1] = change;
        			cnt++;
        			fg=true;
        		}
        	}
        }
        for(int i=0;i<n-1;i++) {
        	System.out.print(ns[i]+" ");
        }
        System.out.println(ns[n-1]);
        System.out.println(cnt);
        scan.close();
    }
}
