#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	
	string S; cin >> S;
  	int P = 2019;
  	int N = S.size();
	if (P == 2) {
		int res = 0;
		REP(i, N) {
			int a = S[i] - '0';
			if (a % 2 == 0)res += (i + 1);
		}
		cout << res << endl;
		return 0;
	}
	if (P == 5) {
		int res = 0;
		REP(i, N) {
			int a = S[i] - '0';
			if (a % 5 == 0)res += (i + 1);
		}
		cout << res << endl;
		return 0;
	}
	int cnt[1000000] = { 0 };

	int ans = 0;
	VI sum(N + 1, 0);
	int po = 1;


	cnt[0]++;

	for (int i = N - 1; i >= 0; i--) {
		int now = (S[i] - '0')*po%P;

		sum[i] = (sum[i + 1] + now) % P;

		po *= 10;
		po %= P;

		ans += cnt[sum[i]];
		cnt[sum[i]]++;

		
	}



	cout << ans << endl;

	return 0;
}

