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

typedef long long ll;

int main(){
  string s;
  cin >> s;
  long long  count = 0,number,sum=0;
  long long length = s.length();
  for(int i=0;i<length;i++){
    number=s[i]-'0';
    count=s[i]-'0';
    for(int j=i+1;j<length;j++){
      number = number*10+s[j]-'0';
      count += s[j]-'0';
      if(count%3==0) {
	if(number%2019==0) sum++;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
