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

int main() {
  string S;
  int N,count;
  cin >> S;
  N = S.size();
  vector<int> A(N);
  
  for (int i = 0; i < N; i++) {
    if( S.at(i) == '0' ){A.at(i) = 0;continue;}
    if( S.at(i) == '0' ){A.at(i) = 0;continue;}
    if( S.at(i) == '1' ){A.at(i) = 1;continue;}
    if( S.at(i) == '2' ){A.at(i) = 2;continue;}
    if( S.at(i) == '3' ){A.at(i) = 3;continue;}
    if( S.at(i) == '4' ){A.at(i) = 4;continue;}
    if( S.at(i) == '5' ){A.at(i) = 5;continue;}
    if( S.at(i) == '6' ){A.at(i) = 6;continue;}
    if( S.at(i) == '7' ){A.at(i) = 7;continue;}
    if( S.at(i) == '8' ){A.at(i) = 8;continue;}
    if( S.at(i) == '9' ){A.at(i) = 9;continue;}
  }
  for (int i = 0; i < (N-3); i++) {
    int judge,B,C;
    judge = A.at(i)+A.at(i+1)+A.at(i+2);
    B = A.at(i) * 100+A.at(i+1)*10+A.at(i+2);
    for (int l = i+3; l < N; l++) {
      judge += A.at(l);
      B *= 10;
      B += A.at(l);
      if((judge % 3) != 0){
        continue;
      }
      C = B/3;
      if((C % 619) == 0){
        count++;
      }
    }   
  }
  cout << count <<endl;
}