class Solution:
def isAdditiveNumber(self, num: str) -> bool:
n = len(num)
for i, j in itertools.combinations(range(1, n), 2):
# 第一个数是从0到i-1, 第二个数是i到j-1
a, b = num[:i], num[i:j]
if a != str(int(a)) or b != str(int(b)):
continue
while j < n:
c = str(int(a) + int(b))
if not num.startswith(c, j): break
j += len(c)
a, b = b, c
if j == n: return True
return False