def find_value(x, replacements, var_values):
    if (x in var_values):
        return var_values[x]
    elif (x in replacements):
        (y, sgn) = replacements[x]
        value = find_value(y, replacements, var_values)
        var_values[x] = (value if (sgn == 1) else (1 - value))
        return var_values[x]
    else:
        raise QiskitOptimizationError('Invalid values!')
def find_value(x, replacements, var_values):
    if (x in var_values):
        return var_values[x]
    elif (x in replacements):
        (y, sgn) = replacements[x]
        value = find_value(y, replacements, var_values)
        var_values[x] = (value if (sgn == 1) else (1 - value))
        return var_values[x]
    else:
        raise QiskitOptimizationError('Invalid values!')