#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int SIZE=2e5;

int ary[SIZE];

const int MOD=2019;
int main(){
    string s; cin>>s;
    for(int i=0;i<s.size();i++){
        ary[i] = s[i]-'0';
    }
    ll res = 0;
    int n = s.size();
    for(int i=0;i<SIZE;i++){
        int sum = 0;
        for(int j=i;j<SIZE;j++){
            sum *= 10;
            sum += ary[j];
            sum %= MOD;
            res += ll(sum==0);
        }
    }
    res -= ll(SIZE-n)*(SIZE-n+1)/2;
    int tmp =1;
    int sum = 0;
    for(int i=n-1;i>=0;i--){
        sum += ary[i]*tmp;
        tmp*=10;
        tmp%=MOD;
        sum%=MOD;
        if(sum==0) res-=SIZE-n;
    }
    cout<<res<<endl;
    return 0;
}
