#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    ll ans=0;
    cin>>s;
    
    vec<pair<ll,ll>> a(s.size()+1);
    for(ll i=s.size();i>0;i--){
        string c=s.substr(s.size()-i);
        ll l=stoll(c, nullptr, 10);
        a[i].first=l;
        a[i].second=i;
    }
    
    for(ll i=0;i<a.size();i++){
        for(ll j=i+1;j<a.size();j++){
            ll sum=a[j].first-a[i].first;
            if(min(a[j].second,a[i].second)!=0) sum=sum/(10*min(a[j].second,a[i].second));
            if(sum%2019==0) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
