N = int(raw_input())
A = map(int, raw_input().split())

def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                temp = A[i]
                A[i] = A[i-1]
                A[i-1] = temp
                flag = 1
                count += 1
    return count

count = bubbleSort(A, N)

print " ".join(map(str, A))
print count N = int(raw_input()) N int(raw_input()) int raw_input() raw_input A = map(int, raw_input().split()) A map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                temp = A[i]
                A[i] = A[i-1]
                A[i-1] = temp
                flag = 1
                count += 1
    return count bubbleSort count = 0 count 0 flag = 1 flag 1 while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                temp = A[i]
                A[i] = A[i-1]
                A[i-1] = temp
                flag = 1
                count += 1
     flag flag = 0 flag 0 for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                temp = A[i]
                A[i] = A[i-1]
                A[i-1] = temp
                flag = 1
                count += 1
     i range(N-1, 0, -1) range N-1 N 1 0 -1 if A[i] < A[i-1]:
                temp = A[i]
                A[i] = A[i-1]
                A[i-1] = temp
                flag = 1
                count += 1
     A[i] < A[i-1] A[i] A i A[i-1] A i-1 i 1 temp = A[i] temp A[i] A i A[i] = A[i-1] A[i] A i A[i-1] A i-1 i 1 A[i-1] = temp A[i-1] A i-1 i 1 temp flag = 1 flag 1 count += 1 count 1 return count count A A N N count = bubbleSort(A, N) count bubbleSort(A, N) bubbleSort A N print " ".join(map(str, A)) " ".join " " join map(str, A) map str A print def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                temp = A[i]
                A[i] = A[i-1]
                A[i-1] = temp
                flag = 1
                count += 1
    return count def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                temp = A[i]
                A[i] = A[i-1]
                A[i-1] = temp
                flag = 1
                count += 1
    return count bubbleSort A = map(int, raw_input().split()) map(int, raw_input().split()) A count = bubbleSort(A, N) bubbleSort(A, N) count N = int(raw_input()) int(raw_input()) N
N = int(raw_input())
A = map(int, raw_input().split())

def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                temp = A[i]
                A[i] = A[i-1]
                A[i-1] = temp
                flag = 1
                count += 1
    return count

count = bubbleSort(A, N)

print " ".join(map(str, A))
print count