def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]

    flag = True
    count = 0
    index = 0
    while flag :
        flag = False
        for i in reversed(range(index+1, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
        index += 1

    nums_str = [str(i) for i in nums]
    print(" ".join(nums_str))
    print(count)

if __name__ == '__main__' :
    main() def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]

    flag = True
    count = 0
    index = 0
    while flag :
        flag = False
        for i in reversed(range(index+1, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
        index += 1

    nums_str = [str(i) for i in nums]
    print(" ".join(nums_str))
    print(count) main n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i nums = [int(i) for i in input().split()] nums [int(i) for i in input().split()] flag = True flag True count = 0 count 0 index = 0 index 0 while flag :
        flag = False
        for i in reversed(range(index+1, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
        index += 1

     flag flag = False flag False for i in reversed(range(index+1, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
         i reversed(range(index+1, n)) reversed range(index+1, n) range index+1 index 1 n if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
         nums[i-1] > nums[i] nums[i-1] nums i-1 i 1 nums[i] nums i nums[i-1], nums[i] = nums[i], nums[i-1] nums[i-1] nums i-1 i 1 nums[i] nums i nums[i] nums i nums[i-1] nums i-1 i 1 count += 1 count 1 flag = True flag True index += 1 index 1 str(i) for i in nums for i in nums i nums for i in nums str(i) str i nums_str = [str(i) for i in nums] nums_str [str(i) for i in nums] print(" ".join(nums_str)) print " ".join(nums_str) " ".join " " join nums_str print(count) print count if __name__ == '__main__' :
    main() __name__ == '__main__' __name__ '__main__' main() main def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]

    flag = True
    count = 0
    index = 0
    while flag :
        flag = False
        for i in reversed(range(index+1, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
        index += 1

    nums_str = [str(i) for i in nums]
    print(" ".join(nums_str))
    print(count) def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]

    flag = True
    count = 0
    index = 0
    while flag :
        flag = False
        for i in reversed(range(index+1, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
        index += 1

    nums_str = [str(i) for i in nums]
    print(" ".join(nums_str))
    print(count) main
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]

    flag = True
    count = 0
    index = 0
    while flag :
        flag = False
        for i in reversed(range(index+1, n)) :
            if nums[i-1] > nums[i] :
                nums[i-1], nums[i] = nums[i], nums[i-1]
                count += 1
                flag = True
        index += 1

    nums_str = [str(i) for i in nums]
    print(" ".join(nums_str))
    print(count)

if __name__ == '__main__' :
    main()