local MOD=2019
local function add(a,b)return (a+b)%MOD end
local function sub(a,b)return (a-b)%MOD end
local function mul_(a,b)
	local ret=0
	while(b>0)do
		if(b%2==1)then ret=(ret+a)%MOD end
		a=(a+a)%MOD
		b=math.floor(b*.5)
	end
	return ret
end
local function mul(a,b)
	return a<b and mul_(b,a)or mul_(a,b)
end
local function pow(a,b)
	local ret=1
	while(b>0)do
		if(b%2==1)then ret=mul(ret,a)end
		a=mul(a,a)
		b=math.floor(b*.5)
	end
	return ret
end
local function inv(x)
	local a=x
	local b,u,v=MOD,1,0
	repeat
		local t=math.floor(a/b)
		a,b=b,a-t*b
		u,v=v,u-t*v
	until(b==0)
	return u%MOD
end
local function div(a,b)return mul(a,inv(b))end
t={}
s={0}
while 1 do
	local a=io.read(1)
	if not(a)then break end
	table.insert(t,tonumber(a))
	table.insert(s,s[#s]+t[#t])
end
N=#t

dp={[0]=0}
a={[0]=1}
for i=1,N do
	dp[i]=add(dp[i-1],mul(t[N-i+1],pow(10,i-1)))
	if(a[dp[i]])then
		a[dp[i]]=a[dp[i]]+1
	else
		a[dp[i]]=1
	end
end
c=0
for _,v in pairs(a)do
	c=c+v*(v-1)/2
end
print(c)