#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int count = 0;
void judge(unsigned long int num,int len,unsigned long long last,int t)//t标记上个数的位数
{
    unsigned long long  start;
    int j = 0;
    do
    {
        start = num % ((unsigned long long int)pow(10, 4+j));
        j++;
        if (j > len-3)
            break;
    } while (start %2019 );
    if (j <=len -3)
    {
        last  = start*(pow(10, t))+last;//第一次应该传入i=0
        count++;
        if (len -4-j>=3)
        {
            judge((num -start)/(pow(10, 3+j)), len -3-j,last ,t+j+3 );
        }
    }
}

int main()
{
    char input[1000];
    int len,i;
    char * end;
    unsigned long long  num;
    fgets(input, 1000, stdin);
    len = (int)strlen(input)-1;//减去回车
    num = strtoull(input, &end, 10);
    for (i = 0; i<len -3; i++)
    {
        judge(num,len-i, 0, 0);
        num /= 10;
    }
    printf("%d",count);
    return 0;
}