#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, j, a;
	ll ans = 0;
	string s;
	cin >> s;
	vector<vector<ll>> dp(s.size() + 1, vector<ll>(2019, 0));
	rep(i, s.size()) {
		a = s[i] - '0';
		rep(j, 2019) {
			if (dp[i][j]) {
				dp[i + 1][(j * 10 + a) % 2019] += dp[i][j];
			}
		}
		dp[i + 1][a]++;
	}
	rep(i, dp.size()) {
		ans += dp[i][0];
	}
	cout << ans << "\n";
	return 0;
}