python soution
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```\nclass Solution:\n    def maxSelectedElements(self, nums: List[int]) -> int:\n        if len(nums)==1:return 1\n        def find_longest_contiguous_subsequence(arr):\n            arr.sort() \n            n = len(arr)\n            if n == 1:\n                return 1\n            x=dict()\n            count = 1\n            max_count = -1\n            x[arr[0]]=1\n            for i in range(n - 1):\n                if arr[i + 1] - arr[i] == 1:\n                    count += 1\n                elif arr[i + 1] - arr[i] == 0:\n                    continue\n                else:\n                    count = 1    \n                x[arr[i+1]]=count\n            return x\n        nums.sort()\n        n=len(nums)\n        h=dict()\n        f=Counter(nums)\n        x=list(f.keys())\n        for i in x:\n            if i not in h:\n                h[i]=1\n            if f[i]>1:\n                h[i+1]=1\n                f[i+1]+=f[i]-1\n        print(h,nums)\n        a=find_longest_contiguous_subsequence(list(h.keys()))\n        b=find_longest_contiguous_subsequence(nums)\n        res=0\n        for i in a:\n            res=max(res,a[i])\n            if i-a[i]-1 in b:\n                res=max(res,a[i]+b[i-a[i]-1])\n        return res\n\n```
['Python3']