Create Palindrome around the median
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```csharp []
public class Solution {
    private int CreatePalin(int n)
    {
        if(n > 0 && n < 10)
            return n;

        string s = n.ToString();
        int low = 0, high = s.Length-1;
        bool isPalin = true;
        while(low < high)
        {
            if(s[low++] != s[high--])
            {
                isPalin = false;
                break;
            }
        }

        if(isPalin)
            return n;

        int len = s.Length;
        int half = len/2;
        int highPart = int.Parse(s.Substring(0, half)), lowPart = int.Parse(s.Substring(half + (len%2== 0 ? 0 : 1)));
        int reverseH = 0, tmp = highPart;
        while(tmp > 0)
        {
            reverseH *= 10;
            reverseH += tmp%10;
            tmp /= 10;
        }
        if(len%2 == 1)
        {
            highPart *= 10;
            highPart += (s[half]-'0');
        }

        if(lowPart > reverseH)
            highPart++;

        int palin = highPart;
        if(len%2 == 1)
            palin /= 10;

        while(palin > 0)
        {
            highPart *= 10;
            highPart += palin%10;
            palin /= 10;
        }

        return highPart;
    }

    private int CreatePrePalin(int n)
    {
        if(n > 0 && n < 10)
            return n;

        string s = n.ToString();
        int len = s.Length;
        bool isPalin  = true;
        int low = 0, high = len-1;
        while(low < high)
        {
            if(s[low++] != s[high--])
            {
                isPalin = false;
                break;
            }
        }

        if(isPalin)
            return n;

        int highPart = int.Parse(s.Substring(0, len/2)), lowPart = int.Parse(s.Substring(len/2 + (len%2 == 1 ? 1 : 0)));
        int reverseH = 0, tmp = highPart;
        while(tmp > 0)
        {
            reverseH *= 10;
            reverseH += tmp%10;
            tmp/=10;
        }
        if(len%2 == 1)
        {
            highPart *= 10;
            highPart += (s[len/2]-'0');
        }

        if(lowPart < reverseH)
            highPart--;

        int palin = highPart;
        if(len%2 == 1)
            palin /= 10;

        while(palin > 0)
        {
            highPart *= 10;
            highPart += palin%10;
            palin /= 10;
        }

        return highPart;
    }

    public long MinimumCost(int[] nums) {
        int minV = int.MaxValue, maxV= 1, len = nums.Length;
        Dictionary<int, int> dict = new();
        Array.Sort(nums);
        
        foreach(int n in nums)
        {
            dict.TryAdd(n, 0);
            dict[n]++;
            minV = Math.Min(minV, n);
            maxV = Math.Max(maxV, n);
           // sum += n;
        }

        List<int> palins = new();
        int median = nums[len / 2];
        Console.WriteLine($"median is {median}");
        int cnt = 0;
        int nextPalin = CreatePalin(median);
        int prePalin = CreatePrePalin(median - 1);
        palins.Add(nextPalin);
        palins.Add(prePalin);

        if(prePalin > 1)
            palins.Add( CreatePrePalin(prePalin - 1));

        palins.Add(CreatePalin(nextPalin + 1));

        long minDiff = long.MaxValue;
      
        foreach(int n in palins)
        {  
            long diff = 0;
            
            foreach(var kvp in dict)
            {
                diff += (Math.Abs(kvp.Key-n)*kvp.Value);
            }

            minDiff = Math.Min(minDiff, diff);
        }

        return minDiff;
    }
}
```
['C#']