// Problem : Multiple of 2019
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc164_d
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

struct NumberTheory{
	//mult,normalize,div,add,sub,fact,finv,ncr,pow,inv
	vector<ll> factorial={1},factorialInv={1};
	ll mod=2019;
	inline ll mult(ll a,ll b){
		return (a*b)%mod;
	}
	inline ll norm(ll x){
		x%=mod;
		if(x<0) x+=mod;
		return x;
	}
	inline ll div(ll a,ll b){
		return mult(a,inv(b));
	}
	inline ll sub(ll a, ll b){
		return norm(a-b);
	}
	inline ll add(ll a,ll b){
		return (a+b)%mod;
	}
	//using ll so it works with both int and ll
	ll ncr(ll n,ll r){
		assert(n>=0);
		if(r<0 || n<r)
			return 0;
		return mult(fac(n),mult(finv(r),finv(n-r)));
	}
	ll finv(ll n){
		int last=factorialInv.size()-1;
		if(last<n){
			//this was as mult is easier than cal inverse again
			//mult in O(1) while inv in log(mod)
			vector<ll> finv_temp(n-last);
			finv_temp[0]=inv(fac(n));
			for(int i=1;i<(int)finv_temp.size();i++){
				finv_temp[i]=mult(finv_temp[i-1],n-i+1);
			}
			for(int i=finv_temp.size()-1;i>=0;i--){
				factorialInv.push_back(finv_temp[i]);
			}
		}
		return factorialInv[n];
	}
	ll pow(ll x,ll e){
		if(e<0){
			x=inv(x);
			e*=-1;
		}
		ll res=1;
		while(e>0){
			if(e&1)
				res=mult(res,x);
			e=e>>1;
			x=mult(x,x);
		}
		return res;
	}
	
	inline ll inv(ll x){
		//currently using fermat little
		return pow(x,mod-2);
	}
	
	ll fac(int n){
		while((int)factorial.size()<=n){
			factorial.push_back(mult(factorial[factorial.size()-1],factorial.size()));
		}
		return factorial[n];
	}
};

int main() {
    fast_io;
    NumberTheory nt;
    string s; cin>>s; int n=s.length();
    vi t(n+1);
    vi freq(2019);
    t[n]=0;
    //for tn;
    freq[0]++;
    for(int i=n-1;i>=0;i--){
    	t[i]=nt.add(t[i+1],nt.mult(nt.pow(10,n-1-i),s[i]-'0'));
    	freq[t[i]]++;
    }
    ll ans=0;
    for(int x:freq){
    	ans+=(ll)x*(x-1)/2;
    }
    cout<<ans;
}

Measured memory_bytes: 4348