//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);
LL dp[2020];

int main() {
	string s;
	cin >> s;
	LL tmp = 1;
	int l1 = s.length();
	vector<int> v;
	for (int i = l1 - 1; i >= 0; i--) {
		LL x = (tmp * (s[i] - '0')) % 2019;
		v.pb(x);
		tmp *= 10;
		tmp %= 2019;
	}
	dp[0] = 1;
	LL pre = 0, ans = 0;
	while (!v.empty()) {
		pre += v.back();
		pre %= 2019;
		v.pop_back();
		ans += dp[pre];
		dp[pre]++;
	}
	printf("%lld\n", ans);
}