#include <bits/stdc++.h>

using namespace std;
#define ll long long int

ll f[2020];
int main()
{
    string s;
    cin >> s;
    f[0]=1;
    ll ans = 0, mod = 0;
    ll curr = 1;
    for(int i=s.length()-1;i>=0;i--){
        mod = (mod+curr*(s[i]-'0'))%2019;
        curr = (curr*10)%2019;
        ans+=f[mod];
        f[mod]++;
    }
    cout << ans << endl;
}
