Loop to find the occurrences of x and update the ans
for i in range ( len ( y ) ) : NEW_LINE INDENT if ( y [ i ] == x ) : NEW_LINE INDENT ans += ( modInv ( fact [ i ] ) * modInv ( fact [ len ( y ) - i - 1 ] ) ) % MOD ; NEW_LINE ans %= MOD ; NEW_LINE DEDENT DEDENT