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

#define N_MAX 200000
#define MODVAL 1000000007

int main(void){
	char s[200000];
	int l;
	int i;
	int j;
	int num;
	long long int ret;
	long long int gain;
	ret = 0;

	scanf("%s",s);
	l = strlen(s);


	for(i=l-1;i>=3;i--){
		num =  s[i]-48;
		num += (s[i-1]-48) * 10;
		num += (s[i-2]-48) * 100;
		gain = 1000;
		for(j=i-3;j>=0;j--){
			num += (s[j]-48) * gain;
//			printf("(%d,%d):%d\n",i,j,num % 2019);
			if(num % 2019 == 0){
				ret++;
			}
			gain *= 10;
			gain = gain % 1000000007;
		}
	}


	printf("%d\n",ret);
	return 0;
}