def bubbleSort(list_, n):
    list_ = list_[:]
    count = 0
    for i in xrange(n):
        for j in xrange(n-1, i, -1):
            if list_[j] < list_[j - 1]:
                list_[j], list_[j - 1] = list_[j - 1], list_[j]
                count += 1

    return list_, count

n = input()
nums = map(int, raw_input().split())
sorted_, count = bubbleSort(nums, n)
print ' '.join(map(str, sorted_))
print count def bubbleSort(list_, n):
    list_ = list_[:]
    count = 0
    for i in xrange(n):
        for j in xrange(n-1, i, -1):
            if list_[j] < list_[j - 1]:
                list_[j], list_[j - 1] = list_[j - 1], list_[j]
                count += 1

    return list_, count bubbleSort list_ = list_[:] list_ list_[:] list_ : count = 0 count 0 for i in xrange(n):
        for j in xrange(n-1, i, -1):
            if list_[j] < list_[j - 1]:
                list_[j], list_[j - 1] = list_[j - 1], list_[j]
                count += 1

     i xrange(n) xrange n for j in xrange(n-1, i, -1):
            if list_[j] < list_[j - 1]:
                list_[j], list_[j - 1] = list_[j - 1], list_[j]
                count += 1

     j xrange(n-1, i, -1) xrange n-1 n 1 i -1 if list_[j] < list_[j - 1]:
                list_[j], list_[j - 1] = list_[j - 1], list_[j]
                count += 1

     list_[j] < list_[j - 1] list_[j] list_ j list_[j - 1] list_ j - 1 j 1 list_[j], list_[j - 1] = list_[j - 1], list_[j] list_[j] list_ j list_[j - 1] list_ j - 1 j 1 list_[j - 1] list_ j - 1 j 1 list_[j] list_ j count += 1 count 1 return list_, count return list_, count list_ count list_ list_ n n n = input() n input() input nums = map(int, raw_input().split()) nums map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split sorted_, count = bubbleSort(nums, n) sorted_ bubbleSort(nums, n) bubbleSort nums n count print ' '.join(map(str, sorted_)) ' '.join ' ' join map(str, sorted_) map str sorted_ print n = input() input() n def bubbleSort(list_, n):
    list_ = list_[:]
    count = 0
    for i in xrange(n):
        for j in xrange(n-1, i, -1):
            if list_[j] < list_[j - 1]:
                list_[j], list_[j - 1] = list_[j - 1], list_[j]
                count += 1

    return list_, count def bubbleSort(list_, n):
    list_ = list_[:]
    count = 0
    for i in xrange(n):
        for j in xrange(n-1, i, -1):
            if list_[j] < list_[j - 1]:
                list_[j], list_[j - 1] = list_[j - 1], list_[j]
                count += 1

    return list_, count bubbleSort count = bubbleSort(nums, n) bubbleSort(nums, n) count nums = map(int, raw_input().split()) map(int, raw_input().split()) nums sorted_, count = bubbleSort(nums, n) bubbleSort(nums, n) sorted_
def bubbleSort(list_, n):
    list_ = list_[:]
    count = 0
    for i in xrange(n):
        for j in xrange(n-1, i, -1):
            if list_[j] < list_[j - 1]:
                list_[j], list_[j - 1] = list_[j - 1], list_[j]
                count += 1

    return list_, count

n = input()
nums = map(int, raw_input().split())
sorted_, count = bubbleSort(nums, n)
print ' '.join(map(str, sorted_))
print count