#include<stdio.h>
#include<string.h>
#define MOD 2019
#define modml(RHS,LHS) ((RHS) * (LHS) % MOD)
#define modadd(RHS,LHS) (((RHS)+(LHS))%MOD)

static inline int modpow(int num,int ind){
    unsigned cnt = ind;
    int res = 1;
    while(cnt){
        if(cnt & 1u)res = modml(num,res);
        num = modml(num,num);
        cnt >>= 1;
    }
    return res;
}

static inline long long nck2(int n){
    return (n * (n-1)) / 2;
}

int rs[2019];

int main(void){
    register int i;
    char num[200200];
    scanf("%s",num);
    int nlen = strlen(num);
    int cusm[nlen+1];
    int nums[nlen];
    for(i = 0;i < nlen;i++)nums[i] = num[nlen-i-1] - '0';
    cusm[0] = 0;
    for(i = 0;i < nlen;i++)cusm[i+1] = modadd(cusm[i],modml(modpow(10,i),nums[i]));
    for(i = 0;i <= nlen;i++)rs[cusm[i]]++;
    long long ans = 0;
    for(i = 0;i < 2019;i++)ans += nck2(rs[i]);
    printf("%lld",ans);
}