#include <bits/stdc++.h>

using namespace std;

int main()
{
  string s;
  cin >> s;
  int n = s.length();
  int dp[n][2019];
  memset(dp, false, sizeof(dp));
  dp[n-1][s[n-1]-'0'] = 1;
  int curr = 10;
  for(int i=n-2;i>=0;i--)
  {
    int z = ((s[i]-'0')*curr)%2019;
    for(int j=0;j<2019;j++)
    {
      if(dp[i+1][j])
      {
        int y = (z+j)%2019;
        dp[i][y] += dp[i+1][j];
      }
    }
    dp[i][z] += 1;
    curr = (curr*10)%2019;
  }
  int ans = 0;
  for(int i=0;i<n;i++)
    ans += dp[i][0];
  cout << ans << "\n";
  return 0;
}
          
          
          
          