#include <stdio.h>
#include <string.h>
#define N 200002
#define M 2019

char a[N];
int c[M] = {1};

int main()
{		
	int n, i, p10, x;
	long long ans = 0;
		
	scanf("%s", a);
	i = strlen(a) - 1;
	c[x = a[i] - 48] = p10 = 1;
	for(i--; i >= 0; i--){
		p10 = p10 * 10 % M;
		x += p10 * (int)(a[i] - 48) % M;
		if(x >= M) x -= M;
		ans += c[x];
		c[x]++;
	}
	printf("%lld\n", ans);
			
	return 0;
}