#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>

int main()
{
  std::string s;
  std::cin >> s;
  std::unordered_map<int, int> modMap;
  const int mod = 2019;
  int64_t tmp = 0;
  int64_t digit = 1;
  for (int i = s.size() - 1; i >= 0; --i)
  {
    tmp = tmp + digit * (s[i] - '0');
    modMap[tmp % mod]++;
    digit *= 10;
  }
  int64_t ans = 0;
  for (auto itr : modMap)
  {
    ans += itr.second * (itr.second - 1) / 2;
  }
  ans += modMap[0];
  std::cout << ans << std::endl;
  return 0;
}