input: from typing import List
  
  def find_maximum_length_of_valid_subsequence(nums: List[int]) -> int:
      """
      You are given an integer array nums.
      A subsequence sub of nums with length x is called valid if it satisfies:
  
      (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 of nums.
  
      A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements..
  
      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: 
      n = len(nums)
      if n < 2:
          return n
      
      dp = [1] * n
      max_len = 1
      
      for i in range(1, n):
          for j in range(i):
              if (nums[i] + nums[j]) % 2 == 0:
                  dp[i] = max(dp[i], dp[j] + 1)
          max_len = max(max_len, dp[i])
      
      return max_len
  