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

using ll = long long;

int nums(char s){
  return s - '0';
}

int main()
{
  string s;
  cin >> s;
  int leng = s.length();
  ll sn = 0;
  vector<int> v(2019, 0);

  v.at(0) = 1;
  int amari = 0;
  int ten = 1;
  for(int i = leng-1; i>=0; i--){
    amari = amari + nums(s[i]) * ten;
    ten *= 10;
    ten %= 2019;
    amari %= 2019;
    // cout << amari << endl;
    v.at(amari) += 1;
  }

  int ans = 0;
  for(int i = 0; i<2019; i++){
    ans += v.at(i) * (v.at(i) -1) /2;
  }
  cout << ans << endl;
}