#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  string s;
  cin>>s;
  int N = s.size();
  int dp[N][2019] = {};//i番目までに2019で割った余りがいくつあるか

  int p = s.at(0) - '0';
  dp[0][p] = 1;
  for(int i = 1;i<N;i++){
    p = s.at(i) - '0';
    dp[i][p]++;
    for(int k = 0;k<2019;k++){
      dp[i][(10*k)%2019] += dp[i-1][k];
      dp[i][(10*k+p)%2019] += dp[i-1][k];
    }
  }
  cout << dp[N-1][0] << endl;
  return 0;
}