1class Solution:2def scoreOfStudents(self, s: str, answers: List[int]) -> int:34@cache5def fn(lo, hi):6"""Return possible answers of s[lo:hi]."""7if lo + 1 == hi:8return {int(s[lo])}9ans = set()10for mid in range(lo + 1, hi, 2):11for x in fn(lo, mid):12for y in fn(mid + 1, hi):13if s[mid] == "+" and x + y <= 1000:14ans.add(x + y)15elif s[mid] == "*" and x * y <= 1000:16ans.add(x * y)17return ans1819target = eval(s)20cand = fn(0, len(s))21ans = 022for x in answers:23if x == target:24ans += 525elif x in cand:26ans += 227return ans