#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<long long>
#define fin(ar,k,n) for(int i=k;i<n;i++) cin>>ar[i]
#define fout(ar,k,n) for(int i=k;i<n;i++) cout<<ar[i]<<' '
#define all(z) z.begin(),z.end()
#define mcc ((int)1e9+7)
#define mcf 998244353
#define mi map<int,int>
#define mem(a,n) memset(a,n,sizeof(a))
using namespace std;

//ll maxl(ll a,ll b) {return (a>b)? a:b;}
//ll minl(ll a,ll b) {return (a<b)? a:b;}
//ll gcdl(ll a,ll b) {return b ? gcdl(b,a%b):a;}
//bool sortc(const vi &v1,const vi &v2) {return v1[0]>v2[0];}


void solve()
{
    string s;
    cin>>s;
    ll dp[2][2019],ans=0;
    mem(dp,0);
    dp[0][s[0]-'0']=1;
    for (int i=1;i<s.length();i++)
    {
        for (int j=0;j<2019;j++)
        {
            int nxt=(j*10+s[i]-'0')%2019;
            dp[1][nxt]+=dp[0][j];
        }
        ans+=dp[1][0];
        memcpy(dp[0],dp[1],sizeof(dp[1]));
        mem(dp[1],0);
        dp[0][s[i]-'0']++;
    }
    cout<<ans<<endl;
}

#if 1
int main()
{
   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
#endif

//------------------------Google-------------------
#if 0
int main()
{
    #ifdef __WIN32
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t,ct=0;
    cin>>t;
    while(t--)
    {
        cout<<"Case #"<<++ct<<": ";
        solve();
    }
    return 0;
}
#endif
