def bubble(A,N):
	flag=1
	cnt=0
	while flag==1:
		flag=0
		for j in range(1,N):
			if A[j]<A[j-1]:
				k=A[j-1]
				A[j-1]=A[j]
				A[j]=k
				flag=1
				cnt+=1
	return A,cnt
n=int(raw_input())			
list=map(int,raw_input().split())
list,cnt=bubble(list,n)
for x in list:
	print x,
print
print cnt, def bubble(A,N):
	flag=1
	cnt=0
	while flag==1:
		flag=0
		for j in range(1,N):
			if A[j]<A[j-1]:
				k=A[j-1]
				A[j-1]=A[j]
				A[j]=k
				flag=1
				cnt+=1
	return A,cnt bubble flag=1 flag 1 cnt=0 cnt 0 while flag==1:
		flag=0
		for j in range(1,N):
			if A[j]<A[j-1]:
				k=A[j-1]
				A[j-1]=A[j]
				A[j]=k
				flag=1
				cnt+=1
	 flag==1 flag 1 flag=0 flag 0 for j in range(1,N):
			if A[j]<A[j-1]:
				k=A[j-1]
				A[j-1]=A[j]
				A[j]=k
				flag=1
				cnt+=1
	 j range(1,N) range 1 N if A[j]<A[j-1]:
				k=A[j-1]
				A[j-1]=A[j]
				A[j]=k
				flag=1
				cnt+=1
	 A[j]<A[j-1] A[j] A j A[j-1] A j-1 j 1 k=A[j-1] k 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]=k A[j] A j k flag=1 flag 1 cnt+=1 cnt 1 return A,cnt return A,cnt A cnt A A N N n=int(raw_input()) n int(raw_input()) int raw_input() raw_input list=map(int,raw_input().split()) list map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split list,cnt=bubble(list,n) list bubble(list,n) bubble list n cnt for x in list:
	print x, x list print x print print cnt n=int(raw_input()) int(raw_input()) n def bubble(A,N):
	flag=1
	cnt=0
	while flag==1:
		flag=0
		for j in range(1,N):
			if A[j]<A[j-1]:
				k=A[j-1]
				A[j-1]=A[j]
				A[j]=k
				flag=1
				cnt+=1
	return A,cnt def bubble(A,N):
	flag=1
	cnt=0
	while flag==1:
		flag=0
		for j in range(1,N):
			if A[j]<A[j-1]:
				k=A[j-1]
				A[j-1]=A[j]
				A[j]=k
				flag=1
				cnt+=1
	return A,cnt bubble cnt=bubble(list,n) bubble(list,n) cnt list=map(int,raw_input().split()) map(int,raw_input().split()) list list,cnt=bubble(list,n) bubble(list,n) list
def bubble(A,N):
	flag=1
	cnt=0
	while flag==1:
		flag=0
		for j in range(1,N):
			if A[j]<A[j-1]:
				k=A[j-1]
				A[j-1]=A[j]
				A[j]=k
				flag=1
				cnt+=1
	return A,cnt
n=int(raw_input())			
list=map(int,raw_input().split())
list,cnt=bubble(list,n)
for x in list:
	print x,
print
print cnt,