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