#include <stdio.h>
#include<stdlib.h>
#include <string.h>
#include<stdbool.h>
typedef struct Values {

	int i;

	//i<=j
	int j;

}values;

const int digitNum = 200001;

char str[digitNum];

int theMultiple = 2019;


int chosenValue(values*);

bool multipleIs(int*, int*);


int main(void) {

	fgets(str,sizeof(str),stdin);

	sscanf(str,"%s", str);

	values tupple = { 0, 0 };

	int length = strlen(str);

	int multipleCount = 0;

	int temp = 0;

	for (int s = 0; s < length; s++) {

		tupple.i = s;

		for (int t = s; t < length; t++) {

			///2019の倍数となる前提
			//4桁
			if (t - s + 1 < 4)continue;

			tupple.j = t;

			temp = chosenValue(&tupple);

			if (multipleIs(&temp, &theMultiple) == true)multipleCount++;

		}

	}

	printf("%d\n", multipleCount);

	return 0;
}

int chosenValue(values* tupple) {

	char tempDigits[digitNum];

	int count = 0;

	for (int k = tupple->i; k <= tupple->j; k++) {

		tempDigits[count] = str[k];

		count++;

	}

	int ans = 0;

	sscanf(tempDigits, "%d", &ans);

	return ans;

}

bool multipleIs(int* value, int* multiple) {

	return (*value % *multiple) == 0 ? true : false;

}