def bubbleSort(A, N):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
    return swap
N = int(input())
A = list(map(int,input().split()))
swap=bubbleSort(A,N)
print(" ".join(map(str,A)))
print (swap) def bubbleSort(A, N):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
    return swap bubbleSort swap = 0 swap 0 flag = True flag True while flag:
        flag = False
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
     flag flag = False flag False for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
     j range(N-1,0,-1) range N-1 N 1 0 -1 if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j],A[j-1] = A[j-1],A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j swap += 1 swap 1 flag = True flag True return swap swap A A N N N = int(input()) N int(input()) int input() input A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split swap=bubbleSort(A,N) swap bubbleSort(A,N) bubbleSort A N print(" ".join(map(str,A))) print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print (swap) print swap N = int(input()) int(input()) N A = list(map(int,input().split())) list(map(int,input().split())) A def bubbleSort(A, N):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
    return swap def bubbleSort(A, N):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
    return swap bubbleSort swap=bubbleSort(A,N) bubbleSort(A,N) swap
def bubbleSort(A, N):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
    return swap
N = int(input())
A = list(map(int,input().split()))
swap=bubbleSort(A,N)
print(" ".join(map(str,A)))
print (swap)