前缀和,把时间复杂度降到O(n)

l = [int(i) for i in input().strip()][::-1]
lenl = len(l)
sum1 = sum(l)
if sum1%9 == 0:
    cnt = 1
else:
    cnt = 0
for i in range(lenl-1):
    sum1 -= l[i]
    if sum1%9 == 0:
        cnt += 1
print(cnt)