#include <stdio.h>
#include <string.h>

int stoi(char *str, const int size)
{
    int ret = 0;
    for (int i = 0; i < size; i++)
    {
        ret *= 10;
        ret += (str[i] - '0');
    }

    return ret;
}

int main()
{
    int n, cnt = 0;
    char str[200001] = {
        0,
    };
    scanf("%s", str);
    n = strlen(str);

    for (int i = 0; i < n; i++)
    {
        int temp = stoi(str + i, 5);
        int remainder = temp % 2019;
        if (remainder == 0)
            cnt++;
        for (int j = i + 6; j < n; j++)
        {
            remainder = ((remainder * 10) % 2019) + (str[i] - '0');
            if (remainder == 0)
                cnt++;
        }
    }

    printf("%d", cnt);

    return 0;
}