#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s;
ll num,t=1,ans;
ll cnt[2200];//记录余数的个数 
int main()
{
  cnt[0]=1;// 
  cin>>s;
  for(int i=s.size()-1;i>=0;i--)
  {
  	 num=(num+(s[i]-'0')*t)%2019;
  	 ans+=cnt[num];
  	 cnt[num]++;
	 t=t*10%2019; 
  }
   cout<<ans;
return 0;
}
