input: from typing import List
  
  def max_good_subsequence_length(nums: List[int], k: int) -> int:
      """
      You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1].
  
      Return the maximum possible length of a good subsequence of nums.
  
      Examples:
      >>> nums = [1,2,1,1,3], k = 2
      4
      >>> nums = [1,2,3,4,5,1], k = 0
      2
  
      Constraints:
      1 <= nums.length <= 500
      1 <= nums[i] <= 10^9
      0 <= k <= min(nums.length, 25)
      """
  
output: 
      n = len(nums)
      if n == 1:
          return 1
      
      dp = [[0] * (k + 1) for _ in range(n)]
      
      for i in range(n):
          dp[i][0] = 1
      
      for i in range(1, n):
          for j in range(k + 1):
              dp[i][j] = dp[i - 1][j] + 1 if nums[i] == nums[i - 1] else dp[i - 1][j]
              if j > 0:
                  dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
      
      return max(dp[n - 1])
  