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


def bubble_sort(n, a):
    cnt = 0
    flag = True
    while flag:
        flag = False
        for i in reversed(range(n)):
            if i is 0: break
            if a[i] < a[i - 1]:
                tmp = a[i]
                a[i] = a[i - 1]
                a[i - 1] = tmp
                flag = True
                cnt += 1
    return a, cnt


if __name__ == '__main__':
    n = int(input())
    a = [int(n) for n in input().split()]
    ans = bubble_sort(n, a)
    print(' '.join(map(str, ans[0])))
    print(ans[1]) def bubble_sort(n, a):
    cnt = 0
    flag = True
    while flag:
        flag = False
        for i in reversed(range(n)):
            if i is 0: break
            if a[i] < a[i - 1]:
                tmp = a[i]
                a[i] = a[i - 1]
                a[i - 1] = tmp
                flag = True
                cnt += 1
    return a, cnt bubble_sort cnt = 0 cnt 0 flag = True flag True while flag:
        flag = False
        for i in reversed(range(n)):
            if i is 0: break
            if a[i] < a[i - 1]:
                tmp = a[i]
                a[i] = a[i - 1]
                a[i - 1] = tmp
                flag = True
                cnt += 1
     flag flag = False flag False for i in reversed(range(n)):
            if i is 0: break
            if a[i] < a[i - 1]:
                tmp = a[i]
                a[i] = a[i - 1]
                a[i - 1] = tmp
                flag = True
                cnt += 1
     i reversed(range(n)) reversed range(n) range n if i is 0: break
             i is 0 i 0 if a[i] < a[i - 1]:
                tmp = a[i]
                a[i] = a[i - 1]
                a[i - 1] = tmp
                flag = True
                cnt += 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 = True flag True cnt += 1 cnt 1 return a, cnt return a, cnt a cnt n n a a if __name__ == '__main__':
    n = int(input())
    a = [int(n) for n in input().split()]
    ans = bubble_sort(n, a)
    print(' '.join(map(str, ans[0])))
    print(ans[1]) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input int(n) for n in input().split() for n in input().split() n input().split() ().split () input split for n in input().split() int(n) int n a = [int(n) for n in input().split()] a [int(n) for n in input().split()] ans = bubble_sort(n, a) ans bubble_sort(n, a) bubble_sort n a print(' '.join(map(str, ans[0]))) print ' '.join(map(str, ans[0])) ' '.join ' ' join map(str, ans[0]) map str ans[0] ans 0 print(ans[1]) print ans[1] ans 1 a = [int(n) for n in input().split()] [int(n) for n in input().split()] a def bubble_sort(n, a):
    cnt = 0
    flag = True
    while flag:
        flag = False
        for i in reversed(range(n)):
            if i is 0: break
            if a[i] < a[i - 1]:
                tmp = a[i]
                a[i] = a[i - 1]
                a[i - 1] = tmp
                flag = True
                cnt += 1
    return a, cnt def bubble_sort(n, a):
    cnt = 0
    flag = True
    while flag:
        flag = False
        for i in reversed(range(n)):
            if i is 0: break
            if a[i] < a[i - 1]:
                tmp = a[i]
                a[i] = a[i - 1]
                a[i - 1] = tmp
                flag = True
                cnt += 1
    return a, cnt bubble_sort n = int(input()) int(input()) n ans = bubble_sort(n, a) bubble_sort(n, a) ans
# -*- coding: utf-8 -*-


def bubble_sort(n, a):
    cnt = 0
    flag = True
    while flag:
        flag = False
        for i in reversed(range(n)):
            if i is 0: break
            if a[i] < a[i - 1]:
                tmp = a[i]
                a[i] = a[i - 1]
                a[i - 1] = tmp
                flag = True
                cnt += 1
    return a, cnt


if __name__ == '__main__':
    n = int(input())
    a = [int(n) for n in input().split()]
    ans = bubble_sort(n, a)
    print(' '.join(map(str, ans[0])))
    print(ans[1])