import itertools

s = input()
A = list(int(x) for x in s)
S = [0] * (len(s) + 1)
S[1:] = itertools.accumulate(A)

ans = 0
for j in range(4, len(s)):
    for i in range(len(s) - j + 1):
        x = int(s[i:i + j])
        if (S[i + j] - S[i]) % 3 == 0:
            if int(s[i:i + j]) % 673 == 0:
                ans += 1
                i = i + j - 1
print(ans)
