def bubbleSort(R, N):
	flag = True
	cnt = 0
	while flag == True:
		flag = False
		for j in range(N - 1, 0, -1):
			if R[j] < R[j - 1]:
				tmp = R[j]
				R[j] = R[j - 1]
				R[j - 1] = tmp
				cnt = cnt + 1
				flag = 1
	print(" ".join(map(str, R)))
	return cnt

if __name__ == '__main__':
	n = int(input())
	A = list(map(int, input().split()))
	ans = bubbleSort(A, n)
	print(ans) def bubbleSort(R, N):
	flag = True
	cnt = 0
	while flag == True:
		flag = False
		for j in range(N - 1, 0, -1):
			if R[j] < R[j - 1]:
				tmp = R[j]
				R[j] = R[j - 1]
				R[j - 1] = tmp
				cnt = cnt + 1
				flag = 1
	print(" ".join(map(str, R)))
	return cnt bubbleSort flag = True flag True cnt = 0 cnt 0 while flag == True:
		flag = False
		for j in range(N - 1, 0, -1):
			if R[j] < R[j - 1]:
				tmp = R[j]
				R[j] = R[j - 1]
				R[j - 1] = tmp
				cnt = cnt + 1
				flag = 1
	 flag == True flag True flag = False flag False for j in range(N - 1, 0, -1):
			if R[j] < R[j - 1]:
				tmp = R[j]
				R[j] = R[j - 1]
				R[j - 1] = tmp
				cnt = cnt + 1
				flag = 1
	 j range(N - 1, 0, -1) range N - 1 N 1 0 -1 if R[j] < R[j - 1]:
				tmp = R[j]
				R[j] = R[j - 1]
				R[j - 1] = tmp
				cnt = cnt + 1
				flag = 1
	 R[j] < R[j - 1] R[j] R j R[j - 1] R j - 1 j 1 tmp = R[j] tmp R[j] R j R[j] = R[j - 1] R[j] R j R[j - 1] R j - 1 j 1 R[j - 1] = tmp R[j - 1] R j - 1 j 1 tmp cnt = cnt + 1 cnt cnt + 1 cnt 1 flag = 1 flag 1 print(" ".join(map(str, R))) print " ".join(map(str, R)) " ".join " " join map(str, R) map str R return cnt cnt R R N N if __name__ == '__main__':
	n = int(input())
	A = list(map(int, input().split()))
	ans = bubbleSort(A, n)
	print(ans) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = bubbleSort(A, n) ans bubbleSort(A, n) bubbleSort A n print(ans) print ans def bubbleSort(R, N):
	flag = True
	cnt = 0
	while flag == True:
		flag = False
		for j in range(N - 1, 0, -1):
			if R[j] < R[j - 1]:
				tmp = R[j]
				R[j] = R[j - 1]
				R[j - 1] = tmp
				cnt = cnt + 1
				flag = 1
	print(" ".join(map(str, R)))
	return cnt def bubbleSort(R, N):
	flag = True
	cnt = 0
	while flag == True:
		flag = False
		for j in range(N - 1, 0, -1):
			if R[j] < R[j - 1]:
				tmp = R[j]
				R[j] = R[j - 1]
				R[j - 1] = tmp
				cnt = cnt + 1
				flag = 1
	print(" ".join(map(str, R)))
	return cnt bubbleSort n = int(input()) int(input()) n ans = bubbleSort(A, n) bubbleSort(A, n) ans A = list(map(int, input().split())) list(map(int, input().split())) A
def bubbleSort(R, N):
	flag = True
	cnt = 0
	while flag == True:
		flag = False
		for j in range(N - 1, 0, -1):
			if R[j] < R[j - 1]:
				tmp = R[j]
				R[j] = R[j - 1]
				R[j - 1] = tmp
				cnt = cnt + 1
				flag = 1
	print(" ".join(map(str, R)))
	return cnt

if __name__ == '__main__':
	n = int(input())
	A = list(map(int, input().split()))
	ans = bubbleSort(A, n)
	print(ans)