#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{    
  string S;
  cin >> S;
  int ans = 0;
  int digit_num = S.length();
  if (digit_num <4)
  {
    cout << 0 << endl;
    return 0;
  }
  
  for (int i = 1; i <= digit_num-3; i++)
  {
    for (int j = i+3; j <= digit_num; j++)
    {
      string str_ext = S.substr(i-1, j-i+1);
      int num_ext = atoi(str_ext.c_str());
      if (num_ext%2019 == 0)
      {
        ans ++;
      }

    }
    
  }
  cout << ans << endl;
} 
