#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589;

int main(){
  string s;
  cin >> s;
  int ans=0;
  int c[200000];
  rep(i, s.size()){
    c[i] = s.at(i) - '0';
    if(c[i]==0) ans++;
  }
  int a = s.size();
  int dp[2][2019];
  dp[0][c[0]]++;
  
  for(int i = 1; i < a; i++){
    if(c[i] == 0){
       for(int j = 0; j<2019; j++){
         dp[1][(10*j + c[i]) % 2019] = dp[0][j];
       }
      for(int j = 0; j < 2019; j++){
        dp[0][j] = dp[1][j];
      }
      continue;
    }else{
       for(int j = 0; j<2019; j++){
         dp[1][(10*j + c[i]) % 2019] = (10*j + c[i])%2019==c[i] ? dp[0][j]+1: dp[0][j];
       }
      for(int j = 0; j < 2019; j++){
        dp[0][j] = dp[1][j];
      }
    }
    ans+=dp[0][0];
  }
  cout<<ans<<endl;
}