function to pregenerate factorials
def pregenFact ( ) : NEW_LINE INDENT fact [ 0 ] = fact [ 1 ] = 1 NEW_LINE for i in range ( 1 , 1000001 ) : NEW_LINE INDENT fact [ i ] = fact [ i - 1 ] * i % mod NEW_LINE DEDENT DEDENT