#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200000 + 10;
const int mod = 2019;
map<int, int> M;
char s[maxn];
int n;
ll ans;
int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	reverse(s + 1, s + n + 1);
	int cur = 0, base = 1;
	M[0] = 1;
 	for(int i = 1; i <= n; ++i)
 	{
 		cur = (base * (s[i] - '0') + cur) % mod;
 		base = base * 10 % mod;
 		//cout << cur << endl; 
 		ans += M[cur];
 		++M[cur];
 	}
 	cout << ans << endl;
 	return 0;
 }