#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A

x = int(input())
y = list(map(int,input().split()))
z = 0

flag = 1
while flag:
	flag = 0
	i = x - 1
	while i > 0:
		if y[i] < y[i - 1]:
			y[i], y[i - 1] = y[i - 1], y[i]
			flag = 1
			z += 1
		i -= 1

print(" ".join(list(map(str,y))))
print(z) x = int(input()) x int(input()) int input() input y = list(map(int,input().split())) y list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split z = 0 z 0 flag = 1 flag 1 while flag:
	flag = 0
	i = x - 1
	while i > 0:
		if y[i] < y[i - 1]:
			y[i], y[i - 1] = y[i - 1], y[i]
			flag = 1
			z += 1
		i -= 1 flag flag = 0 flag 0 i = x - 1 i x - 1 x 1 while i > 0:
		if y[i] < y[i - 1]:
			y[i], y[i - 1] = y[i - 1], y[i]
			flag = 1
			z += 1
		i -= 1 i > 0 i 0 if y[i] < y[i - 1]:
			y[i], y[i - 1] = y[i - 1], y[i]
			flag = 1
			z += 1
		 y[i] < y[i - 1] y[i] y i y[i - 1] y i - 1 i 1 y[i], y[i - 1] = y[i - 1], y[i] y[i] y i y[i - 1] y i - 1 i 1 y[i - 1] y i - 1 i 1 y[i] y i flag = 1 flag 1 z += 1 z 1 i -= 1 i 1 print(" ".join(list(map(str,y)))) print " ".join(list(map(str,y))) " ".join " " join list(map(str,y)) list map(str,y) map str y print(z) print z y = list(map(int,input().split())) list(map(int,input().split())) y x = int(input()) int(input()) x flag = 1 1 flag z += 1 1 z i -= 1 1 i flag = 1 1 flag z = 0 0 z flag = 0 0 flag i = x - 1 x - 1 i
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A

x = int(input())
y = list(map(int,input().split()))
z = 0

flag = 1
while flag:
	flag = 0
	i = x - 1
	while i > 0:
		if y[i] < y[i - 1]:
			y[i], y[i - 1] = y[i - 1], y[i]
			flag = 1
			z += 1
		i -= 1

print(" ".join(list(map(str,y))))
print(z)