#include<stdio.h>
#include<math.h>
int main()
{
    int i, j, length = 0, sum = 0;
    unsigned long long int s,num;
    scanf("%llu", &s);
    unsigned long long int s2 = s;
    while (s2 > 0)
    {
        s2 /= 10;
        length++;
    }
    for (i = 1;i <= length - 3;i++)
    {
        for (j = length;j >= i + 3;j--)
        {
            num = (s % (unsigned long long int)pow(10,length - i+1)) / (unsigned long long int)pow(10,length - j);
            if (num % 2019 == 0) sum++;
        }
    }
    printf("%d", sum);
    return 0;
}
