def bubble_sort(a,n):
    m=0
    flag=True
    while(flag):
        flag=False
        for i in range(n-1,0,-1):
            if(a[i-1] > a[i]):
                tmp=a[i-1]
                a[i-1]=a[i]
                m+=1
                a[i]=tmp
                flag=True
                
    b=list(map(str,a))
    print(" ".join(b))
    print(m)

a=[]
n=int(input())
s=input()
a=list(map(int,s.split()))
bubble_sort(a,n) def bubble_sort(a,n):
    m=0
    flag=True
    while(flag):
        flag=False
        for i in range(n-1,0,-1):
            if(a[i-1] > a[i]):
                tmp=a[i-1]
                a[i-1]=a[i]
                m+=1
                a[i]=tmp
                flag=True
                
    b=list(map(str,a))
    print(" ".join(b))
    print(m) bubble_sort m=0 m 0 flag=True flag True while(flag):
        flag=False
        for i in range(n-1,0,-1):
            if(a[i-1] > a[i]):
                tmp=a[i-1]
                a[i-1]=a[i]
                m+=1
                a[i]=tmp
                flag=True
                
     flag flag=False flag False for i in range(n-1,0,-1):
            if(a[i-1] > a[i]):
                tmp=a[i-1]
                a[i-1]=a[i]
                m+=1
                a[i]=tmp
                flag=True
                
     i range(n-1,0,-1) range n-1 n 1 0 -1 if(a[i-1] > a[i]):
                tmp=a[i-1]
                a[i-1]=a[i]
                m+=1
                a[i]=tmp
                flag=True
                
     a[i-1] > a[i] a[i-1] a i-1 i 1 a[i] a i tmp=a[i-1] tmp a[i-1] a i-1 i 1 a[i-1]=a[i] a[i-1] a i-1 i 1 a[i] a i m+=1 m 1 a[i]=tmp a[i] a i tmp flag=True flag True b=list(map(str,a)) b list(map(str,a)) list map(str,a) map str a print(" ".join(b)) print " ".join(b) " ".join " " join b print(m) print m a a n n a=[] a [] n=int(input()) n int(input()) int input() input s=input() s input() input a=list(map(int,s.split())) a list(map(int,s.split())) list map(int,s.split()) map int s.split() s.split s split bubble_sort(a,n) bubble_sort a n n=int(input()) int(input()) n a=[] [] a a=list(map(int,s.split())) list(map(int,s.split())) a def bubble_sort(a,n):
    m=0
    flag=True
    while(flag):
        flag=False
        for i in range(n-1,0,-1):
            if(a[i-1] > a[i]):
                tmp=a[i-1]
                a[i-1]=a[i]
                m+=1
                a[i]=tmp
                flag=True
                
    b=list(map(str,a))
    print(" ".join(b))
    print(m) def bubble_sort(a,n):
    m=0
    flag=True
    while(flag):
        flag=False
        for i in range(n-1,0,-1):
            if(a[i-1] > a[i]):
                tmp=a[i-1]
                a[i-1]=a[i]
                m+=1
                a[i]=tmp
                flag=True
                
    b=list(map(str,a))
    print(" ".join(b))
    print(m) bubble_sort s=input() input() s
def bubble_sort(a,n):
    m=0
    flag=True
    while(flag):
        flag=False
        for i in range(n-1,0,-1):
            if(a[i-1] > a[i]):
                tmp=a[i-1]
                a[i-1]=a[i]
                m+=1
                a[i]=tmp
                flag=True
                
    b=list(map(str,a))
    print(" ".join(b))
    print(m)

a=[]
n=int(input())
s=input()
a=list(map(int,s.split()))
bubble_sort(a,n)