N = int(input())
l = list(map(int,input().split(' ')))

i = 0
count = 0
flag =1
while flag :
    flag = 0
    for j in range(N-1,i,-1):
        if l[j-1] > l[j]:
            l[j-1],l[j] = l[j],l[j-1]
            count +=1
            flag =1
    i+=1

print(' '.join(list(map(str,l))))
print(count)
 N = int(input()) N int(input()) int input() input l = list(map(int,input().split(' '))) l list(map(int,input().split(' '))) list map(int,input().split(' ')) map int input().split(' ') ().split () input split ' ' i = 0 i 0 count = 0 count 0 flag =1 flag 1 while flag :
    flag = 0
    for j in range(N-1,i,-1):
        if l[j-1] > l[j]:
            l[j-1],l[j] = l[j],l[j-1]
            count +=1
            flag =1
    i+=1 flag flag = 0 flag 0 for j in range(N-1,i,-1):
        if l[j-1] > l[j]:
            l[j-1],l[j] = l[j],l[j-1]
            count +=1
            flag =1
     j range(N-1,i,-1) range N-1 N 1 i -1 if l[j-1] > l[j]:
            l[j-1],l[j] = l[j],l[j-1]
            count +=1
            flag =1
     l[j-1] > l[j] l[j-1] l j-1 j 1 l[j] l j l[j-1],l[j] = l[j],l[j-1] l[j-1] l j-1 j 1 l[j] l j l[j] l j l[j-1] l j-1 j 1 count +=1 count 1 flag =1 flag 1 i+=1 i 1 print(' '.join(list(map(str,l)))) print ' '.join(list(map(str,l))) ' '.join ' ' join list(map(str,l)) list map(str,l) map str l print(count) print count flag =1 1 flag l = list(map(int,input().split(' '))) list(map(int,input().split(' '))) l flag = 0 0 flag flag =1 1 flag i+=1 1 i count +=1 1 count N = int(input()) int(input()) N count = 0 0 count i = 0 0 i
N = int(input())
l = list(map(int,input().split(' ')))

i = 0
count = 0
flag =1
while flag :
    flag = 0
    for j in range(N-1,i,-1):
        if l[j-1] > l[j]:
            l[j-1],l[j] = l[j],l[j-1]
            count +=1
            flag =1
    i+=1

print(' '.join(list(map(str,l))))
print(count)

