#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

typedef long long ll;

int main(){
	const int MOD = 2019;
	string S;
	cin >> S;
	reverse(S.begin(),S.end());

	ll ans = 0;
	vector<ll> cnt(2020);
	cnt[0] = 1;
	int p = 1; int t=0;
	for(char c : S ){
		int i = c-'0';
		t = (t + i * p) % MOD;
		ans += cnt[t];

		p = p*10;
		p %= MOD;
		cnt[t]++;
	}

	cout << ans << endl;
}