
    Design a fraud detection algorithm that determines the number of possible legitimate transaction sequences across n consecutive events, where transactions from k different channels are monitored, and no more than 2 consecutive transactions can occur through the same channel to minimize fraud risk. The sequence length n represents the monitoring window, and k represents the available transaction channels (such as ATM, online banking, point-of-sale, wire transfer).
    

    
def count_no_of_ways(n, k):
    """
    Design a fraud detection algorithm that determines the number of possible legitimate transaction sequences across n consecutive events, where transactions from k different channels are monitored, and no more than 2 consecutive transactions can occur through the same channel to minimize fraud risk. The sequence length n represents the monitoring window, and k represents the available transaction channels (such as ATM, online banking, point-of-sale, wire transfer).
    

    """
def count_no_of_ways(n, k):
    """
    Design a fraud detection algorithm that determines the number of possible legitimate transaction sequences across n consecutive events, where transactions from k different channels are monitored, and no more than 2 consecutive transactions can occur through the same channel to minimize fraud risk. The sequence length n represents the monitoring window, and k represents the available transaction channels (such as ATM, online banking, point-of-sale, wire transfer).
    

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