def next_pow_two(max_sent_tokens):
    """
    Next power of two for a given input, with a minimum of 16 and a
    maximum of 512

    Args:
        max_sent_tokens (int): the integer

    Returns:
        int: the appropriate power of two
    """
    pow_two = [16, 32, 64, 128, 256, 512]
    if max_sent_tokens <= pow_two[0]:
        return pow_two[0]
    if max_sent_tokens >= pow_two[-1]:
        return pow_two[-1]
    check = [max_sent_tokens > j for j in pow_two]
    idx = check.index(False)
    return pow_two[idx]