n = int(input())

a = list(map(int,input().split()))

flag = 1
i = 0
count = 0

while flag:
    flag = 0
    for j in range(n-1,i,-1):
        if a[j] < a[j-1]:
            a[j],a[j-1] = a[j-1],a[j]
            count += 1
        flag = 1
        
    i += 1

for w in range(n):
    if w != n-1:
        print(a[w],end=" ")
    else:
        print(a[w])
print(count) n = int(input()) n int(input()) int input() input a = list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split flag = 1 flag 1 i = 0 i 0 count = 0 count 0 while flag:
    flag = 0
    for j in range(n-1,i,-1):
        if a[j] < a[j-1]:
            a[j],a[j-1] = a[j-1],a[j]
            count += 1
        flag = 1
        
    i += 1 flag flag = 0 flag 0 for j in range(n-1,i,-1):
        if a[j] < a[j-1]:
            a[j],a[j-1] = a[j-1],a[j]
            count += 1
        flag = 1
        
     j range(n-1,i,-1) range n-1 n 1 i -1 if a[j] < a[j-1]:
            a[j],a[j-1] = a[j-1],a[j]
            count += 1
         a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j],a[j-1] = a[j-1],a[j] a[j] a j a[j-1] a j-1 j 1 a[j-1] a j-1 j 1 a[j] a j count += 1 count 1 flag = 1 flag 1 i += 1 i 1 for w in range(n):
    if w != n-1:
        print(a[w],end=" ")
    else:
        print(a[w]) w range(n) range n if w != n-1:
        print(a[w],end=" ")
    else:
        print(a[w]) w != n-1 w n-1 n 1 print(a[w],end=" ") print a[w] a w end=" " end " " print(a[w]) print a[w] a w print(count) print count count = 0 0 count flag = 1 1 flag n = int(input()) int(input()) n flag = 0 0 flag i += 1 1 i count += 1 1 count i = 0 0 i a = list(map(int,input().split())) list(map(int,input().split())) a flag = 1 1 flag
n = int(input())

a = list(map(int,input().split()))

flag = 1
i = 0
count = 0

while flag:
    flag = 0
    for j in range(n-1,i,-1):
        if a[j] < a[j-1]:
            a[j],a[j-1] = a[j-1],a[j]
            count += 1
        flag = 1
        
    i += 1

for w in range(n):
    if w != n-1:
        print(a[w],end=" ")
    else:
        print(a[w])
print(count)