import java.util.Scanner;

public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] A = new int[101];
		int n, i, j, key;
		n = input.nextInt();
		for(i = 0; i <n; i++)
		{
			A[i]=input.nextInt();
		}
		bubble(A, n);
	}

	public static void bubble(int A[], int n)
	{
		int count = 0, t;
		for(int i = 0; i < n; i++)
		{
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		}
		trace(A, n);
		System.out.println(count);
	}

	public static void trace(int A[], int n)
	{
		for(int i = 0; i < n; i++)
		{
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
	}
} import java.util.Scanner; Scanner java.util public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] A = new int[101];
		int n, i, j, key;
		n = input.nextInt();
		for(i = 0; i <n; i++)
		{
			A[i]=input.nextInt();
		}
		bubble(A, n);
	}

	public static void bubble(int A[], int n)
	{
		int count = 0, t;
		for(int i = 0; i < n; i++)
		{
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		}
		trace(A, n);
		System.out.println(count);
	}

	public static void trace(int A[], int n)
	{
		for(int i = 0; i < n; i++)
		{
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
	}
} Main public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] A = new int[101];
		int n, i, j, key;
		n = input.nextInt();
		for(i = 0; i <n; i++)
		{
			A[i]=input.nextInt();
		}
		bubble(A, n);
	} main {
		Scanner input = new Scanner(System.in);
		int[] A = new int[101];
		int n, i, j, key;
		n = input.nextInt();
		for(i = 0; i <n; i++)
		{
			A[i]=input.nextInt();
		}
		bubble(A, n);
	} Scanner input = new Scanner(System.in); input new Scanner(System.in) int[] A = new int[101]; A new int[101] 101 int n n i i j j key; key n = input.nextInt() n input.nextInt() input.nextInt input for(i = 0; i <n; i++)
		{
			A[i]=input.nextInt();
		} i = 0; i = 0 i 0 i <n i n i++ i++ i {
			A[i]=input.nextInt();
		} {
			A[i]=input.nextInt();
		} A[i]=input.nextInt() A[i] A i input.nextInt() input.nextInt input bubble(A, n) bubble A n String args[] args public static void bubble(int A[], int n)
	{
		int count = 0, t;
		for(int i = 0; i < n; i++)
		{
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		}
		trace(A, n);
		System.out.println(count);
	} bubble {
		int count = 0, t;
		for(int i = 0; i < n; i++)
		{
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		}
		trace(A, n);
		System.out.println(count);
	} int count = 0 count 0 t; t for(int i = 0; i < n; i++)
		{
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		} {
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		} for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			} int j = n-1; int j = n-1; j n-1 n 1 j>=i+1 j i+1 i 1 j-- j-- j {
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			} {
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			} if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				} A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				} t = A[j] t A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = t A[j-1] A j-1 j 1 t count++ count trace(A, n) trace A n System.out.println(count) System.out.println System.out System System.out count int A[] A int n n public static void trace(int A[], int n)
	{
		for(int i = 0; i < n; i++)
		{
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
	} trace {
		for(int i = 0; i < n; i++)
		{
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
	} for(int i = 0; i < n; i++)
		{
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		} {
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		} if(i > 0)System.out.print(" "); i > 0 i 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(A[i]) System.out.print System.out System System.out A[i] A i System.out.println() System.out.println System.out System System.out int A[] A int n n public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] A = new int[101];
		int n, i, j, key;
		n = input.nextInt();
		for(i = 0; i <n; i++)
		{
			A[i]=input.nextInt();
		}
		bubble(A, n);
	}

	public static void bubble(int A[], int n)
	{
		int count = 0, t;
		for(int i = 0; i < n; i++)
		{
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		}
		trace(A, n);
		System.out.println(count);
	}

	public static void trace(int A[], int n)
	{
		for(int i = 0; i < n; i++)
		{
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
	}
} public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] A = new int[101];
		int n, i, j, key;
		n = input.nextInt();
		for(i = 0; i <n; i++)
		{
			A[i]=input.nextInt();
		}
		bubble(A, n);
	}

	public static void bubble(int A[], int n)
	{
		int count = 0, t;
		for(int i = 0; i < n; i++)
		{
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		}
		trace(A, n);
		System.out.println(count);
	}

	public static void trace(int A[], int n)
	{
		for(int i = 0; i < n; i++)
		{
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
	}
} Main
import java.util.Scanner;

public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] A = new int[101];
		int n, i, j, key;
		n = input.nextInt();
		for(i = 0; i <n; i++)
		{
			A[i]=input.nextInt();
		}
		bubble(A, n);
	}

	public static void bubble(int A[], int n)
	{
		int count = 0, t;
		for(int i = 0; i < n; i++)
		{
			for(int j = n-1; j>=i+1; j--)
			{
				if(A[j] < A[j-1])
				{
					t = A[j];
					A[j] = A[j-1];
					A[j-1] = t;
					count++;
				}
			}
		}
		trace(A, n);
		System.out.println(count);
	}

	public static void trace(int A[], int n)
	{
		for(int i = 0; i < n; i++)
		{
			if(i > 0)System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
	}
}