def clamp(MIN: int, n: int, MAX: int) -> int:
    """Clam n in [MIN, MAX["""
    if MIN < MAX:
        return max(MIN, min(n, MAX - 1))
    else:
        raise ValueError("MAX value must be greater than MIN value")