
    Design a fraud detection algorithm that determines the number of possible transaction risk pattern sequences for n consecutive transactions, where each transaction can be classified into k risk levels, with the constraint that no more than 2 consecutive transactions can be assigned the same risk level. The algorithm must analyze the sequence of transactions to identify valid risk assessment patterns that comply with the bank's security protocol of avoiding prolonged sequences of identical risk classifications.
    

    
def count_no_of_ways(n, k):
    """
    Design a fraud detection algorithm that determines the number of possible transaction risk pattern sequences for n consecutive transactions, where each transaction can be classified into k risk levels, with the constraint that no more than 2 consecutive transactions can be assigned the same risk level. The algorithm must analyze the sequence of transactions to identify valid risk assessment patterns that comply with the bank's security protocol of avoiding prolonged sequences of identical risk classifications.
    

    """
def count_no_of_ways(n, k):
    """
    Design a fraud detection algorithm that determines the number of possible transaction risk pattern sequences for n consecutive transactions, where each transaction can be classified into k risk levels, with the constraint that no more than 2 consecutive transactions can be assigned the same risk level. The algorithm must analyze the sequence of transactions to identify valid risk assessment patterns that comply with the bank's security protocol of avoiding prolonged sequences of identical risk classifications.
    

    """
    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]