import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		int n=Integer.parseInt(br.readLine());
		int[] in=new int[n];
		int count=0;
StringTokenizer st=new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++) in[i]=Integer.parseInt(st.nextToken());
		
		for(int i=n;i>0;i--){
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		}
StringBuilder stb=new StringBuilder(Integer.toString(in[0]));
for(int i=1;i<n;i++)stb.append(" "+in[i]);
System.out.println(stb);
		System.out.println(count);




	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.FileNotFoundException; FileNotFoundException java.io import java.io.FileReader; FileReader java.io import java.io.IOException; IOException java.io import java.util.StringTokenizer; StringTokenizer java.util import java.io.InputStreamReader; InputStreamReader java.io public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		int n=Integer.parseInt(br.readLine());
		int[] in=new int[n];
		int count=0;
StringTokenizer st=new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++) in[i]=Integer.parseInt(st.nextToken());
		
		for(int i=n;i>0;i--){
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		}
StringBuilder stb=new StringBuilder(Integer.toString(in[0]));
for(int i=1;i<n;i++)stb.append(" "+in[i]);
System.out.println(stb);
		System.out.println(count);




	}

} Main public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		int n=Integer.parseInt(br.readLine());
		int[] in=new int[n];
		int count=0;
StringTokenizer st=new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++) in[i]=Integer.parseInt(st.nextToken());
		
		for(int i=n;i>0;i--){
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		}
StringBuilder stb=new StringBuilder(Integer.toString(in[0]));
for(int i=1;i<n;i++)stb.append(" "+in[i]);
System.out.println(stb);
		System.out.println(count);




	} main {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		int n=Integer.parseInt(br.readLine());
		int[] in=new int[n];
		int count=0;
StringTokenizer st=new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++) in[i]=Integer.parseInt(st.nextToken());
		
		for(int i=n;i>0;i--){
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		}
StringBuilder stb=new StringBuilder(Integer.toString(in[0]));
for(int i=1;i<n;i++)stb.append(" "+in[i]);
System.out.println(stb);
		System.out.println(count);




	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n=Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] in=new int[n]; in new int[n] n int count=0; count 0 StringTokenizer st=new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) for(int i=0;i<n;i++) in[i]=Integer.parseInt(st.nextToken()); int i=0; int i=0; i 0 i<n i n i++ i++ i in[i]=Integer.parseInt(st.nextToken()); in[i]=Integer.parseInt(st.nextToken()) in[i] in i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st for(int i=n;i>0;i--){
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		} int i=n; int i=n; i n i>0 i 0 i-- i-- i {
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		} {
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		} for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			} int j=1; int j=1; j 1 j<i j i j++ j++ j {
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			} {
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			} if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				} in[j-1]>in[j] in[j-1] in j-1 j 1 in[j] in j {count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				} count++ count int tmp=in[j-1]; tmp in[j-1] in j-1 j 1 in[j-1]=in[j] in[j-1] in j-1 j 1 in[j] in j in[j]=tmp in[j] in j tmp StringBuilder stb=new StringBuilder(Integer.toString(in[0])); stb new StringBuilder(Integer.toString(in[0])) for(int i=1;i<n;i++)stb.append(" "+in[i]); int i=1; int i=1; i 1 i<n i n i++ i++ i stb.append(" "+in[i]); stb.append(" "+in[i]) stb.append stb " "+in[i] " " in[i] in i System.out.println(stb) System.out.println System.out System System.out stb System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		int n=Integer.parseInt(br.readLine());
		int[] in=new int[n];
		int count=0;
StringTokenizer st=new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++) in[i]=Integer.parseInt(st.nextToken());
		
		for(int i=n;i>0;i--){
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		}
StringBuilder stb=new StringBuilder(Integer.toString(in[0]));
for(int i=1;i<n;i++)stb.append(" "+in[i]);
System.out.println(stb);
		System.out.println(count);




	}

} public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		int n=Integer.parseInt(br.readLine());
		int[] in=new int[n];
		int count=0;
StringTokenizer st=new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++) in[i]=Integer.parseInt(st.nextToken());
		
		for(int i=n;i>0;i--){
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		}
StringBuilder stb=new StringBuilder(Integer.toString(in[0]));
for(int i=1;i<n;i++)stb.append(" "+in[i]);
System.out.println(stb);
		System.out.println(count);




	}

} Main
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));
		int n=Integer.parseInt(br.readLine());
		int[] in=new int[n];
		int count=0;
StringTokenizer st=new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++) in[i]=Integer.parseInt(st.nextToken());
		
		for(int i=n;i>0;i--){
			for(int j=1;j<i;j++){
				if(in[j-1]>in[j]){count++;
					int tmp=in[j-1];
					in[j-1]=in[j];
					in[j]=tmp;
				}
			}
		}
StringBuilder stb=new StringBuilder(Integer.toString(in[0]));
for(int i=1;i<n;i++)stb.append(" "+in[i]);
System.out.println(stb);
		System.out.println(count);




	}

}