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


public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int n = getInt(breader);
		int[] num = getAry(breader);
		int snum = 0;
		for(int i = 0; i < n ; i++ ) {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		}
		putAry(num);
		System.out.println(snum);
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int n = getInt(breader);
		int[] num = getAry(breader);
		int snum = 0;
		for(int i = 0; i < n ; i++ ) {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		}
		putAry(num);
		System.out.println(snum);
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

} Main public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int n = getInt(breader);
		int[] num = getAry(breader);
		int snum = 0;
		for(int i = 0; i < n ; i++ ) {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		}
		putAry(num);
		System.out.println(snum);
	} main {
		BufferedReader breader = getReader();
		int n = getInt(breader);
		int[] num = getAry(breader);
		int snum = 0;
		for(int i = 0; i < n ; i++ ) {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		}
		putAry(num);
		System.out.println(snum);
	} BufferedReader breader = getReader(); breader getReader() getReader int n = getInt(breader); n getInt(breader) getInt breader int[] num = getAry(breader); num getAry(breader) getAry breader int snum = 0; snum 0 for(int i = 0; i < n ; i++ ) {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		} {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		} for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			} int j = n-1 ; int j = n-1 ; j n-1 n 1 j > i j i j-- j-- j {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			} {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			} if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				} num[j] < num[j-1] num[j] num j num[j-1] num j-1 j 1 {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				} int k = num[j] ; k num[j] num j num[j] = num[j-1] num[j] num j num[j-1] num j-1 j 1 num[j-1] = k num[j-1] num j-1 j 1 k snum++ snum putAry(num) putAry num System.out.println(snum) System.out.println System.out System System.out snum String[] args args public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	} getReader {
		return( new BufferedReader(new InputStreamReader(System.in)));
	} return( new BufferedReader(new InputStreamReader(System.in))); ( new BufferedReader(new InputStreamReader(System.in))) public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	} getInt {
		String line = br.readLine();
		return Integer.valueOf(line);
	} String line = br.readLine(); line br.readLine() br.readLine br return Integer.valueOf(line); Integer.valueOf(line) Integer.valueOf Integer line BufferedReader br br public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	} getAry {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	} String line = br.readLine(); line br.readLine() br.readLine br String[] nstr = line.split(" "); nstr line.split(" ") line.split line " " int[] n = new int[nstr.length]; n new int[nstr.length] nstr.length nstr nstr.length for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		} int i=0 ; int i=0 ; i 0 i < nstr.length i nstr.length nstr nstr.length i++ i++ i {
			n[i] = Integer.valueOf(nstr[i]);
		} {
			n[i] = Integer.valueOf(nstr[i]);
		} n[i] = Integer.valueOf(nstr[i]) n[i] n i Integer.valueOf(nstr[i]) Integer.valueOf Integer nstr[i] nstr i return n; n BufferedReader br br public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	} getAryMl {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	} int n = getInt(br); n getInt(br) getInt br int[] ary = new int[n]; ary new int[n] n for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		} int i=0 ; int i=0 ; i 0 i < n i n i++ i++ i {
			ary[i] = getInt(br);
		} {
			ary[i] = getInt(br);
		} ary[i] = getInt(br) ary[i] ary i getInt(br) getInt br return ary; ary BufferedReader br br public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	} putAry {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	} for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		} {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		} System.out.print(ary[i]) System.out.print System.out System System.out ary[i] ary i if ( i < num-1) {
				System.out.print(" ");
			} i < num-1 i num-1 num 1 {
				System.out.print(" ");
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.println("") System.out.println System.out System System.out "" int[] ary ary int num num public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	} putAry {
		putAry(ary, ary.length ) ;
	} putAry(ary, ary.length ) putAry ary ary.length ary ary.length int[] ary ary public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	} isPrime {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	} int r = (int)Math.sqrt((double)n)+1; r (int)Math.sqrt((double)n)+1 (int)Math.sqrt((double)n) Math.sqrt Math (double)n 1 for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		} int j = 2 ; int j = 2 ; j 2 j < r j r j += 1 j += 1 j 1 {
			if ( n%j == 0 ) {
				return false;
			}
		} {
			if ( n%j == 0 ) {
				return false;
			}
		} if ( n%j == 0 ) {
				return false;
			} n%j == 0 n%j n j 0 {
				return false;
			} return false; false return true; true int n n public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int n = getInt(breader);
		int[] num = getAry(breader);
		int snum = 0;
		for(int i = 0; i < n ; i++ ) {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		}
		putAry(num);
		System.out.println(snum);
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

} public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int n = getInt(breader);
		int[] num = getAry(breader);
		int snum = 0;
		for(int i = 0; i < n ; i++ ) {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		}
		putAry(num);
		System.out.println(snum);
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int n = getInt(breader);
		int[] num = getAry(breader);
		int snum = 0;
		for(int i = 0; i < n ; i++ ) {
			for( int j = n-1 ; j > i ; j-- ) {
				if ( num[j] < num[j-1] ) {
					int k = num[j] ;
					num[j] = num[j-1];
					num[j-1] = k;
					snum++;
				}
			}
		}
		putAry(num);
		System.out.println(snum);
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static int[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

}