def valid_under_constraints(
    word: str, positions: dict[int, str], appears: set[str], no_appears: set[str]
) -> bool:
    """Check if the word is valid under the constraints."""
    return (
        all(word[i] == x for i, x in positions.items())
        and all(char in word for char in appears)
        and all(char not in word for char in no_appears)
    )