#include <bits/stdc++.h>
using namespace std;

int main(){
  string S;
  int count=0;
  cin>>S;
  map<long long,long long> saves;
  saves[0]++;
  for(long long i=1;i<(long long)S.size()+1;i++){
  string a=S.substr(S.size()-i,i);
    long long b=stoll(a);
    //cout<<b<<endl;
  saves[b%2019]++;
}

    for(auto k=saves.begin();k!=saves.end();k++){
    int amari=k->second;
      count=count+amari*(amari-1)/2;
  }  
      cout<<count<<endl;
}