#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

string s;
set<ll>st[2019];
ll solve(){
   ll n=s.size();
   ll ans=0;
   rep(i,n){
       ll rem=0,pre=0;
       for(int j=i;j<n;j++){
           rem=(10*rem+(s[j]-'0'))%2019;
           if(st[j].count(rem)!=0)break;
           st[j].insert(rem);
           if(rem==0)
           {
               pre++;
           }
       }
       ans+=pre*(pre+1)/2;
   }
   
   return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>s;
    cout<<solve()<<endl;
    return 0;
}