# -*- coding: utf-8 -*-


def bubble_sort(a, N):
    change = 0
    for i in xrange(N - 1):
        for j in xrange(N - 1, i, -1):
            if a[j - 1] > a[j]:
                temp = a[j - 1]
                a[j - 1] = a[j]
                a[j] = temp
                change += 1
    return (a, change)


if __name__ == "__main__":
    N = input()
    a = map(int, raw_input().split())
    result, change = bubble_sort(a, N)
    print ' '.join(map(str, result))
    print change def bubble_sort(a, N):
    change = 0
    for i in xrange(N - 1):
        for j in xrange(N - 1, i, -1):
            if a[j - 1] > a[j]:
                temp = a[j - 1]
                a[j - 1] = a[j]
                a[j] = temp
                change += 1
    return (a, change) bubble_sort change = 0 change 0 for i in xrange(N - 1):
        for j in xrange(N - 1, i, -1):
            if a[j - 1] > a[j]:
                temp = a[j - 1]
                a[j - 1] = a[j]
                a[j] = temp
                change += 1
     i xrange(N - 1) xrange N - 1 N 1 for j in xrange(N - 1, i, -1):
            if a[j - 1] > a[j]:
                temp = a[j - 1]
                a[j - 1] = a[j]
                a[j] = temp
                change += 1
     j xrange(N - 1, i, -1) xrange N - 1 N 1 i -1 if a[j - 1] > a[j]:
                temp = a[j - 1]
                a[j - 1] = a[j]
                a[j] = temp
                change += 1
     a[j - 1] > a[j] a[j - 1] a j - 1 j 1 a[j] a j temp = a[j - 1] temp a[j - 1] a j - 1 j 1 a[j - 1] = a[j] a[j - 1] a j - 1 j 1 a[j] a j a[j] = temp a[j] a j temp change += 1 change 1 return (a, change) (a, change) a change a a N N if __name__ == "__main__":
    N = input()
    a = map(int, raw_input().split())
    result, change = bubble_sort(a, N)
    print ' '.join(map(str, result))
    print change __name__ == "__main__" __name__ "__main__" N = input() N input() input a = map(int, raw_input().split()) a map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split result, change = bubble_sort(a, N) result bubble_sort(a, N) bubble_sort a N change print ' '.join(map(str, result)) ' '.join ' ' join map(str, result) map str result print a = map(int, raw_input().split()) map(int, raw_input().split()) a change = bubble_sort(a, N) bubble_sort(a, N) change N = input() input() N result, change = bubble_sort(a, N) bubble_sort(a, N) result def bubble_sort(a, N):
    change = 0
    for i in xrange(N - 1):
        for j in xrange(N - 1, i, -1):
            if a[j - 1] > a[j]:
                temp = a[j - 1]
                a[j - 1] = a[j]
                a[j] = temp
                change += 1
    return (a, change) def bubble_sort(a, N):
    change = 0
    for i in xrange(N - 1):
        for j in xrange(N - 1, i, -1):
            if a[j - 1] > a[j]:
                temp = a[j - 1]
                a[j - 1] = a[j]
                a[j] = temp
                change += 1
    return (a, change) bubble_sort
# -*- coding: utf-8 -*-


def bubble_sort(a, N):
    change = 0
    for i in xrange(N - 1):
        for j in xrange(N - 1, i, -1):
            if a[j - 1] > a[j]:
                temp = a[j - 1]
                a[j - 1] = a[j]
                a[j] = temp
                change += 1
    return (a, change)


if __name__ == "__main__":
    N = input()
    a = map(int, raw_input().split())
    result, change = bubble_sort(a, N)
    print ' '.join(map(str, result))
    print change