#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mx 100000000


int md=1e9+7;
int __gcd(int a, int b) {if(b==0) return a; return __gcd(b, a%b);}
int poww(int a, int b) {int res=1;while(b) {if(b&1){res*=a;res%=md;}a*=a;a%=md;b>>=1;}return res;}
void ainp(int arr[], int n) {for(int i=1;i<=n;i++) cin>>arr[i];}
void vinp(vector<int> v,int n){for(int i=0;i<n;i++){int a;cin>>a;v.push_back(a);}}
map<int, int> mapp;
set<int> s;vector<int> v;

void fun()
{ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}



signed main()
{  fun();
	string s;
	cin>>s;
	int rem=0,pref,nmul=0;
	int n=s.size();
	
set<int> rema[n];
	for(int i=0;i<n;i++)
	{
		rem=0;pref=0;
		for(int j=i;j<n;j++)
		{
			rem=(10*rem+s[j]-'0')%2019;
			//cout<<rem<<"\n";
			if(rema[j].find(rem)!=rema[j].end())
			{
				break;
			}
			rema[j].insert(rem);
			if(rem==0)
			{
				pref++;
			}
		}
		nmul+=pref*(pref+1)/2;
	}
	cout<<nmul<<"\n";
}

