In [46]:
possibilities = []

In [76]:
def find_max_combinations(num):
    possibilities = []
    num_arr = [int(i) for i in str(num)]
    is_invalid = False
    for i in range (0, len(num_arr)):
        if i == 0:
            possibilities.insert(i, 1)
        else:
            possibilities.insert(i, possibilities[i-1])
            
            sum = num_arr[i-1]*10 + num_arr[i]
            if sum > 0:
                if sum <= 26: 
                    if num_arr[i] == 0: #current is 0, append to previous
                        possibilities[i] = possibilities[i-2] if i >= 2 else 1
                    elif num_arr[i-1] == 0: #previous was 0, possibilities would remain same
                        pass
                    else:
                         possibilities[i] = possibilities[i-2] + possibilities[i-1] if i >= 2 else 2
                elif sum > 26 and num_arr[i] == 0:
                    is_invalid = True
                    break
            else:
                is_invalid = True
                break
                
    return 0 if is_invalid else possibilities[len(possibilities) - 1]

In [77]:
while True:
    num = input()
    if num > 0:
        print find_max_combinations(num)
    else:
        break


220
1
0

In [69]:
print find_max_combinations(202002)
print find_max_combinations(200202)
print find_max_combinations(25114)
print find_max_combinations(1010)
print find_max_combinations(1001)
print find_max_combinations(270)
print find_max_combinations(501)
print find_max_combinations(100)
print find_max_combinations(101)
print find_max_combinations(1011)


0
0
6
2
0
0
0
0
1
2

In [ ]: