S=io.read()
N=#S
t={}
s={0}
for i=1,N do
	t[i]=tonumber(S:sub(i,i))
	s[i+1]=s[i]+t[i]
end

r=0
for i=1,N do
for j=1,i-3 do
	if((s[i+1]-s[j])%3==0)then
		local n=0
		for k=j,i do
			n=n*10+t[k]
		end
		if(n%673==0)then r=r+1 end
	end
end
end
print(r)