N = int(input())
a = [int(x) for x in input().split()]
def bubbleSort(A, N):
	flag = 1
	count = 0
	while flag:
		flag = 0
		for j in reversed(range(1,N)):
			if A[j] < A[j-1]:
				tmp = A[j]
				A[j] = A[j-1]
				A[j-1] = tmp
				flag = 1
				count += 1
	return A,count
ans,c = bubbleSort(a,N)
print(*ans)
print(c) N = int(input()) N int(input()) int input() input int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x a = [int(x) for x in input().split()] a [int(x) for x in input().split()] def bubbleSort(A, N):
	flag = 1
	count = 0
	while flag:
		flag = 0
		for j in reversed(range(1,N)):
			if A[j] < A[j-1]:
				tmp = A[j]
				A[j] = A[j-1]
				A[j-1] = tmp
				flag = 1
				count += 1
	return A,count bubbleSort flag = 1 flag 1 count = 0 count 0 while flag:
		flag = 0
		for j in reversed(range(1,N)):
			if A[j] < A[j-1]:
				tmp = A[j]
				A[j] = A[j-1]
				A[j-1] = tmp
				flag = 1
				count += 1
	 flag flag = 0 flag 0 for j in reversed(range(1,N)):
			if A[j] < A[j-1]:
				tmp = A[j]
				A[j] = A[j-1]
				A[j-1] = tmp
				flag = 1
				count += 1
	 j reversed(range(1,N)) reversed range(1,N) range 1 N if A[j] < A[j-1]:
				tmp = A[j]
				A[j] = A[j-1]
				A[j-1] = tmp
				flag = 1
				count += 1
	 A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 tmp = A[j] tmp A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = tmp A[j-1] A j-1 j 1 tmp flag = 1 flag 1 count += 1 count 1 return A,count return A,count A count A A N N ans,c = bubbleSort(a,N) ans bubbleSort(a,N) bubbleSort a N c print(*ans) print *ans ans print(c) print c def bubbleSort(A, N):
	flag = 1
	count = 0
	while flag:
		flag = 0
		for j in reversed(range(1,N)):
			if A[j] < A[j-1]:
				tmp = A[j]
				A[j] = A[j-1]
				A[j-1] = tmp
				flag = 1
				count += 1
	return A,count def bubbleSort(A, N):
	flag = 1
	count = 0
	while flag:
		flag = 0
		for j in reversed(range(1,N)):
			if A[j] < A[j-1]:
				tmp = A[j]
				A[j] = A[j-1]
				A[j-1] = tmp
				flag = 1
				count += 1
	return A,count bubbleSort c = bubbleSort(a,N) bubbleSort(a,N) c N = int(input()) int(input()) N ans,c = bubbleSort(a,N) bubbleSort(a,N) ans a = [int(x) for x in input().split()] [int(x) for x in input().split()] a
N = int(input())
a = [int(x) for x in input().split()]
def bubbleSort(A, N):
	flag = 1
	count = 0
	while flag:
		flag = 0
		for j in reversed(range(1,N)):
			if A[j] < A[j-1]:
				tmp = A[j]
				A[j] = A[j-1]
				A[j-1] = tmp
				flag = 1
				count += 1
	return A,count
ans,c = bubbleSort(a,N)
print(*ans)
print(c)