
    At a complex intersection, determine the number of possible ways to arrange n distinct traffic signal phases such that exactly m phase transitions result in higher traffic flow than their subsequent phases, helping optimize the overall traffic light cycle sequence. The solution will help traffic engineers identify optimal signal timing patterns that minimize congestion while maintaining safe traffic flow.
    

    
def eulerian_num(n, m):
    """
    At a complex intersection, determine the number of possible ways to arrange n distinct traffic signal phases such that exactly m phase transitions result in higher traffic flow than their subsequent phases, helping optimize the overall traffic light cycle sequence. The solution will help traffic engineers identify optimal signal timing patterns that minimize congestion while maintaining safe traffic flow.
    

    """
def eulerian_num(n, m):
    """
    At a complex intersection, determine the number of possible ways to arrange n distinct traffic signal phases such that exactly m phase transitions result in higher traffic flow than their subsequent phases, helping optimize the overall traffic light cycle sequence. The solution will help traffic engineers identify optimal signal timing patterns that minimize congestion while maintaining safe traffic flow.
    

    """
    if m >= n or n == 0:
        return 0
    if m == 0:
        return 1
    return (n - m) * eulerian_num(n - 1, m - 1) + (m + 1) * eulerian_num(n - 1, m)