#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  string s;
  cin>>s;
  s='!'+s;
  ll R,r,p,j,i=1;
  set<ll> a[s.size()+9];
  ll ans=0;
  while(i<s.size())
  {
  	R=0;
  	r=0;
  	p=0;
  	j=i;
  	while(j<=s.size())
  	{
  		R*=10;
  		R%=3;
  		R+=(ll)(s[j]-'0');
  		R%=3;
  		r*=10;
  		r%=673;
  		r+=(ll)(s[j]-'0');
  		r%=673;
  		if(a[j].find(r)!=a[j].end())
  			break;
  		a[j].insert(r);
  		if(r==0&&R==0)
  			p++;
  		j++;
  	}
  	ans+=p*(p+1)/2;
  	i++;
  }
  deb(ans);
}
