def bubbleSort(A, N):
    flag = 1
    i = 0
    swapnum = 0
    while flag:
        flag = 0
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                swapnum += 1
                flag = 1
        i = i + 1
    return swapnum
def showlist(A):
    for i in range(len(A)):
        if i==len(A)-1:
            print(A[i])
        else:
            print(A[i], end=' ')
N = eval(input())
A = list(map(int, input().split()))
swapnum = bubbleSort(A, N)
showlist(A)
print(swapnum) def bubbleSort(A, N):
    flag = 1
    i = 0
    swapnum = 0
    while flag:
        flag = 0
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                swapnum += 1
                flag = 1
        i = i + 1
    return swapnum bubbleSort flag = 1 flag 1 i = 0 i 0 swapnum = 0 swapnum 0 while flag:
        flag = 0
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                swapnum += 1
                flag = 1
        i = i + 1
     flag flag = 0 flag 0 for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                swapnum += 1
                flag = 1
         j range(N-1, i, -1) range N-1 N 1 i -1 if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                swapnum += 1
                flag = 1
         A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 temp = A[j-1] temp A[j-1] A j-1 j 1 A[j-1] = A[j] A[j-1] A j-1 j 1 A[j] A j A[j] = temp A[j] A j temp swapnum += 1 swapnum 1 flag = 1 flag 1 i = i + 1 i i + 1 i 1 return swapnum swapnum A A N N def showlist(A):
    for i in range(len(A)):
        if i==len(A)-1:
            print(A[i])
        else:
            print(A[i], end=' ') showlist for i in range(len(A)):
        if i==len(A)-1:
            print(A[i])
        else:
            print(A[i], end=' ') i range(len(A)) range len(A) len A if i==len(A)-1:
            print(A[i])
        else:
            print(A[i], end=' ') i==len(A)-1 i len(A)-1 len(A) len A 1 print(A[i]) print A[i] A i print(A[i], end=' ') print A[i] A i end=' ' end ' ' A A N = eval(input()) N eval(input()) eval 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 swapnum = bubbleSort(A, N) swapnum bubbleSort(A, N) bubbleSort A N showlist(A) showlist A print(swapnum) print swapnum def showlist(A):
    for i in range(len(A)):
        if i==len(A)-1:
            print(A[i])
        else:
            print(A[i], end=' ') def showlist(A):
    for i in range(len(A)):
        if i==len(A)-1:
            print(A[i])
        else:
            print(A[i], end=' ') showlist A = list(map(int, input().split())) list(map(int, input().split())) A swapnum = bubbleSort(A, N) bubbleSort(A, N) swapnum def bubbleSort(A, N):
    flag = 1
    i = 0
    swapnum = 0
    while flag:
        flag = 0
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                swapnum += 1
                flag = 1
        i = i + 1
    return swapnum def bubbleSort(A, N):
    flag = 1
    i = 0
    swapnum = 0
    while flag:
        flag = 0
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                swapnum += 1
                flag = 1
        i = i + 1
    return swapnum bubbleSort N = eval(input()) eval(input()) N
def bubbleSort(A, N):
    flag = 1
    i = 0
    swapnum = 0
    while flag:
        flag = 0
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                temp = A[j-1]
                A[j-1] = A[j]
                A[j] = temp
                swapnum += 1
                flag = 1
        i = i + 1
    return swapnum
def showlist(A):
    for i in range(len(A)):
        if i==len(A)-1:
            print(A[i])
        else:
            print(A[i], end=' ')
N = eval(input())
A = list(map(int, input().split()))
swapnum = bubbleSort(A, N)
showlist(A)
print(swapnum)
