def clamp(n, minn, maxn):
    """
    Clamp an integer to a certain range.
    :param n: int to be clamped
    :param minn: lower bound
    :param maxn: upper bound
    :return: clamped int
    """
    return min(max(n, minn), maxn)