from functools import cache import sys @cache def f(check: int, i: int, nums_list: str, is_limited: bool, is_num: bool): count = 0 if is_limited: up = int(nums_list[i]) else: up = 9 if i == len(nums_list) - 1: for k in range(int(not is_num), up + 1): ...