import std.string;
import std.stdio;

void main() {
	enum M = 2019;
	string s = readln.chomp;

	long count;
	while (s.length >= 4) {
		int mods = 0;

		foreach (e;s) {
			mods = mods * 10 + cast(int)e - '0';
			if (mods >= M) {
				mods %= M;
			}
			if (mods == 0) {
				++count;
			}
		}

		s = s[1..$];
	}

	writeln(count);
}
