Python beats 100 %
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\ndef closest_palindrome(n):\n\n    s = str(n) \n\n    if s=="10":\n        return [9, 11]\n    if s==s[::-1]:\n        return [n]\n    \n    first_half = s[:len(s) // 2]\n\n    if len(s) % 2:\n        odd = s[len(s) // 2]\n\n    second_half = first_half[::-1]\n\n    pal1 = ""  # for same middle digit\n    pal2 = ""  # for middle -1 digit\n    pal3 = ""  # for middle + 1 digit\n    \n    if len(s) % 2:\n   \n        pal1 = first_half + odd + second_half\n        \n        if odd == \'0\':\n            temp = add_carry(first_half, -1)\n            pal2 = temp + "9" + temp[::-1]\n        else:\n            pal2 = first_half + str(int(odd) - 1) + second_half\n        \n        if odd == \'9\':\n            temp = add_carry(first_half, 1)\n            pal3 = temp + \'0\' + temp[::-1]\n        else:\n            pal3 = first_half + str(int(odd) + 1) + second_half\n    else:\n       \n        pal1 = first_half + second_half\n        \n        small_size = len(first_half)  \n        if first_half[small_size - 1] == \'0\':\n            temp = add_carry(first_half, -1)\n        else:\n            temp = first_half[:small_size - 1] + str(int(first_half[small_size - 1]) - 1)\n        pal2 = temp + temp[::-1]\n        \n        if first_half[small_size - 1] == \'9\':\n            temp = add_carry(first_half, 1)\n        else:\n            temp = first_half[:small_size - 1] + str(int(first_half[small_size - 1]) + 1)\n        pal3 = temp + temp[::-1]\n\n\n    # print(pal1, pal2, pal3)\n    return [int(pal1), int(pal2), int(pal3)]\n\ndef add_carry(num, carry):\n    if carry == -1:\n        itr = len(num) - 1\n        while itr >= 0 and num[itr] == \'0\':\n            num = num[:itr] + \'9\' + num[itr + 1:]\n            itr -= 1\n        \n        if itr >= 0:\n            num = num[:itr] + str(int(num[itr]) - 1) + num[itr + 1:]\n    else:\n        for i in range(len(num) - 1, -1, -1):\n            temp = int(num[i])\n            num = num[:i] + str((temp + carry) % 10) + num[i + 1:]\n            carry = (temp + carry) // 10\n    \n    return num\n\n\nclass Solution:\n    def minimumCost(self, nums: List[int]) -> int:\n        n = len(nums)\n        nums.sort()\n\n        min_costs = float(\'inf\')\n\n        if n%2:\n            targets = closest_palindrome(nums[n//2])\n\n            # print(f\'odd {targets}\')\n            for target in targets:\n                cost = 0\n                for i in nums:\n                    cost += abs(i - target)\n                min_costs = min(min_costs, cost)\n\n            return min_costs\n\n        else:\n            targets = closest_palindrome((nums[n//2] + nums[(n//2) - 1])//2)\n\n            for target in targets:\n                cost = 0\n                for i in nums:\n                    cost += abs(i - target)\n                min_costs = min(min_costs, cost)\n\n            return min_costs\n```
['Python3']