def bubble_sort(List):
	cnt=0
	l=len(List)
	for i in range(l):
		for j in range(l-1,i,-1):
			if List[j]<List[j-1]:
				temp=List[j]
				List[j]=List[j-1]
				List[j-1]=temp
				cnt+=1
	return cnt
def main():
	N=input()
	N_List=map(int,raw_input().split())
	cnt=bubble_sort(N_List)
	for k in range(len(N_List)):
		N_List[k]=str(N_List[k])
	print(" ".join(N_List))
	print(cnt)

if __name__=='__main__':
	main() def bubble_sort(List):
	cnt=0
	l=len(List)
	for i in range(l):
		for j in range(l-1,i,-1):
			if List[j]<List[j-1]:
				temp=List[j]
				List[j]=List[j-1]
				List[j-1]=temp
				cnt+=1
	return cnt bubble_sort cnt=0 cnt 0 l=len(List) l len(List) len List for i in range(l):
		for j in range(l-1,i,-1):
			if List[j]<List[j-1]:
				temp=List[j]
				List[j]=List[j-1]
				List[j-1]=temp
				cnt+=1
	 i range(l) range l for j in range(l-1,i,-1):
			if List[j]<List[j-1]:
				temp=List[j]
				List[j]=List[j-1]
				List[j-1]=temp
				cnt+=1
	 j range(l-1,i,-1) range l-1 l 1 i -1 if List[j]<List[j-1]:
				temp=List[j]
				List[j]=List[j-1]
				List[j-1]=temp
				cnt+=1
	 List[j]<List[j-1] List[j] List j List[j-1] List j-1 j 1 temp=List[j] temp List[j] List j List[j]=List[j-1] List[j] List j List[j-1] List j-1 j 1 List[j-1]=temp List[j-1] List j-1 j 1 temp cnt+=1 cnt 1 return cnt cnt List List def main():
	N=input()
	N_List=map(int,raw_input().split())
	cnt=bubble_sort(N_List)
	for k in range(len(N_List)):
		N_List[k]=str(N_List[k])
	print(" ".join(N_List))
	print(cnt) main N=input() N input() input N_List=map(int,raw_input().split()) N_List map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split cnt=bubble_sort(N_List) cnt bubble_sort(N_List) bubble_sort N_List for k in range(len(N_List)):
		N_List[k]=str(N_List[k])
	 k range(len(N_List)) range len(N_List) len N_List N_List[k]=str(N_List[k]) N_List[k] N_List k str(N_List[k]) str N_List[k] N_List k print(" ".join(N_List)) print " ".join(N_List) " ".join " " join N_List print(cnt) print cnt if __name__=='__main__':
	main() __name__=='__main__' __name__ '__main__' main() main def bubble_sort(List):
	cnt=0
	l=len(List)
	for i in range(l):
		for j in range(l-1,i,-1):
			if List[j]<List[j-1]:
				temp=List[j]
				List[j]=List[j-1]
				List[j-1]=temp
				cnt+=1
	return cnt def bubble_sort(List):
	cnt=0
	l=len(List)
	for i in range(l):
		for j in range(l-1,i,-1):
			if List[j]<List[j-1]:
				temp=List[j]
				List[j]=List[j-1]
				List[j-1]=temp
				cnt+=1
	return cnt bubble_sort def main():
	N=input()
	N_List=map(int,raw_input().split())
	cnt=bubble_sort(N_List)
	for k in range(len(N_List)):
		N_List[k]=str(N_List[k])
	print(" ".join(N_List))
	print(cnt) def main():
	N=input()
	N_List=map(int,raw_input().split())
	cnt=bubble_sort(N_List)
	for k in range(len(N_List)):
		N_List[k]=str(N_List[k])
	print(" ".join(N_List))
	print(cnt) main
def bubble_sort(List):
	cnt=0
	l=len(List)
	for i in range(l):
		for j in range(l-1,i,-1):
			if List[j]<List[j-1]:
				temp=List[j]
				List[j]=List[j-1]
				List[j-1]=temp
				cnt+=1
	return cnt
def main():
	N=input()
	N_List=map(int,raw_input().split())
	cnt=bubble_sort(N_List)
	for k in range(len(N_List)):
		N_List[k]=str(N_List[k])
	print(" ".join(N_List))
	print(cnt)

if __name__=='__main__':
	main()