#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define rep(i,k,n) for(int (i)=(k);(i)<(n);(i)++)
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define abs(a) (a)>0 ?(a):-(a)
#define llong long long

int main(){
	char S[200100]; scanf("%s",S);
	int s[200100],N=strlen(S);
	rep(i,0,N) s[i] = S[N-1-i]-'0';
	int sum[N],mod[2019];
	rep(i,0,2019) mod[i]=0;
	mod[0]++;
	sum[0]=s[0]; mod[sum[0]]++;
	int pow10=1;
	rep(i,1,N){
		pow10 = (pow10*10)%2019;
		sum[i] = (sum[i-1]+pow10*s[i])%2019;
		mod[sum[i]]++;
	}
	llong ans=0;
	rep(i,0,2019){
		ans += mod[i]*(mod[i]-1)/2;
	}
	printf("%lld",ans);
	return 0;
}
