N = int(raw_input())
A = raw_input().split(" ")
count = 0
flag = 1

i = 0
while flag == 1:
    flag = 0
    for j in reversed(range(i+1, N)):
        if int(A[j]) < int(A[j-1]):
            temp = A[j]
            A[j] = A[j-1]
            A[j-1] = temp
            count += 1
            flag = 1
    i += 1
    
print " ".join(A)
print count N = int(raw_input()) N int(raw_input()) int raw_input() raw_input A = raw_input().split(" ") A raw_input().split(" ") ().split () raw_input split " " count = 0 count 0 flag = 1 flag 1 i = 0 i 0 while flag == 1:
    flag = 0
    for j in reversed(range(i+1, N)):
        if int(A[j]) < int(A[j-1]):
            temp = A[j]
            A[j] = A[j-1]
            A[j-1] = temp
            count += 1
            flag = 1
    i += 1
     flag == 1 flag 1 flag = 0 flag 0 for j in reversed(range(i+1, N)):
        if int(A[j]) < int(A[j-1]):
            temp = A[j]
            A[j] = A[j-1]
            A[j-1] = temp
            count += 1
            flag = 1
     j reversed(range(i+1, N)) reversed range(i+1, N) range i+1 i 1 N if int(A[j]) < int(A[j-1]):
            temp = A[j]
            A[j] = A[j-1]
            A[j-1] = temp
            count += 1
            flag = 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 temp = A[j] temp A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = temp A[j-1] A j-1 j 1 temp count += 1 count 1 flag = 1 flag 1 i += 1 i 1 print " ".join(A) " ".join " " join A print flag = 1 1 flag temp = A[j] A[j] temp i = 0 0 i count += 1 1 count flag = 0 0 flag N = int(raw_input()) int(raw_input()) N count = 0 0 count A = raw_input().split(" ") raw_input().split(" ") A flag = 1 1 flag i += 1 1 i
N = int(raw_input())
A = raw_input().split(" ")
count = 0
flag = 1

i = 0
while flag == 1:
    flag = 0
    for j in reversed(range(i+1, N)):
        if int(A[j]) < int(A[j-1]):
            temp = A[j]
            A[j] = A[j-1]
            A[j-1] = temp
            count += 1
            flag = 1
    i += 1
    
print " ".join(A)
print count