N = int(input())
A = [int(i) for i in 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]:
                tmp = A[i]
                A[i] = A[i-1]
                A[i-1] = tmp
                flag = 1
                count += 1
    return A, count

A, count = bubbleSort(A, N)
print(' '.join([str(i) for i in A]))
print(count) N = int(input()) N int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A = [int(i) for i in input().split()] A [int(i) for i in 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]:
                tmp = A[i]
                A[i] = A[i-1]
                A[i-1] = tmp
                flag = 1
                count += 1
    return A, 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]:
                tmp = A[i]
                A[i] = A[i-1]
                A[i-1] = tmp
                flag = 1
                count += 1
     flag flag = 0 flag 0 for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i-1]
                A[i-1] = tmp
                flag = 1
                count += 1
     i range(N-1, 0, -1) range N-1 N 1 0 -1 if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i-1]
                A[i-1] = tmp
                flag = 1
                count += 1
     A[i] < A[i-1] A[i] A i A[i-1] A i-1 i 1 tmp = A[i] tmp A[i] A i A[i] = A[i-1] A[i] A i A[i-1] A i-1 i 1 A[i-1] = tmp A[i-1] A i-1 i 1 tmp flag = 1 flag 1 count += 1 count 1 return A, count return A, count A count A A N N A, count = bubbleSort(A, N) A bubbleSort(A, N) bubbleSort A N count str(i) for i in A for i in A i A for i in A str(i) str i print(' '.join([str(i) for i in A])) print ' '.join([str(i) for i in A]) ' '.join ' ' join [str(i) for i in A] print(count) print count N = int(input()) int(input()) N 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]:
                tmp = A[i]
                A[i] = A[i-1]
                A[i-1] = tmp
                flag = 1
                count += 1
    return A, 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]:
                tmp = A[i]
                A[i] = A[i-1]
                A[i-1] = tmp
                flag = 1
                count += 1
    return A, count bubbleSort A = [int(i) for i in input().split()] [int(i) for i in input().split()] A A, count = bubbleSort(A, N) bubbleSort(A, N) A count = bubbleSort(A, N) bubbleSort(A, N) count
N = int(input())
A = [int(i) for i in 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]:
                tmp = A[i]
                A[i] = A[i-1]
                A[i-1] = tmp
                flag = 1
                count += 1
    return A, count

A, count = bubbleSort(A, N)
print(' '.join([str(i) for i in A]))
print(count)