Find median and solve 564
564 https://leetcode.com/problems/find-the-closest-palindrome/\n\n\nclass Solution:\n    def minimumCost(self, nums: List[int]) -> int:\n        N = len(nums)\n
564 https://leetcode.com/problems/find-the-closest-palindrome/\n\n```\nclass Solution:\n    def minimumCost(self, nums: List[int]) -> int:\n        N = len(nums)\n        nums.sort()\n        if N % 2 == 0:\n            med = (nums[N // 2] + nums[(N - 1) // 2]) // 2\n        else:\n            med = nums[N // 2]\n\n\t\t### 564\n        s = str(med)\n        left = s[:(len(s) - 1) // 2 + 1]\n        \n        left_num = int(left)\n        left_min = str(left_num - 1)\n        left_max = str(left_num + 1)\n\n        take = len(left) - len(s) % 2\n\n        min_num = left_min + left_min[:take][::-1]\n        if len(left) > len(left_min) or left_min[:take] == \'0\':\n            min_num = \'9\' * (len(s) - 1)\n        max_num = left_max + left_max[:take][::-1]\n\n        if len(s) % 2 == 0:\n            pali = left + left[::-1]\n        else:\n            pali = left[:-1] + left[-1:] + left[:-1][::-1]\n\n        pali = int(pali)\n        min_num = int(min_num) # previous pali\n        max_num = int(max_num) # next palu\n\t\t### end 564\n        \n        res1 = res2 = res3 = 0\n        for n in nums:\n            res1 += abs(n - pali)\n            res2 += abs(n - min_num)\n            res3 += abs(n - max_num)\n        return min(res1, res2, res3)\n```\n\n> beats 99.88%, but who cares ;)
['Python']