#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int counter[200010];
int rui[200010];
const int P=2019;
int ans;
int N;

signed main()
{
	string S; cin>>S;
	N=S.size();
	S = ' ' + S;
	counter[0]++;
	int ten = 1;
	for (int i = N; i >= 1; --i) {
		rui[i] += rui[i + 1];
		rui[i] += (S[i] - '0') * ten;
		rui[i] %= P;

		ans += counter[rui[i]];
		counter[rui[i]]++;

		ten *= 10;
		ten %= P;
	}

	cout<<ans<<endl;
}

