input: 
  from typing import List
  
  def longest_valid_subsequence(nums: List[int], k: int) -> int:
      """
      Given a list of integers nums and a non-negative integer k, a sequence seq is deemed valid if there are at most k positions i within the range [0, seq.length - 2] where seq[i] differs from seq[i + 1].
  
      Determine the maximum length of a valid subsequence from nums.
  
      Examples:
      >>> nums = [1,2,1,1,3], k = 2
      4
      >>> nums = [1,2,3,4,5,1], k = 0
      2
  
      Constraints:
      1 <= len(nums) <= 500
      1 <= nums[i] <= 10^9
      0 <= k <= min(len(nums), 25)
      """
  
output:     n = len(nums)
      max_len = 0
  
      for i in range(n):
          changes = 0
          current_len = 1
          
          for j in range(i + 1, n):
              if nums[j] != nums[j - 1]:
                  changes += 1
              if changes > k:
                  break
              current_len += 1
          
          max_len = max(max_len, current_len)
      
      return max_len