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

static unsigned int K = 2019;
int R[2019] = {0};

int main(int argc, char* argv[]){
	char str[200000+1]={0};
	int L=0;

	scanf("%s", str);
	L = strlen(str);

	int u0 = atoi(&str[L-1]);
	R[u0]++;
	int r0=1, r1=1;
	int u1=0;
	for(int i=1; i<L; i++){
		char c[2]={0};
		c[0] = str[L-1-i];
		int a = atoi(c);
		//u1 = u0 + a*(10**i)i;
		r1 = (r0*10)%K;
		u1 = a*r1 + u0 ;
		u1 = u1%K;
		R[u1]++;
		r0 = r1;
		u0 = u1;
	}

	long long ans = R[0];
	for(int i=0; i<K; i++){
		int m = R[i];
		if( m>1 ){
			ans += (m*(m-1))/2; 
		}
	}
	printf("%lld\n", ans);
	return 0;
}
