n = int(input())
a = [int(x) for x in input().split()]
c = 0
for x in range(n):
    for i in range(n-1, x, -1):
        if a[i] < a[i-1]:
            a[i], a[i-1] = a[i-1], a[i]
            c += 1
print(*a)
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()] c = 0 c 0 for x in range(n):
    for i in range(n-1, x, -1):
        if a[i] < a[i-1]:
            a[i], a[i-1] = a[i-1], a[i]
            c += 1 x range(n) range n for i in range(n-1, x, -1):
        if a[i] < a[i-1]:
            a[i], a[i-1] = a[i-1], a[i]
            c += 1 i range(n-1, x, -1) range n-1 n 1 x -1 if a[i] < a[i-1]:
            a[i], a[i-1] = a[i-1], a[i]
            c += 1 a[i] < a[i-1] a[i] a i a[i-1] a i-1 i 1 a[i], a[i-1] = a[i-1], a[i] a[i] a i a[i-1] a i-1 i 1 a[i-1] a i-1 i 1 a[i] a i c += 1 c 1 print(*a) print *a a print(c) print c c = 0 0 c n = int(input()) int(input()) n c += 1 1 c 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()]
c = 0
for x in range(n):
    for i in range(n-1, x, -1):
        if a[i] < a[i-1]:
            a[i], a[i-1] = a[i-1], a[i]
            c += 1
print(*a)
print(c)