• + 2 comments

    Useful remark (especially for Python3 programmers): try to avoid big integer math (> 2 ** 64). Instead of:

    for ... :
        total *= m
    
    print(total % 1000000007)
    

    do:

    for ... :
        total = (total * m) % 1000000007
    
    print(total)
    

    This trick dramatically decreases execution time.