#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
/*
string S_str[H];
cins(S_str, S_str + H);
S_str[i][j];
*/
inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i, n) for(ll i = 0; i < n; i++)

#define rrep(i,a,b) for(int i=a;i>=b;i--)

int N; string S;
int cnt[2019];
//---------------------------------------------------------------------------------------------------
int main() {
	cin >> S;
	ll ans = 0;
  ll N = S.length();


		int cu = 0; int dg = 1;

		rrep(i, N - 1, 0) {
			cu = (cu + dg * (S[i] - '0')) % 2019;
			dg = (dg * 10) % 2019;

			ans += cnt[cu];
			if (cu == 0) ans++;

			cnt[cu]++;
		}


	cout << ans << endl;
}

/*
int main(){
  string s;
  cin >> s;
  int n = s.length();

  ll num[n];
  ll cnt[2019]={0};
  ll ans=0;
  rep(i,n){
    num[i]=  stoll(s.substr(i));


    ans += cnt[num[i]%2019];
    cnt[num[i]%2019]++;
  }
  ans += cnt[0];


  cout <<ans<<endl;


}
*/
