
    Design an algorithm for a patient monitoring system that determines the number of possible ways to classify a patient's risk levels across n consecutive monitoring intervals, where each interval can be assigned one of k risk status categories, with the constraint that no more than 2 consecutive intervals can be classified with the same risk level. This pattern recognition is crucial for identifying potentially dangerous trends in patient vital signs while reducing false alarms from brief fluctuations.
    

    
def count_no_of_ways(n, k):
    """
    Design an algorithm for a patient monitoring system that determines the number of possible ways to classify a patient's risk levels across n consecutive monitoring intervals, where each interval can be assigned one of k risk status categories, with the constraint that no more than 2 consecutive intervals can be classified with the same risk level. This pattern recognition is crucial for identifying potentially dangerous trends in patient vital signs while reducing false alarms from brief fluctuations.
    

    """
def count_no_of_ways(n, k):
    """
    Design an algorithm for a patient monitoring system that determines the number of possible ways to classify a patient's risk levels across n consecutive monitoring intervals, where each interval can be assigned one of k risk status categories, with the constraint that no more than 2 consecutive intervals can be classified with the same risk level. This pattern recognition is crucial for identifying potentially dangerous trends in patient vital signs while reducing false alarms from brief fluctuations.
    

    """
    dp = [0] * (n + 1)
    total = k
    mod = 1000000007
    dp[1] = k
    dp[2] = k * k
    for i in range(3, n + 1):
        dp[i] = (k - 1) * (dp[i - 1] + dp[i - 2]) % mod
    return dp[n]