#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
typedef long long ll;
char S[200000];
ll c(ll n,ll a){
    ll ans=1;
    for(ll i=1;i<=a;i++)
        ans *= (n+1-i);
    for(ll i=1;i<=a;i++)
        ans /= i;
    return ans;
}

int main(){
    scanf("%s",S);
    ll length = strlen(S);
    ll keep_mod[200000] = {0};
    ll l_ans = 0,keep=0,keep_tenmod = 1;
    for(ll i=length-1;i>=0;i--){
        keep += (S[i]-'0')*keep_tenmod;
        keep %= 2019;
        keep_tenmod *= 10;
        keep_tenmod %= 2019;
        keep_mod[keep]++;
    } 
    ll ans = keep_mod[0];
    for(ll i=0;i<2019;i++)
        if(keep_mod[i] >= 2) ans += c(keep_mod[i],2);
    printf("%lld",ans);
}

