<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of <strong>positive</strong> integers.</p>

<p>Initially, you can increase the value of <strong>any</strong> element in the array by <strong>at most</strong> <code>1</code>.</p>

<p>After that, you need to select <strong>one or more</strong> elements from the final array such that those elements are <strong>consecutive</strong> when sorted in increasing order. For example, the elements <code>[3, 4, 5]</code> are consecutive while <code>[3, 4, 6]</code> and <code>[1, 1, 2, 3]</code> are not.<!-- notionvc: 312f8c5d-40d0-4cd1-96cc-9e96a846735b --></p>

<p>Return <em>the <strong>maximum</strong> number of elements that you can select</em>.</p>

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

<pre>
<strong>Input:</strong> nums = [2,1,5,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> We can increase the elements at indices 0 and 3. The resulting array is nums = [3,1,5,2,1].
We select the elements [<u><strong>3</strong></u>,<u><strong>1</strong></u>,5,<u><strong>2</strong></u>,1] and we sort them to obtain [1,2,3], which are consecutive.
It can be shown that we cannot select more than 3 consecutive elements.</pre>

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

<pre>
<strong>Input:</strong> nums = [1,4,7,10]
<strong>Output:</strong> 1
<strong>Explanation:</strong> The maximum consecutive elements that we can select is 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>6</sup></code></li>
</ul>

class Solution:
    def maxSelectedElements(self, nums: List[int]) -> int:
        if len(nums)==1:return 1
        def find_longest_contiguous_subsequence(arr):
            arr.sort() 
            n = len(arr)
            if n == 1:
                return 1
            x=dict()
            count = 1
            max_count = -1
            x[arr[0]]=1
            for i in range(n - 1):
                if arr[i + 1] - arr[i] == 1:
                    count += 1
                elif arr[i + 1] - arr[i] == 0:
                    continue
                else:
                    count = 1    
                x[arr[i+1]]=count
            return x
        nums.sort()
        n=len(nums)
        h=dict()
        f=Counter(nums)
        x=list(f.keys())
        for i in x:
            if i not in h:
                h[i]=1
            if f[i]>1:
                h[i+1]=1
                f[i+1]+=f[i]-1
        print(h,nums)
        a=find_longest_contiguous_subsequence(list(h.keys()))
        b=find_longest_contiguous_subsequence(nums)
        res=0
        for i in a:
            res=max(res,a[i])
            if i-a[i]-1 in b:
                res=max(res,a[i]+b[i-a[i]-1])
        return res
56200