#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>

using lint = int64_t;

using std::cin;  using std::cout; using std::endl;
using std::sort; using std::reverse;
using std::max;  using std::min;
using std::string;
using std::vector;
using std::pair;
using std::map;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;
using std::greater;

#define low std::lower_bound
#define upp std::upper_bound
#define rep(i, n) for (lint i = 0; i < (n); ++i)
#define rep1(i, n) for (lint i = 1; i < (n); ++i)
#define Rep(i, n) for (lint i = (n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T>
#define prique2(T) priority_queue<T, vector<T>, greater<T>>

struct edge { lint to, cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1'000'000'007LL;
constexpr lint inf = 7LL * mod * mod;
const double Pi = std::acos(-1.0);

template<class T> inline bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

constexpr lint gcd(lint a, lint b) { return b == 0 ? a : gcd(b, a % b); }

constexpr lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

constexpr bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

constexpr bool kousa(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy) {
	double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
	double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
	double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
	double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);

	return tc * td < -1e-12 && ta * tb < -1e-12;
}

double dis(D a, D b) { return std::hypot(a.first - b.first, a.second - b.second); }

lint fact[3000000];
void f_init(lint n) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
}

lint nck[1010][1010];
void comb(lint n) {
	for(lint i = 0; i < n - 1; ++i) {
		for(lint j = 0; j < i + 1; ++j) {
			if (i == 0 || j == 0) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

lint modpow(lint x, lint n, lint m) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) {
			res *= x;
			if (m <= res) res %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint res = fact[n] * modpow(fact[n - r], mod - 2, mod) % mod * modpow(fact[r], mod - 2, mod) % mod;
	if (res < 0) return res + mod;
	return res;
}

lint xor128() {
	static lint x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	lint t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}

class unionfind {
private:
	lint par[2 * 100010], rank[2 * 100010], size[2 * 100010];
public:
	void init(lint n) noexcept {
		for (lint i = 0; i < n; ++i) {
			par[i] = i;
			rank[i] = 0;
			size[i] = 1;
		}
	}

	lint root(lint x) noexcept {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	bool same(lint x, lint y) noexcept { return root(x) == root(y); }

	void unite(lint x, lint y) noexcept {
		x = root(x); y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
			size[y] += size[x];
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y]) ++rank[x];
			size[x] += size[y];
		}
	}
};

class BIT {
private:
	lint n, bit[500010];
public:
	void init(lint n_) noexcept { n = n_; }

	void add(lint a, lint w) noexcept {
		for (lint x = a; x <= n; x += (x & -x)) bit[x] += w;
	}
	lint sum(lint a) const noexcept {
		lint res = 0;
		for (lint x = a; x > 0; x -= (x & -x)) res += bit[x];
		return res;
	}
};

lint n, cnt, ans;
string s;
map<lint, lint>mp;
int main() {
	cin >> s;
	n = s.size();
	reverse(all(s));
	mp[0] = 1;
	rep(i, n) {
		cnt += (s[i] - '0') * modpow(10, i, 2019);
		cnt %= 2019;
		++mp[cnt];
	}
	for (auto p : mp) {
		ans += p.second * (p.second - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3740