#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
void main()
{
	int N, ct=0;
	scanf("%d", &N);
	int len = strlen(itoa(N)), i, j;
	char *num;
	num = itoa(N);
	int n=0,k;
	for (i = 0; i < N - 4; i++,n=0)
		for (j = i,k=0; j < N; j++,k++)
		{
			n += pow(10, k)*atoi(num[i]);
			if (n % 2019 == 0)
				ct++;
		}
}