#include<iostream>
#include<string>
#include<vector>
#define MAX 200000
using namespace std;

const long long mod = 2019;
long long dp[2020];

//aC2を返す
long long choose(long long a){
    long long ans;
    ans = a*(a - 1)/2;

    return ans;
}

int main(){
    string s;
    cin >> s;
    int sl = s.size(); //sのサイズ
    //cout << sl << endl;
    //sの累積和を入れる
    vector<int> t(sl),tt(sl); //累積和
    long long ten = 1; //10の累乗
    long long ss; //s.at(i)のlong long 型

    //cout << endl;

    for(int i = sl - 1;i >= 0;i--){
        ss = (s.at(i) - '0');
        t.at(i) = (ten*ss)%mod;
        ten *= 10;
        ten = ten%mod; 
        //cout << i << ":";
        //cout << ten << " ";
        //cout << t.at(i) << endl;
    }

    //累積
    tt.at(0) = t.at(0);
   // cout << tt.at(0) << endl;
    dp[tt.at(0)]++;
    for(int i = 1;i < sl;i++){
        tt.at(i) = (tt.at(i - 1) + t.at(i))%mod;
        //cout << tt.at(i) << endl;
        dp[tt.at(i)]++;
    }

    //mod2019の値が等しいものを見つける

    long long ans = dp[0];

    for(int i = 0;i < mod;i++){
        if(dp[i] >= 2){
            ans += choose(dp[i]);
            //cout << "aaa" << endl;
        }
    }

    cout << ans << endl;

    

    return 0;
}
