<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers, representing targets on a number line. You are also given an integer <code>space</code>.</p>

<p>You have a machine which can destroy targets. <strong>Seeding</strong> the machine with some <code>nums[i]</code> allows it to destroy all targets with values that can be represented as <code>nums[i] + c * space</code>, where <code>c</code> is any non-negative integer. You want to destroy the <strong>maximum</strong> number of targets in <code>nums</code>.</p>

<p>Return<em> the <strong>minimum value</strong> of </em><code>nums[i]</code><em> you can seed the machine with to destroy the maximum number of targets.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,7,8,1,1,5], space = 2
<strong>Output:</strong> 1
<strong>Explanation:</strong> If we seed the machine with nums[3], then we destroy all targets equal to 1,3,5,7,9,... 
In this case, we would destroy 5 total targets (all except for nums[2]). 
It is impossible to destroy more than 5 targets, so we return nums[3].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,3,5,2,4,6], space = 2
<strong>Output:</strong> 1
<strong>Explanation:</strong> Seeding the machine with nums[0], or nums[3] destroys 3 targets. 
It is not possible to destroy more than 3 targets.
Since nums[0] is the minimal integer that can destroy 3 targets, we return 1.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [6,2,5], space = 100
<strong>Output:</strong> 2
<strong>Explanation:</strong> Whatever initial seed we select, we can only destroy 1 target. The minimal seed is nums[1].
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
	<li><code>1 &lt;= space &lt;=&nbsp;10<sup>9</sup></code></li>
</ul>

from sortedcontainers import *
#1 1 3 5 7 8
class Solution:
    def destroyTargets(self, nums: List[int], space: int) -> int:
        def fn(vl, space):
            l = -1 * pow(10,10)
            r = pow(10, 10)
            mid = 0
            ans = vl 
            while l <=r and l >=-1 * pow(10, 10) and r <=pow(10,10):
                mid = int((l+r)/2)
                # print(mid,l , r,space)
                val = vl + (mid * space)
                # print(val)
                if l == r:
                    if val >=0:
                        return min(val , ans)
                    return ans
                if val <0:
                    l = mid + 1
                    
                else :
                    r = mid - 1
                    ans = min(ans, val)
            return ans
        if len(nums) <= 1:
            return nums[0]
        dc = {}
        nums.sort()
        # print(dc)
        # print(fn(5,4))
        for i in nums:
            c = fn(i, space)
            if c in dc:
                dc[c].append(i)
            else :
                dc[c] = [i]
        mxl = 0
        mnv = 0
        # print(len(nums))
        # sm = 0
        for i,j in dc.items():
            # print( (i,j,len(j)))
            # sm+=len(j)
            if len(j) > mxl:
                mxl = len(j)
                mnv = j[0]
            if len(j) == mxl:
                mnv = min(j[0], mnv)
        # print(sm)
        return mnv
42800