n = int(input())
R = [int(x) for x in input().split()]
time = 0
flag = True
while flag:
     flag = False
     for i in reversed(range(n-1)):
        if R[i+1] < R[i]:
            R[i], R[i+1] = R[i+1], R[i]
            flag = True
            time += 1 
print(*R)
print(time) 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 R = [int(x) for x in input().split()] R [int(x) for x in input().split()] time = 0 time 0 flag = True flag True while flag:
     flag = False
     for i in reversed(range(n-1)):
        if R[i+1] < R[i]:
            R[i], R[i+1] = R[i+1], R[i]
            flag = True
            time += 1  flag flag = False flag False for i in reversed(range(n-1)):
        if R[i+1] < R[i]:
            R[i], R[i+1] = R[i+1], R[i]
            flag = True
            time += 1  i reversed(range(n-1)) reversed range(n-1) range n-1 n 1 if R[i+1] < R[i]:
            R[i], R[i+1] = R[i+1], R[i]
            flag = True
            time += 1  R[i+1] < R[i] R[i+1] R i+1 i 1 R[i] R i R[i], R[i+1] = R[i+1], R[i] R[i] R i R[i+1] R i+1 i 1 R[i+1] R i+1 i 1 R[i] R i flag = True flag True time += 1 time 1 print(*R) print *R R print(time) print time flag = True True flag R = [int(x) for x in input().split()] [int(x) for x in input().split()] R flag = True True flag time += 1 1 time n = int(input()) int(input()) n flag = False False flag time = 0 0 time
n = int(input())
R = [int(x) for x in input().split()]
time = 0
flag = True
while flag:
     flag = False
     for i in reversed(range(n-1)):
        if R[i+1] < R[i]:
            R[i], R[i+1] = R[i+1], R[i]
            flag = True
            time += 1 
print(*R)
print(time)