#include <bits/stdc++.h>
using namespace std;
#define ll long long;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;cin>>s;
	reverse(s.begin(), s.end());
	int n = s.size();
	int pref[n], mod = 2019, ten = 1;
	pref[0] = s[0] - '0';
	map<int, int> mp;
	mp[0] = 1;
	mp[pref[0]] = 1;
	for(int i = 1; i < n; ++i){
		ten*=10;
		ten%=mod;
		pref[i] = pref[i-1] + ten*(s[i]-'0');
		pref[i] %= mod;
		mp[pref[i]]++;
	}
	int cnt = 0;
	for(auto x : mp){
		cnt += (x.second-1)*x.second/2;
	}
	cout<<cnt<<endl;
	return 0;
}

