#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()

#define fast cin.tie(0); ios::sync_with_stdio(false)

int32_t main(){ fast;
	
	string s; cin>>s;
	vector<ll> dp(2019);
	ll answer = 0;
	for(char c: s){
		vector<ll> new_dp(2019);
		rep(i, 2019){
			new_dp[(i * 10 + (c - '0')) % 2019] += dp[i];
		}
		new_dp[c - '0']++;
		answer += new_dp[0];
		dp = new_dp;
	}
	cout<<answer<<endl;
}
