input: from typing import List
  
  def max_consecutive_elements(nums: List[int]) -> int:
      """
      Given a 0-indexed array nums containing positive integers, you can initially increase the value of any element in the array by at most 1.
  
      Afterwards, select one or more elements from the modified array such that these elements are consecutive when sorted in ascending order. For example, [3, 4, 5] are consecutive, but [3, 4, 6] and [1, 1, 2, 3] are not.
  
      Determine the maximum number of consecutive elements that can be chosen.
  
      Examples:
      >>> nums = [2,1,5,1,1]
      3
      >>> nums = [1,4,7,10]
      1
  
      Constraints:
      1 <= nums.length <= 10^5
      1 <= nums[i] <= 10^6
      """
output:     
      # First, sort the array
      nums.sort()
  
      max_consecutive = 1
      current_consecutive = 1
  
      for i in range(1, len(nums)):
          if nums[i] == nums[i - 1] + 1 or nums[i] == nums[i - 1]:
              current_consecutive += 1
          else:
              max_consecutive = max(max_consecutive, current_consecutive)
              current_consecutive = 1
  
      max_consecutive = max(max_consecutive, current_consecutive)
      return max_consecutive
  