#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define N 200000

int main(){
    char S[N+1];
    scanf("%s",S);

    long long count = 0;
    long long Slen = strlen(S);
    long long T[Slen+1];
    long long C[2019];
    for(int i = 0;i<2019;i++) C[i]=0;
    T[Slen]=0;
    
    for(int i = Slen-1;i>-1;i--) T[i] = (T[i+1] + (long long)pow(10,Slen-1-i)% 2019*(S[i]-'0')) % 2019;
    for(int i = 0;i<Slen+1;i++) C[T[i]]++;
    for(int i = 0;i<2019;i++) count+=(C[i]-1)*(C[i])/2.0;
    printf("%lld\n",count);
    return 0;
}