#include <bits/stdc++.h>
#define pb push_back
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
int a[200005];
int mp[2100];
signed main()
{
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	int y=1;
	for (int i=0;i<sz(s);i++){
		a[i]=(y*(s[i]-'0'))%2019;
		y=(y*10)%2019;
	}
	y=0;
	for (int i=0;i<sz(s);i++){
		y=(y+a[i])%2019;
		mp[y]++;
	}
	int ans=0;
	for (int i=0;i<2019;i++)
		ans=ans+mp[i]*(mp[i]-1)/2;
	ans+=mp[0];
	cout<<ans;
	re 0;
}