#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;
bool isMultiple (string s, int base, int m) {
	ll temp = 0;
	for (int i=0; i<s.length(); i++) {
		temp = (temp*base+s[i]-'0')%m;
	}
	if (temp==0) {return true;}
	return false;
}
void solve()
{
	string s;
	cin>>s;
	vector<int>dsum(size(s));
	int t=0;
	vector<vector<int>>three(3);
	set<string>ans;
	map<string,int>app;
	rep(i,size(s)){
		t+=s[i]-'0';
		three[t%3].push_back(i);
	}
	int cnt=0;
	rep(i,3){

		rep(j,size(three[i])){
			if(i==0 && three[i][j]>=3){
				ans.insert(s.substr(0,three[i][j]+1));
				app[s.substr(0,three[i][j]+1)]++;
				//cnt+=isMultiple(s.substr(0,three[i][j]+1),10,2019);		
			}
			FOR(k,j+1,size(three[i])){
				ans.insert(s.substr(three[i][j]+1,three[i][k]-three[i][j]));
				app[s.substr(three[i][j]+1,three[i][k]-three[i][j])]++;
				//cnt+=isMultiple(s.substr(three[i][j]+1,three[i][k]-three[i][j]),10,2019);
			}
		}
	}
	for(auto i=ans.begin();i!= ans.end();i++){
		cnt+=app[*i]*isMultiple(*i,10,2019);
	}
	/*FOR(i,4,size(s)+1){
		int digitsum=0;
		rep(j,i){
			digitsum+=s[j]-'0';
		}
//		cout<<digitsum<<endl;
		if(digitsum%3==0){
			cpp_int tmp(s.substr(0,i));
			if(tmp%673==0){
				cnt++;
				//cout<<tmp<<endl;
				//cout<<1<<" "<<i<<endl;
			}
		}
		FOR(k,i,size(s)){
			
			digitsum-=s[k-i]-'0';
			digitsum+=s[k]-'0';
			//cout<<" "<<digitsum<<endl;
			if(digitsum%3==0){
				cpp_int tmp(s.substr(k-i+1,i));
				if(tmp%673==0){
					cnt++;
					//cout<<<<" "<<k+i<<endl;
				}
			}
		}
	}*/
	cout<<cnt<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}
