def bSort(A):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A, count

if __name__ == '__main__':
    length = input()
    data = [int(x) for x in input().split()]
    data_s, c = bSort(data)
    print (' '.join([str(x) for x in data_s]))
    print (c) def bSort(A):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A, count bSort flag = 1 flag 1 i = 0 i 0 count = 0 count 0 while flag:
        flag = 0
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
     flag flag = 0 flag 0 for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
         j range(len(A)-1, i, -1) range len(A)-1 len(A) len A 1 i -1 if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
         A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 tmp = A[j] tmp A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = tmp A[j-1] A j-1 j 1 tmp flag = 1 flag 1 count += 1 count 1 i += 1 i 1 return A, count return A, count A count A A if __name__ == '__main__':
    length = input()
    data = [int(x) for x in input().split()]
    data_s, c = bSort(data)
    print (' '.join([str(x) for x in data_s]))
    print (c) __name__ == '__main__' __name__ '__main__' length = input() length input() input int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x data = [int(x) for x in input().split()] data [int(x) for x in input().split()] data_s, c = bSort(data) data_s bSort(data) bSort data c str(x) for x in data_s for x in data_s x data_s for x in data_s str(x) str x print (' '.join([str(x) for x in data_s])) print ' '.join([str(x) for x in data_s]) ' '.join ' ' join [str(x) for x in data_s] print (c) print c def bSort(A):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A, count def bSort(A):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A, count bSort data_s, c = bSort(data) bSort(data) data_s length = input() input() length data = [int(x) for x in input().split()] [int(x) for x in input().split()] data c = bSort(data) bSort(data) c
def bSort(A):
    flag = 1
    i = 0
    count = 0
    while flag:
        flag = 0
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                count += 1
        i += 1
    return A, count

if __name__ == '__main__':
    length = input()
    data = [int(x) for x in input().split()]
    data_s, c = bSort(data)
    print (' '.join([str(x) for x in data_s]))
    print (c)
