#include <stdio.h>
#include <math.h>

int main()
{
    char c;
    int i = 0, j = 0;
    int length;
    int number[200000] = {0};
    int multiple = 0;
    int digit = 0;
    int result;
    while ((c = getchar()) != '\n')
    {
        number[i] = c - '0';
        i++;
    }
    length = i;

    for (digit = 4; digit <= length; digit++) //每次取多少位进行判断
    {
        for (i = 0; i <= length - digit; i++) //从第一位开始取digit位逐个进行判断
        {
            for (j = digit; j >= 0; j--)
            {
                multiple += pow(10, j-1) * number[i + digit - j];
            }
            if (!(multiple % 2019))
            {
                result += 1;
            }
            multiple = 0;
        }
    }
    printf("%d", result);

    return 0;
}