n=int(input())
z=list(map(int,input().split()))
flag=1
a=0
cnt=0
while flag:
    flag=0

    for i in reversed(range(a,n)):
        if i ==0:
            break
        if z[i]<z[i-1]:
            tmp=z[i]
            z[i]=z[i-1]
            z[i-1]=tmp
            flag=1
            cnt+=1
        
    a+=1
print(' '.join(list(map(str,z))))
print(cnt) n=int(input()) n int(input()) int input() input z=list(map(int,input().split())) z list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split flag=1 flag 1 a=0 a 0 cnt=0 cnt 0 while flag:
    flag=0

    for i in reversed(range(a,n)):
        if i ==0:
            break
        if z[i]<z[i-1]:
            tmp=z[i]
            z[i]=z[i-1]
            z[i-1]=tmp
            flag=1
            cnt+=1
        
    a+=1 flag flag=0 flag 0 for i in reversed(range(a,n)):
        if i ==0:
            break
        if z[i]<z[i-1]:
            tmp=z[i]
            z[i]=z[i-1]
            z[i-1]=tmp
            flag=1
            cnt+=1
        
     i reversed(range(a,n)) reversed range(a,n) range a n if i ==0:
            break
         i ==0 i 0 break if z[i]<z[i-1]:
            tmp=z[i]
            z[i]=z[i-1]
            z[i-1]=tmp
            flag=1
            cnt+=1
        
     z[i]<z[i-1] z[i] z i z[i-1] z i-1 i 1 tmp=z[i] tmp z[i] z i z[i]=z[i-1] z[i] z i z[i-1] z i-1 i 1 z[i-1]=tmp z[i-1] z i-1 i 1 tmp flag=1 flag 1 cnt+=1 cnt 1 a+=1 a 1 print(' '.join(list(map(str,z)))) print ' '.join(list(map(str,z))) ' '.join ' ' join list(map(str,z)) list map(str,z) map str z print(cnt) print cnt tmp=z[i] z[i] tmp cnt+=1 1 cnt flag=1 1 flag flag=0 0 flag a=0 0 a cnt=0 0 cnt n=int(input()) int(input()) n flag=1 1 flag z=list(map(int,input().split())) list(map(int,input().split())) z a+=1 1 a
n=int(input())
z=list(map(int,input().split()))
flag=1
a=0
cnt=0
while flag:
    flag=0

    for i in reversed(range(a,n)):
        if i ==0:
            break
        if z[i]<z[i-1]:
            tmp=z[i]
            z[i]=z[i-1]
            z[i-1]=tmp
            flag=1
            cnt+=1
        
    a+=1
print(' '.join(list(map(str,z))))
print(cnt)