#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;


const ll mod = 1e9+7;
const double eps = 1e-9;


string s;
int dp[2019];

void solve(){
    cin>>s;
    int n=(int)s.size();
    ll ans=0;
    for(int i=0;i<n;i++) {
        int tdp[2019];
        memset(tdp,0,sizeof(tdp));
        int d=(s[i]-'0');
        tdp[d%2019]=1;
        for(int j=0;j<2019;j++) {
            if(dp[j]>0) { 
                int rem=(10*j+d)%2019;
                if(rem==0)ans += dp[j];
                tdp[rem]+=dp[j];
            }
        }
        for(int i=0;i<2019;i++) {
            dp[i]=tdp[i];
        }
    }
    cout<<ans;
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}
