import java.io.*;

public class Main{
	public static void main(String[] args)
	{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			bubbleSort(ar,ar.length);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void bubbleSort(int[] a , int l)
	{
		boolean bool = true;
		int cou = 0;
		for(int i = l-1 ; bool ; i--  )
		{
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		}
		show(a,cou);		
	}
	public static void show(int[] b,int co){
		StringBuilder sb = new StringBuilder();
		for(int i= 0;i<b.length-1;i++)
		{
			sb.append(b[i]).append(" ");	
		}
		sb.append(b[b.length-1]).append("\n").append(co).append("\n");	
		System.out.print(sb);
	}
} import java.io.*; io.* java public class Main{
	public static void main(String[] args)
	{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			bubbleSort(ar,ar.length);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void bubbleSort(int[] a , int l)
	{
		boolean bool = true;
		int cou = 0;
		for(int i = l-1 ; bool ; i--  )
		{
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		}
		show(a,cou);		
	}
	public static void show(int[] b,int co){
		StringBuilder sb = new StringBuilder();
		for(int i= 0;i<b.length-1;i++)
		{
			sb.append(b[i]).append(" ");	
		}
		sb.append(b[b.length-1]).append("\n").append(co).append("\n");	
		System.out.print(sb);
	}
} Main public static void main(String[] args)
	{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			bubbleSort(ar,ar.length);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	} main {
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			bubbleSort(ar,ar.length);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	} try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			bubbleSort(ar,ar.length);
			
		}catch(Exception e){
			e.printStackTrace();
		} catch(Exception e){
			e.printStackTrace();
		} Exception e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			bubbleSort(ar,ar.length);
			
		} 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 String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] ar = new int[n]; ar new int[n] n for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			} int i=0 ; int i=0 ; i 0 i < n i n i++ i++ i {
				ar[i] = Integer.parseInt(str[i]);
			} {
				ar[i] = Integer.parseInt(str[i]);
			} ar[i] = Integer.parseInt(str[i]) ar[i] ar i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i bubbleSort(ar,ar.length) bubbleSort ar ar.length ar ar.length String[] args args public static void bubbleSort(int[] a , int l)
	{
		boolean bool = true;
		int cou = 0;
		for(int i = l-1 ; bool ; i--  )
		{
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		}
		show(a,cou);		
	} bubbleSort {
		boolean bool = true;
		int cou = 0;
		for(int i = l-1 ; bool ; i--  )
		{
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		}
		show(a,cou);		
	} boolean bool = true; bool true int cou = 0; cou 0 for(int i = l-1 ; bool ; i--  )
		{
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		} int i = l-1 ; int i = l-1 ; i l-1 l 1 bool i-- i-- i {
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		} {
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		} bool = false bool false for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			} int j = 0 ; int j = 0 ; j 0 j < i j i j++ j++ j {
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			} {
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			} if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				} a[j] > a[j+1] a[j] a j a[j+1] a j+1 j 1 {
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				} int temp = a[j+1]; temp a[j+1] a j+1 j 1 a[j+1] = a[j] a[j+1] a j+1 j 1 a[j] a j a[j] = temp a[j] a j temp bool = true bool true cou++ cou show(a,cou) show a cou int[] a a int l l public static void show(int[] b,int co){
		StringBuilder sb = new StringBuilder();
		for(int i= 0;i<b.length-1;i++)
		{
			sb.append(b[i]).append(" ");	
		}
		sb.append(b[b.length-1]).append("\n").append(co).append("\n");	
		System.out.print(sb);
	} show {
		StringBuilder sb = new StringBuilder();
		for(int i= 0;i<b.length-1;i++)
		{
			sb.append(b[i]).append(" ");	
		}
		sb.append(b[b.length-1]).append("\n").append(co).append("\n");	
		System.out.print(sb);
	} StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i= 0;i<b.length-1;i++)
		{
			sb.append(b[i]).append(" ");	
		} int i= 0; int i= 0; i 0 i<b.length-1 i b.length-1 b.length b b.length 1 i++ i++ i {
			sb.append(b[i]).append(" ");	
		} {
			sb.append(b[i]).append(" ");	
		} sb.append(b[i]).append(" ") sb.append(b[i]).append sb.append(b[i]) sb.append sb b[i] b i " " sb.append(b[b.length-1]).append("\n").append(co).append("\n") sb.append(b[b.length-1]).append("\n").append(co).append sb.append(b[b.length-1]).append("\n").append(co) sb.append(b[b.length-1]).append("\n").append sb.append(b[b.length-1]).append("\n") sb.append(b[b.length-1]).append sb.append(b[b.length-1]) sb.append sb b[b.length-1] b b.length-1 b.length b b.length 1 "\n" co "\n" System.out.print(sb) System.out.print System.out System System.out sb int[] b b int co co public class Main{
	public static void main(String[] args)
	{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			bubbleSort(ar,ar.length);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void bubbleSort(int[] a , int l)
	{
		boolean bool = true;
		int cou = 0;
		for(int i = l-1 ; bool ; i--  )
		{
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		}
		show(a,cou);		
	}
	public static void show(int[] b,int co){
		StringBuilder sb = new StringBuilder();
		for(int i= 0;i<b.length-1;i++)
		{
			sb.append(b[i]).append(" ");	
		}
		sb.append(b[b.length-1]).append("\n").append(co).append("\n");	
		System.out.print(sb);
	}
} public class Main{
	public static void main(String[] args)
	{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			bubbleSort(ar,ar.length);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void bubbleSort(int[] a , int l)
	{
		boolean bool = true;
		int cou = 0;
		for(int i = l-1 ; bool ; i--  )
		{
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		}
		show(a,cou);		
	}
	public static void show(int[] b,int co){
		StringBuilder sb = new StringBuilder();
		for(int i= 0;i<b.length-1;i++)
		{
			sb.append(b[i]).append(" ");	
		}
		sb.append(b[b.length-1]).append("\n").append(co).append("\n");	
		System.out.print(sb);
	}
} Main
import java.io.*;

public class Main{
	public static void main(String[] args)
	{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i=0 ; i < n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			bubbleSort(ar,ar.length);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void bubbleSort(int[] a , int l)
	{
		boolean bool = true;
		int cou = 0;
		for(int i = l-1 ; bool ; i--  )
		{
			bool = false;
			for(int j = 0 ; j < i ; j++)
			{
				if(a[j] > a[j+1])
				{
					int temp = a[j+1];
					a[j+1] = a[j];
					a[j] = temp;
					bool = true;
					cou++;
				}
			}
		}
		show(a,cou);		
	}
	public static void show(int[] b,int co){
		StringBuilder sb = new StringBuilder();
		for(int i= 0;i<b.length-1;i++)
		{
			sb.append(b[i]).append(" ");	
		}
		sb.append(b[b.length-1]).append("\n").append(co).append("\n");	
		System.out.print(sb);
	}
}