# Bubble Sort
n = int(input())
line = [int(i) for i in input().rstrip().split()]
# print(line)

count = 0
for i in range(n - 1):
    a = n - 1
    while a > i:
        if line[a - 1] > line[a]:
            line[a - 1], line[a] = line[a], line[a - 1]
            # print(line)
            count += 1
        a -= 1

for i in range(n):
    print(line[i], end = "")
    if i < n - 1:
        print(" ", end = "")
print()
# print(line)
print(count)
 n = int(input()) n int(input()) int input() input int(i) for i in input().rstrip().split() for i in input().rstrip().split() i input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split for i in input().rstrip().split() int(i) int i line = [int(i) for i in input().rstrip().split()] line [int(i) for i in input().rstrip().split()] count = 0 count 0 for i in range(n - 1):
    a = n - 1
    while a > i:
        if line[a - 1] > line[a]:
            line[a - 1], line[a] = line[a], line[a - 1]
            # print(line)
            count += 1
        a -= 1 i range(n - 1) range n - 1 n 1 a = n - 1 a n - 1 n 1 while a > i:
        if line[a - 1] > line[a]:
            line[a - 1], line[a] = line[a], line[a - 1]
            # print(line)
            count += 1
        a -= 1 a > i a i if line[a - 1] > line[a]:
            line[a - 1], line[a] = line[a], line[a - 1]
            # print(line)
            count += 1
         line[a - 1] > line[a] line[a - 1] line a - 1 a 1 line[a] line a line[a - 1], line[a] = line[a], line[a - 1] line[a - 1] line a - 1 a 1 line[a] line a line[a] line a line[a - 1] line a - 1 a 1 count += 1 count 1 a -= 1 a 1 for i in range(n):
    print(line[i], end = "")
    if i < n - 1:
        print(" ", end = "") i range(n) range n print(line[i], end = "") print line[i] line i end = "" end "" if i < n - 1:
        print(" ", end = "") i < n - 1 i n - 1 n 1 print(" ", end = "") print " " end = "" end "" print() print print(count) print count a = n - 1 n - 1 a n = int(input()) int(input()) n count = 0 0 count count += 1 1 count line = [int(i) for i in input().rstrip().split()] [int(i) for i in input().rstrip().split()] line a -= 1 1 a
# Bubble Sort
n = int(input())
line = [int(i) for i in input().rstrip().split()]
# print(line)

count = 0
for i in range(n - 1):
    a = n - 1
    while a > i:
        if line[a - 1] > line[a]:
            line[a - 1], line[a] = line[a], line[a - 1]
            # print(line)
            count += 1
        a -= 1

for i in range(n):
    print(line[i], end = "")
    if i < n - 1:
        print(" ", end = "")
print()
# print(line)
print(count)

