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



int main() {
    long long ans=0;
    int k, l;
    vector<int> dp(200000);
    string s;
    cin >> s;
    map<int, int> m;
    k=0;
    m[k]=1;
    for(int i=s.size()-1; i>=0; i--) {
        l=(int)(s[i]-'0');
        if(i==s.size()-1) dp[i]=1;
        else dp[i]=dp[i+1]*10;
        dp[i]%=2019;
        k=l*dp[i]+k;
        k%=2019;
        if(m.count(k)) m[k]++;
        else m[k]=1;
    }
    for(int i=0; i<2019; i++) {
        if(m.count(i)) {
            ans+=m.at(i)*(m.at(i)-1)/2;
        }
    }
    cout << ans;
}