import sys

lines = sys.stdin.readlines()

N = lines[0]
A = lines[1].strip().split(" ")

flag = 1

c = 0
i = 0
while flag == 1:
    flag = 0
    for j in reversed(range(i+1,len(A))):
        if int(A[j]) < int(A[j-1]):
            a = A[j]
            b = A[j-1]
            A[j] = b
            A[j-1] = a
            flag = 1
            c += 1
    i += 1

print " ".join(A)
print c import sys sys lines = sys.stdin.readlines() lines sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines N = lines[0] N lines[0] lines 0 A = lines[1].strip().split(" ") A lines[1].strip().split(" ") [1].strip().split [1].strip() [1].strip [1] lines 1 strip split " " flag = 1 flag 1 c = 0 c 0 i = 0 i 0 while flag == 1:
    flag = 0
    for j in reversed(range(i+1,len(A))):
        if int(A[j]) < int(A[j-1]):
            a = A[j]
            b = A[j-1]
            A[j] = b
            A[j-1] = a
            flag = 1
            c += 1
    i += 1 flag == 1 flag 1 flag = 0 flag 0 for j in reversed(range(i+1,len(A))):
        if int(A[j]) < int(A[j-1]):
            a = A[j]
            b = A[j-1]
            A[j] = b
            A[j-1] = a
            flag = 1
            c += 1
     j reversed(range(i+1,len(A))) reversed range(i+1,len(A)) range i+1 i 1 len(A) len A if int(A[j]) < int(A[j-1]):
            a = A[j]
            b = A[j-1]
            A[j] = b
            A[j-1] = a
            flag = 1
            c += 1
     int(A[j]) < int(A[j-1]) int(A[j]) int A[j] A j int(A[j-1]) int A[j-1] A j-1 j 1 a = A[j] a A[j] A j b = A[j-1] b A[j-1] A j-1 j 1 A[j] = b A[j] A j b A[j-1] = a A[j-1] A j-1 j 1 a flag = 1 flag 1 c += 1 c 1 i += 1 i 1 print " ".join(A) " ".join " " join A print A = lines[1].strip().split(" ") lines[1].strip().split(" ") A b = A[j-1] A[j-1] b c = 0 0 c c += 1 1 c a = A[j] A[j] a flag = 0 0 flag flag = 1 1 flag flag = 1 1 flag i += 1 1 i i = 0 0 i lines = sys.stdin.readlines() sys.stdin.readlines() lines N = lines[0] lines[0] N
import sys

lines = sys.stdin.readlines()

N = lines[0]
A = lines[1].strip().split(" ")

flag = 1

c = 0
i = 0
while flag == 1:
    flag = 0
    for j in reversed(range(i+1,len(A))):
        if int(A[j]) < int(A[j-1]):
            a = A[j]
            b = A[j-1]
            A[j] = b
            A[j-1] = a
            flag = 1
            c += 1
    i += 1

print " ".join(A)
print c