#coding:UTF-8
def BS(N,A):
    count=0
    flag=True
    while flag==True:
        flag=False
        for i in range(1,N):
            if A[N-i]<A[N-i-1]:
                swap=A[N-i]
                A[N-i]=A[N-i-1]
                A[N-i-1]=swap
                flag=True
                count+=1
    for i in range(len(A)):
        A[i]=str(A[i])
    print(" ".join(A))
    print(count)

if __name__=="__main__":
    N=int(input())
    a=input()
    A=a.split(" ")
    for i in range(len(A)):
        A[i]=int(A[i])
    BS(N,A) def BS(N,A):
    count=0
    flag=True
    while flag==True:
        flag=False
        for i in range(1,N):
            if A[N-i]<A[N-i-1]:
                swap=A[N-i]
                A[N-i]=A[N-i-1]
                A[N-i-1]=swap
                flag=True
                count+=1
    for i in range(len(A)):
        A[i]=str(A[i])
    print(" ".join(A))
    print(count) BS count=0 count 0 flag=True flag True while flag==True:
        flag=False
        for i in range(1,N):
            if A[N-i]<A[N-i-1]:
                swap=A[N-i]
                A[N-i]=A[N-i-1]
                A[N-i-1]=swap
                flag=True
                count+=1
     flag==True flag True flag=False flag False for i in range(1,N):
            if A[N-i]<A[N-i-1]:
                swap=A[N-i]
                A[N-i]=A[N-i-1]
                A[N-i-1]=swap
                flag=True
                count+=1
     i range(1,N) range 1 N if A[N-i]<A[N-i-1]:
                swap=A[N-i]
                A[N-i]=A[N-i-1]
                A[N-i-1]=swap
                flag=True
                count+=1
     A[N-i]<A[N-i-1] A[N-i] A N-i N i A[N-i-1] A N-i-1 N-i N i 1 swap=A[N-i] swap A[N-i] A N-i N i A[N-i]=A[N-i-1] A[N-i] A N-i N i A[N-i-1] A N-i-1 N-i N i 1 A[N-i-1]=swap A[N-i-1] A N-i-1 N-i N i 1 swap flag=True flag True count+=1 count 1 for i in range(len(A)):
        A[i]=str(A[i])
     i range(len(A)) range len(A) len A A[i]=str(A[i]) A[i] A i str(A[i]) str A[i] A i print(" ".join(A)) print " ".join(A) " ".join " " join A print(count) print count N N A A if __name__=="__main__":
    N=int(input())
    a=input()
    A=a.split(" ")
    for i in range(len(A)):
        A[i]=int(A[i])
    BS(N,A) __name__=="__main__" __name__ "__main__" N=int(input()) N int(input()) int input() input a=input() a input() input A=a.split(" ") A a.split(" ") a.split a split " " for i in range(len(A)):
        A[i]=int(A[i])
     i range(len(A)) range len(A) len A A[i]=int(A[i]) A[i] A i int(A[i]) int A[i] A i BS(N,A) BS N A A=a.split(" ") a.split(" ") A a=input() input() a def BS(N,A):
    count=0
    flag=True
    while flag==True:
        flag=False
        for i in range(1,N):
            if A[N-i]<A[N-i-1]:
                swap=A[N-i]
                A[N-i]=A[N-i-1]
                A[N-i-1]=swap
                flag=True
                count+=1
    for i in range(len(A)):
        A[i]=str(A[i])
    print(" ".join(A))
    print(count) def BS(N,A):
    count=0
    flag=True
    while flag==True:
        flag=False
        for i in range(1,N):
            if A[N-i]<A[N-i-1]:
                swap=A[N-i]
                A[N-i]=A[N-i-1]
                A[N-i-1]=swap
                flag=True
                count+=1
    for i in range(len(A)):
        A[i]=str(A[i])
    print(" ".join(A))
    print(count) BS N=int(input()) int(input()) N
#coding:UTF-8
def BS(N,A):
    count=0
    flag=True
    while flag==True:
        flag=False
        for i in range(1,N):
            if A[N-i]<A[N-i-1]:
                swap=A[N-i]
                A[N-i]=A[N-i-1]
                A[N-i-1]=swap
                flag=True
                count+=1
    for i in range(len(A)):
        A[i]=str(A[i])
    print(" ".join(A))
    print(count)

if __name__=="__main__":
    N=int(input())
    a=input()
    A=a.split(" ")
    for i in range(len(A)):
        A[i]=int(A[i])
    BS(N,A)