def bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    swap_count = 0
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            if data[j] < data[j-1]:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                swap_count += 1
                flag = True
        i == 1
    return swap_count, data


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    data = [int(x) for x in input().split(' ')]
    # data = [5, 3, 2, 4, 1]

    # ???????????????????????????
    count, data = bubble_sort(data, num)

    # ???????????????
    print('{0}\n{1}'.format(' '.join(map(str, data)), count)) def bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    swap_count = 0
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            if data[j] < data[j-1]:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                swap_count += 1
                flag = True
        i == 1
    return swap_count, data bubble_sort """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """ swap_count = 0 swap_count 0 flag = True flag True i = 0 i 0 while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            if data[j] < data[j-1]:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                swap_count += 1
                flag = True
        i == 1
     flag is True flag True flag = False flag False for j in range(n-1, i, -1):
            if data[j] < data[j-1]:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                swap_count += 1
                flag = True
         j range(n-1, i, -1) range n-1 n 1 i -1 if data[j] < data[j-1]:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                swap_count += 1
                flag = True
         data[j] < data[j-1] data[j] data j data[j-1] data j-1 j 1 temp = data[j] temp data[j] data j data[j] = data[j-1] data[j] data j data[j-1] data j-1 j 1 data[j-1] = temp data[j-1] data j-1 j 1 temp swap_count += 1 swap_count 1 flag = True flag True i == 1 i 1 return swap_count, data return swap_count, data swap_count data data data n n if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    data = [int(x) for x in input().split(' ')]
    # data = [5, 3, 2, 4, 1]

    # ???????????????????????????
    count, data = bubble_sort(data, num)

    # ???????????????
    print('{0}\n{1}'.format(' '.join(map(str, data)), count)) __name__ == '__main__' __name__ '__main__' num = int(input()) num int(input()) int 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(' ')] count, data = bubble_sort(data, num) count bubble_sort(data, num) bubble_sort data num data print('{0}\n{1}'.format(' '.join(map(str, data)), count)) print '{0}\n{1}'.format(' '.join(map(str, data)), count) '{0}\n{1}'.format '{0}\n{1}' format ' '.join(map(str, data)) ' '.join ' ' join map(str, data) map str data count count, data = bubble_sort(data, num) bubble_sort(data, num) count def bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    swap_count = 0
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            if data[j] < data[j-1]:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                swap_count += 1
                flag = True
        i == 1
    return swap_count, data def bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    swap_count = 0
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            if data[j] < data[j-1]:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                swap_count += 1
                flag = True
        i == 1
    return swap_count, data bubble_sort data = bubble_sort(data, num) bubble_sort(data, num) data num = int(input()) int(input()) num data = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] data
def bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    swap_count = 0
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            if data[j] < data[j-1]:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                swap_count += 1
                flag = True
        i == 1
    return swap_count, data


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    data = [int(x) for x in input().split(' ')]
    # data = [5, 3, 2, 4, 1]

    # ???????????????????????????
    count, data = bubble_sort(data, num)

    # ???????????????
    print('{0}\n{1}'.format(' '.join(map(str, data)), count))