#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <deque>
#include <map>

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define LEN(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

int a[200001],p[2020];

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s; cin >>s;
	reverse(ALL(s));
	int i,tmp=1,ans=0;
	for (i=0;i<s.size();i++) {
		a[i]=(tmp*(s[i]-'0'))%2019;
		tmp=(tmp*10)%2019;
	}
	tmp=0;
	for (i=0;i<s.size();i++) {
		tmp=(tmp+a[i])%2019;
		p[tmp]++;
	}
	for (i=0;i<2019;i++) {
		ans+=p[i]*(p[i]-1)/2;
	}
	ans+=p[0];
	cout <<ans;
	return 0;
}
/******************************************************************************
******************************************************************************/
