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

int main() {
  string s;
  cin >> s;
  reverse(s.begin(),s.end());

  map<long long, long long> mp;
  mp[0] = 1;
  long long now = 0, ten = 1;

  for(auto e:s){
    now = (now + (e - '0') * ten) % 2019;
    ten *= 10;
    ten %= 2019;
    mp[now]++;
    cout << now << endl;
  }

  long long ans = 0;
  for(auto e:mp){
    ans += e.second * (e.second - 1) / 2;
//    cout << e.first << " : " <<  e.second << " : " << ans << endl;
  }
  cout << ans << endl;
}