# coding: utf-8
# Here your code !
S = int(input())
N = list(map(int,input().split()))
count=0
def bubblesort(n,s):
    global count
    flag = 1
    while flag:
        flag = 0
        for i in range(s-1,0,-1):
            key = n[i]
            if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
    print(" ".join(list(map(str,n))))
    print(count)
        
bubblesort(N,S) S = int(input()) S int(input()) int input() input N = list(map(int,input().split())) N list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split count=0 count 0 def bubblesort(n,s):
    global count
    flag = 1
    while flag:
        flag = 0
        for i in range(s-1,0,-1):
            key = n[i]
            if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
    print(" ".join(list(map(str,n))))
    print(count)
         bubblesort global count flag = 1 flag 1 while flag:
        flag = 0
        for i in range(s-1,0,-1):
            key = n[i]
            if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
     flag flag = 0 flag 0 for i in range(s-1,0,-1):
            key = n[i]
            if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
     i range(s-1,0,-1) range s-1 s 1 0 -1 key = n[i] key n[i] n i if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
     n[i]<n[i-1] n[i] n i n[i-1] n i-1 i 1 n[i]=n[i-1] n[i] n i n[i-1] n i-1 i 1 n[i-1]=key n[i-1] n i-1 i 1 key count+=1 count 1 flag=1 flag 1 print(" ".join(list(map(str,n)))) print " ".join(list(map(str,n))) " ".join " " join list(map(str,n)) list map(str,n) map str n print(count) print count n n s s bubblesort(N,S) bubblesort N S N = list(map(int,input().split())) list(map(int,input().split())) N def bubblesort(n,s):
    global count
    flag = 1
    while flag:
        flag = 0
        for i in range(s-1,0,-1):
            key = n[i]
            if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
    print(" ".join(list(map(str,n))))
    print(count)
         def bubblesort(n,s):
    global count
    flag = 1
    while flag:
        flag = 0
        for i in range(s-1,0,-1):
            key = n[i]
            if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
    print(" ".join(list(map(str,n))))
    print(count)
         bubblesort count=0 0 count S = int(input()) int(input()) S
# coding: utf-8
# Here your code !
S = int(input())
N = list(map(int,input().split()))
count=0
def bubblesort(n,s):
    global count
    flag = 1
    while flag:
        flag = 0
        for i in range(s-1,0,-1):
            key = n[i]
            if n[i]<n[i-1]:
                n[i]=n[i-1]
                n[i-1]=key
                count+=1
                flag=1
    print(" ".join(list(map(str,n))))
    print(count)
        
bubblesort(N,S)