Generating prefix - sum of hash of a
mul [ 0 ] = 1 NEW_LINE hash_a [ 0 ] = ( ord ( a [ 0 ] ) - 97 ) % mod NEW_LINE for i in range ( 1 , len ( a ) ) : NEW_LINE INDENT mul [ i ] = ( mul [ i - 1 ] * d ) % mod NEW_LINE hash_a [ i ] = ( hash_a [ i - 1 ] + mul [ i ] * ( ord ( a [ i ] ) - 97 ) ) % mod NEW_LINE DEDENT