#!/usr/bin/env python
# encoding: utf-8


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def bubble_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        flag = 1
        count = 0
        while flag:
            flag = 0
            for j in range(array_length - 1, 0, -1):
                if unsorted_array[j] < unsorted_array[j - 1]:
                    unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
                    flag = 1
                    count += 1
        print(" ".join(map(str, unsorted_array)))
        print(str(count))


if __name__ == '__main__':
    solution = Solution()
    solution.bubble_sort() class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def bubble_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        flag = 1
        count = 0
        while flag:
            flag = 0
            for j in range(array_length - 1, 0, -1):
                if unsorted_array[j] < unsorted_array[j - 1]:
                    unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
                    flag = 1
                    count += 1
        print(" ".join(map(str, unsorted_array)))
        print(str(count)) Solution """
    @param prices: Given an integer array
    @return: Maximum profit
    """ def bubble_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        flag = 1
        count = 0
        while flag:
            flag = 0
            for j in range(array_length - 1, 0, -1):
                if unsorted_array[j] < unsorted_array[j - 1]:
                    unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
                    flag = 1
                    count += 1
        print(" ".join(map(str, unsorted_array)))
        print(str(count)) bubble_sort array_length = int(input()) array_length 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 unsorted_array = [int(x) for x in input().split()] unsorted_array [int(x) for x in input().split()] flag = 1 flag 1 count = 0 count 0 while flag:
            flag = 0
            for j in range(array_length - 1, 0, -1):
                if unsorted_array[j] < unsorted_array[j - 1]:
                    unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
                    flag = 1
                    count += 1
         flag flag = 0 flag 0 for j in range(array_length - 1, 0, -1):
                if unsorted_array[j] < unsorted_array[j - 1]:
                    unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
                    flag = 1
                    count += 1
         j range(array_length - 1, 0, -1) range array_length - 1 array_length 1 0 -1 if unsorted_array[j] < unsorted_array[j - 1]:
                    unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
                    flag = 1
                    count += 1
         unsorted_array[j] < unsorted_array[j - 1] unsorted_array[j] unsorted_array j unsorted_array[j - 1] unsorted_array j - 1 j 1 unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j] unsorted_array[j] unsorted_array j unsorted_array[j - 1] unsorted_array j - 1 j 1 unsorted_array[j - 1] unsorted_array j - 1 j 1 unsorted_array[j] unsorted_array j flag = 1 flag 1 count += 1 count 1 print(" ".join(map(str, unsorted_array))) print " ".join(map(str, unsorted_array)) " ".join " " join map(str, unsorted_array) map str unsorted_array print(str(count)) print str(count) str count @staticmethod
     bubble_sort staticmethod bubble_sort if __name__ == '__main__':
    solution = Solution()
    solution.bubble_sort() __name__ == '__main__' __name__ '__main__' solution = Solution() solution Solution() Solution solution.bubble_sort() solution.bubble_sort solution bubble_sort solution = Solution() Solution() solution class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def bubble_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        flag = 1
        count = 0
        while flag:
            flag = 0
            for j in range(array_length - 1, 0, -1):
                if unsorted_array[j] < unsorted_array[j - 1]:
                    unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
                    flag = 1
                    count += 1
        print(" ".join(map(str, unsorted_array)))
        print(str(count)) class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def bubble_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        flag = 1
        count = 0
        while flag:
            flag = 0
            for j in range(array_length - 1, 0, -1):
                if unsorted_array[j] < unsorted_array[j - 1]:
                    unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
                    flag = 1
                    count += 1
        print(" ".join(map(str, unsorted_array)))
        print(str(count)) Solution
#!/usr/bin/env python
# encoding: utf-8


class Solution:
    """
    @param prices: Given an integer array
    @return: Maximum profit
    """

    @staticmethod
    def bubble_sort():
        # write your code here
        array_length = int(input())
        unsorted_array = [int(x) for x in input().split()]

        flag = 1
        count = 0
        while flag:
            flag = 0
            for j in range(array_length - 1, 0, -1):
                if unsorted_array[j] < unsorted_array[j - 1]:
                    unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
                    flag = 1
                    count += 1
        print(" ".join(map(str, unsorted_array)))
        print(str(count))


if __name__ == '__main__':
    solution = Solution()
    solution.bubble_sort()