#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length();
    vector<int> a(n+1);
    int tmp=1;
    ll c[2019]={1};
    ifr(i,n){
        a[i]=a[i+1];
        a[i]+=(s[i]-'0')*tmp;
        a[i]%=2019;
        tmp*=10;
        tmp%=2019;
        c[a[i]]++;
    }
    ll ans{};
    fr(i,2019) ans+=c[i]*(c[i]-1)/2;
    cout<<ans<<endl;
}