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

int main()
{
    char s[200000];
    
    scanf("%s",s);

    int len = strlen(s);
    int i,j;

    int T[200001] = {0};
    T[len] = 0;
    int count2019[2019] = {0};
    count2019[0] = 1;
    int dig = 1;
    for (i = len - 1; i >= 0; i--)
    {   
        T[i] = (T[i + 1] + dig * (s[i] - '0')) % 2019;
        count2019[T[i]]++;
        dig *= 10;
        dig %= 2019;
    }

    long long ans = 0;
    for (i = 0; i < 2019; i++)
    {
        ans += count2019[i] * (count2019[i] - 1) / 2;
    }
    
    printf("%lld",ans);
}
