input: Write a Python function that, given a list of integers, finds the length of the longest subsequence that satisfies the condition: (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2. A subsequence is derived from an array by potentially removing some elements without changing the order.
  
  from typing import List
  
  def longest_valid_subsequence_length(nums: List[int]) -> int:
      """
      Given an integer array nums, find the maximum length of a valid subsequence. 
  
      A subsequence sub of nums with length x is considered valid if it fulfills:
  
      (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2.
  
      Return the length of the longest valid subsequence from nums.
  
      Examples:
      >>> nums = [1,2,3,4]
      4
      >>> nums = [1,2,1,1,2,1,2]
      6
  
      Constraints:
      2 <= nums.length <= 2 * 10^5
      1 <= nums[i] <= 10^7
      """
output: def longest_valid_subsequence_length(nums: List[int]) -> int:
      max_length = 1
      current_length = 1
  
      for i in range(1, len(nums)):
          if (nums[i] + nums[i - 1]) % 2 == (nums[i - 1] + nums[i - 2]) % 2 if i > 1 else True:
              current_length += 1
          else:
              max_length = max(max_length, current_length)
              current_length = 2
  
      return max(max_length, current_length)