/*
	Name: Prathamesh Shendarkar
	My Motto: IS TO NEVER GIVE UP
	My Belief: If you are not able to solve a particular question don't copy and paste a solution, 
			  no one is going to look into your account and tell you that, oh my look he has solved so many questions, 
			  remeber you are cheating on yourself, Just try to solve that question after some time or some days, 
			  or look upon a solution and check for the intiution or approach they have used, 
			  But never mug up there solution. 
			  Go for Learning don't copy plz.
*/

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ll long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define loop(x,n) for(ll i=x;i<n;i++)
#define loopa(x,n) for(ll j=x;j<n;j++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}

ll exp(ll x,ll y){ 
	ll res=1;
	x=x%mod;
	while(y>0) 
	{ 
		if(y&1) 
			res=(res*x)%mod; 
		y = y>>1;
		x=(x*x)%mod; 
	} 
	return res; 
}

// This is fermat's little theorem
ll exp_mod(ll x,ll y, ll p){ 
	ll res=1;
	x=x%p;
	while(y>0) 
	{ 
		if(y&1) 
			res=(res*x)%p; 
		y = y>>1;
		x=(x*x)%p; 
	} 
	return res; 
} 

using namespace std;

ll check_prime(ll n){
	for(ll i = 2;i<=ceil(sqrt(n));i++){
		if(n%i == 0){
			return 0;
		}
	}
	return 1;
}

// This is extended eucledian algorithm
ll d,x,y;
void extended_euclid(ll a, ll b){
	if(b == 0){
		d = a;
		x = 1;
		y = 0;
	}else{
		extended_euclid(b, a%b);
		int temp = x;
		x = y;
		y = temp - (a/b)*y;
	}
}

ll mod_inverse(ll a, ll p){
	extended_euclid(a,p);
	return (x%p + p)%p;
}

// To Check if any number is a multiple of any other number or how many numbers in a string are there which are multiple of k integer
// It is from ATcoder 164 contest D Task
ll multiplesofnumber(string s, ll m){
	vector<ll> v(2019);
	v[0] = 1;
	ll n = s.size();
	ll ans = 0,r = 0,x = 1;
	for(ll i = n - 1;i>=0;i--){
		r = (r + (s[i] - '0')*x)%m;
		r = r%m;
		x = (x*10)%m;
		ans += v[r];
//		cout << ans << " " << v[r] << "\n";
		v[r]++;
	}	
	return ans;
}

int main(){
    fastio;
    
    // 1. To calculate Modular Multiplicative Inverse using fermat's little theorem
    // It is used in div of two numbers with mod, i.e (a/b)%mod => (a%mod * x%mod)%mod , where x 
    // Is nothing but multiplicative inverse of a
    // This was fermat little theorem
//	 ll a,p;
//	 cin >> a >> p;
//	 cout << exp_mod(a, p - 2, p) << "\n";
	
	// 2. TO calculate gcd, function is present above The time complexity is O(log(max(A, B))).
	// This is extended eucledian algo
//	cout << mod_inverse(a, p) << "\n";
	string s;
	cin >> s;
	cout << multiplesofnumber(s,2019) << "\n";
}


/* <--SOME IMPORTANT CONCEPTS-->
  #1.
  ascii value for A-Z 065-096
  ascii value for a-z 097-122
  conversion:  lower=upper+32
  
  #2.
  converting a number to string:
  
  step:1 include the following class:
          #include<sstream>
  step:2  ostringstream st;
  
  step 3: st<<num
  
  step 4: string s=st.str();
  
  #3 
  converting a string to number
  
  step:1 include the following class:
          #include<sstream>
  
  step:2  stringstream val(s); //s is the string
  
  step:3  int y=0;
  
  step 4: val>>y;
  
  now y is the numeric form of the string

#4
  
  sorting in descending order
  
  sort(arr, arr+n, greater<int>());
 #5
  
  to convert a char to numeric
  (the character is c)
   c-'0'

 #6
  
  for(int &x:a)
  cin>>x;
  for(int &x:b)
  cout<<x<<" ";

#7    [bitwise left shift] 
       1<<n=pow(2,n)

#8
        [bitwise right shift]

         n>>k=n/pow(2,k)

#9
 clock_t start, end; 
  start = clock(); 
fun();
end = clock(); 

double time_taken 
        = double(end - start) 
          / double(CLOCKS_PER_SEC); 

cout << "Execution time: " << time_taken 
         << " secs";


*/




Measured memory_bytes: 3816