def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in reversed(xrange(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count+=1
    return count

# MAIN
N = input()
A = map(int, raw_input().split())
c = bubbleSort(A, N)
for i in A: print i,
print 
print c def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in reversed(xrange(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count+=1
    return count

# MAIN bubbleSort flag = 1 flag 1 count = 0 count 0 while flag:
        flag = 0
        for j in reversed(xrange(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count+=1
     flag flag = 0 flag 0 for j in reversed(xrange(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count+=1
     j reversed(xrange(1, N)) reversed xrange(1, N) xrange 1 N if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count+=1
     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 flag = 1 flag 1 count+=1 count 1 return count count A A N N N = input() N input() input A = map(int, raw_input().split()) A map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split c = bubbleSort(A, N) c bubbleSort(A, N) bubbleSort A N for i in A: print i A i print print c = bubbleSort(A, N) bubbleSort(A, N) c A = map(int, raw_input().split()) map(int, raw_input().split()) A def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in reversed(xrange(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count+=1
    return count

# MAIN def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in reversed(xrange(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count+=1
    return count

# MAIN bubbleSort N = input() input() N
def bubbleSort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in reversed(xrange(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count+=1
    return count

# MAIN
N = input()
A = map(int, raw_input().split())
c = bubbleSort(A, N)
for i in A: print i,
print 
print c