#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);

string s;
int pot[200002];
int post[3000];

int main () {

	cin >> s;
	int n = s.size();
	pot[0] = 1;
	for (int i = 1; i <= n; i++) {
		pot[i] = pot[i-1] * 10;
		pot[i] %= 2019;
	}
	
	ll sol = 0;
	int zbr = 0;
	post[0] = 1;
	for (int i = n-1; i >= 0; i--) {
		zbr += pot[n-1-i]*(s[i]-'0');
		zbr %= 2019;
		//14282668646cout << zbr << " " << post[zbr] << endl;
		sol += post[zbr];
		post[zbr] ++;
	}
	
	cout << sol;

	return 0;
}