#include<rishabh.h>
void main()
{
	clrscr();
	int s;
	int arr[100];
	cin>>s;
	for(int i=0;i<s;i++){
		cin>>arr[i];
	}
	int ctr=0;
	for(int beg=0;beg<s;){
		int j=beg+1,c=0;
		for(j;j<s;j++){
			       if(arr[j]<arr[beg]){
					c++;
			       }
			       ctr++;
		}
		if(c==0){
			beg++;
		}
		else{
			int t=arr[c+beg];
			arr[c+beg]=arr[beg];
			arr[beg]=t;
		}
	}
	for(int l=0;l<s;l++)
		cout<<arr[l]<<" ";
	cout<<"\nworked for : "<<ctr<<" times";
	getch();
}