def inputInline():
    N=int(input())
    numbers=list(map(int,input().split(" ")))
    return numbers
def bubbleSort(list):
    N=len(list)
    count=0
    flag=True
    while flag:
        flag=False
        for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
    return (list,count)
result=bubbleSort(inputInline())
print(" ".join(list(map(str,result[0]))))
print(result[1]) def inputInline():
    N=int(input())
    numbers=list(map(int,input().split(" ")))
    return numbers inputInline N=int(input()) N int(input()) int input() input numbers=list(map(int,input().split(" "))) numbers list(map(int,input().split(" "))) list map(int,input().split(" ")) map int input().split(" ") ().split () input split " " return numbers numbers def bubbleSort(list):
    N=len(list)
    count=0
    flag=True
    while flag:
        flag=False
        for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
    return (list,count) bubbleSort N=len(list) N len(list) len list count=0 count 0 flag=True flag True while flag:
        flag=False
        for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
     flag flag=False flag False for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
     i range(N-1) range N-1 N 1 if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
     list[i]>list[i+1] list[i] list i list[i+1] list i+1 i 1 temp=list[i] temp list[i] list i list[i]=list[i+1] list[i] list i list[i+1] list i+1 i 1 list[i+1]=temp list[i+1] list i+1 i 1 temp flag=True flag True count+=1 count 1 return (list,count) (list,count) list count list list result=bubbleSort(inputInline()) result bubbleSort(inputInline()) bubbleSort inputInline() inputInline print(" ".join(list(map(str,result[0])))) print " ".join(list(map(str,result[0]))) " ".join " " join list(map(str,result[0])) list map(str,result[0]) map str result[0] result 0 print(result[1]) print result[1] result 1 def bubbleSort(list):
    N=len(list)
    count=0
    flag=True
    while flag:
        flag=False
        for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
    return (list,count) def bubbleSort(list):
    N=len(list)
    count=0
    flag=True
    while flag:
        flag=False
        for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
    return (list,count) bubbleSort result=bubbleSort(inputInline()) bubbleSort(inputInline()) result def inputInline():
    N=int(input())
    numbers=list(map(int,input().split(" ")))
    return numbers def inputInline():
    N=int(input())
    numbers=list(map(int,input().split(" ")))
    return numbers inputInline
def inputInline():
    N=int(input())
    numbers=list(map(int,input().split(" ")))
    return numbers
def bubbleSort(list):
    N=len(list)
    count=0
    flag=True
    while flag:
        flag=False
        for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
    return (list,count)
result=bubbleSort(inputInline())
print(" ".join(list(map(str,result[0]))))
print(result[1])