def bubble_sort_aoj(nums, len):
    '''バブルソート：隣接項の比較'''
    flag = True
    count = 0
    
    while flag:
        flag = False
        
        for i in range(len - 1, 0, -1):
            if nums[i] < nums[i-1]:
                nums[i], nums[i-1] = nums[i-1], nums[i]
                flag = True
                count += 1
    
    return nums, count

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))

    ans = bubble_sort_aoj(A, N)

    print(' '.join([str(x) for x in ans[0]]))
    print(ans[1]) def bubble_sort_aoj(nums, len):
    '''バブルソート：隣接項の比較'''
    flag = True
    count = 0
    
    while flag:
        flag = False
        
        for i in range(len - 1, 0, -1):
            if nums[i] < nums[i-1]:
                nums[i], nums[i-1] = nums[i-1], nums[i]
                flag = True
                count += 1
    
    return nums, count bubble_sort_aoj '''バブルソート：隣接項の比較''' flag = True flag True count = 0 count 0 while flag:
        flag = False
        
        for i in range(len - 1, 0, -1):
            if nums[i] < nums[i-1]:
                nums[i], nums[i-1] = nums[i-1], nums[i]
                flag = True
                count += 1
    
     flag flag = False flag False for i in range(len - 1, 0, -1):
            if nums[i] < nums[i-1]:
                nums[i], nums[i-1] = nums[i-1], nums[i]
                flag = True
                count += 1
    
     i range(len - 1, 0, -1) range len - 1 len 1 0 -1 if nums[i] < nums[i-1]:
                nums[i], nums[i-1] = nums[i-1], nums[i]
                flag = True
                count += 1
    
     nums[i] < nums[i-1] nums[i] nums i nums[i-1] nums i-1 i 1 nums[i], nums[i-1] = nums[i-1], nums[i] nums[i] nums i nums[i-1] nums i-1 i 1 nums[i-1] nums i-1 i 1 nums[i] nums i flag = True flag True count += 1 count 1 return nums, count return nums, count nums count nums nums len len if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))

    ans = bubble_sort_aoj(A, N)

    print(' '.join([str(x) for x in ans[0]]))
    print(ans[1]) __name__ == '__main__' __name__ '__main__' N = int(input()) N int(input()) int input() input A = list(map(int, input().split(' '))) A list(map(int, input().split(' '))) list map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' ans = bubble_sort_aoj(A, N) ans bubble_sort_aoj(A, N) bubble_sort_aoj A N str(x) for x in ans[0] for x in ans[0] x ans[0] ans 0 for x in ans[0] str(x) str x print(' '.join([str(x) for x in ans[0]])) print ' '.join([str(x) for x in ans[0]]) ' '.join ' ' join [str(x) for x in ans[0]] print(ans[1]) print ans[1] ans 1 A = list(map(int, input().split(' '))) list(map(int, input().split(' '))) A def bubble_sort_aoj(nums, len):
    '''バブルソート：隣接項の比較'''
    flag = True
    count = 0
    
    while flag:
        flag = False
        
        for i in range(len - 1, 0, -1):
            if nums[i] < nums[i-1]:
                nums[i], nums[i-1] = nums[i-1], nums[i]
                flag = True
                count += 1
    
    return nums, count def bubble_sort_aoj(nums, len):
    '''バブルソート：隣接項の比較'''
    flag = True
    count = 0
    
    while flag:
        flag = False
        
        for i in range(len - 1, 0, -1):
            if nums[i] < nums[i-1]:
                nums[i], nums[i-1] = nums[i-1], nums[i]
                flag = True
                count += 1
    
    return nums, count bubble_sort_aoj ans = bubble_sort_aoj(A, N) bubble_sort_aoj(A, N) ans N = int(input()) int(input()) N
def bubble_sort_aoj(nums, len):
    '''バブルソート：隣接項の比較'''
    flag = True
    count = 0
    
    while flag:
        flag = False
        
        for i in range(len - 1, 0, -1):
            if nums[i] < nums[i-1]:
                nums[i], nums[i-1] = nums[i-1], nums[i]
                flag = True
                count += 1
    
    return nums, count

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))

    ans = bubble_sort_aoj(A, N)

    print(' '.join([str(x) for x in ans[0]]))
    print(ans[1])
