#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順

using namespace std;
using ll = long long int;

ll mod_pow(ll a,ll index,ll divider){
    ll ret = 1;
    for(;index>0;index/=2,a=a*a%divider){
        if(index%2==1){
            ret = ret * a % divider;
        }
    }
    return ret;
}

int main(){
    ll cnt[2020] = {0};
    string S;cin>>S;
    int a;
    vector<int> num(S.length()+1);
    num[S.length()] = 0;
    for(int j=S.length()-1;j>=0;j--){
        a = S[j] - '0';
        num[j] = num[j+1] + a*mod_pow(10,S.length()-j-1,2019);
        num[j] %= 2019;
        cnt[num[j]]++;
    }
    ll ans = cnt[0] * (cnt[0] + 1) / 2;
    for(int i=1;i<2020;i++){
        ans += cnt[i] * (cnt[i] - 1 ) / 2;
    }
    cout << ans << endl;
    return 0;
}