#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

ll combi(ll a,ll b)
{
    ll ret=1;
    for(ll i=a;i>a-b;i--)
    {
        ret*=i;
    }
    for(ll i=b;i>0;i--)
    {
        ret/=i;
    }
    return ret;
}

int main()
{
    string s;
    cin>>s;
    int n=s.length();
    vector<ll > dp(n+1,0);
    ll ans =0;
    int ten=1;
    for(int i=n-1;i>=0;i--)
    {
        dp[i]=(dp[i+1]+(s[i]-'0')*ten%2019)%2019;
        ten*=10;
        ten%=2019;
    }
    vector<int> p(2019,0);
    for(int i=n;i>=0;i--)
    {
        ans+=p[dp[i]];
        p[dp[i]]++;
    }
    cout<<ans;
}
