n = int(input())
s = list(map(int, input().strip().split(' ')))
e = int()
e = 0
flag = True
while flag:
        flag = False
        for i in range(n - 1, 0, -1):
            if s[i] < s[i - 1]:
                s[i - 1], s[i] = s[i], s[i - 1]
                e = e + 1
                flag = True

for i in range(0 , len(s)):
    if i != len(s) - 1:
        print(s[i], end=" ")
    else:
        print(s[i])

print(e)
 n = int(input()) n int(input()) int input() input s = list(map(int, input().strip().split(' '))) s list(map(int, input().strip().split(' '))) list map(int, input().strip().split(' ')) map int input().strip().split(' ') ().strip().split ().strip() ().strip () input strip split ' ' e = int() e int() int e = 0 e 0 flag = True flag True while flag:
        flag = False
        for i in range(n - 1, 0, -1):
            if s[i] < s[i - 1]:
                s[i - 1], s[i] = s[i], s[i - 1]
                e = e + 1
                flag = True flag flag = False flag False for i in range(n - 1, 0, -1):
            if s[i] < s[i - 1]:
                s[i - 1], s[i] = s[i], s[i - 1]
                e = e + 1
                flag = True i range(n - 1, 0, -1) range n - 1 n 1 0 -1 if s[i] < s[i - 1]:
                s[i - 1], s[i] = s[i], s[i - 1]
                e = e + 1
                flag = True s[i] < s[i - 1] s[i] s i s[i - 1] s i - 1 i 1 s[i - 1], s[i] = s[i], s[i - 1] s[i - 1] s i - 1 i 1 s[i] s i s[i] s i s[i - 1] s i - 1 i 1 e = e + 1 e e + 1 e 1 flag = True flag True for i in range(0 , len(s)):
    if i != len(s) - 1:
        print(s[i], end=" ")
    else:
        print(s[i]) i range(0 , len(s)) range 0 len(s) len s if i != len(s) - 1:
        print(s[i], end=" ")
    else:
        print(s[i]) i != len(s) - 1 i len(s) - 1 len(s) len s 1 print(s[i], end=" ") print s[i] s i end=" " end " " print(s[i]) print s[i] s i print(e) print e flag = True True flag e = 0 0 e s = list(map(int, input().strip().split(' '))) list(map(int, input().strip().split(' '))) s e = int() int() e flag = False False flag e = e + 1 e + 1 e flag = True True flag n = int(input()) int(input()) n
n = int(input())
s = list(map(int, input().strip().split(' ')))
e = int()
e = 0
flag = True
while flag:
        flag = False
        for i in range(n - 1, 0, -1):
            if s[i] < s[i - 1]:
                s[i - 1], s[i] = s[i], s[i - 1]
                e = e + 1
                flag = True

for i in range(0 , len(s)):
    if i != len(s) - 1:
        print(s[i], end=" ")
    else:
        print(s[i])

print(e)

