#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

long modpow(long a, long n, long mod){
  long size;
  for (long i = 1; ; i++) {
    if (pow(2,i) > n) {
      size = i;
      break;
    }
  }
  long bit[size];
  bit[0] = n;
  for (long i = 1; i < size; i++) {
    bit[i] = bit[i-1]/2;
    bit[i-1] %= 2;
  }
  long powa[size];
  powa[0] = a;
  for (long i = 1; i < size; i++) {
    powa[i] = powa[i-1]*powa[i-1];
    powa[i] %= mod;
  }
  long answer = 1;
  for (long i = 0; i < size; i++) {
    if (bit[i] == 1) {
      answer *= bit[i]*powa[i];
      answer %= mod;
    }
  }
  return answer;
}

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  char s[200001];
  scanf("%s", s);
  long length = strlen(s);
  long modlist[length];
  modlist[length-1] = s[length-1]-'0';
  for (long i = length-2; i >= 0; i--) {
    modlist[i] = modlist[i+1]+(s[i]-'0')*modpow(10,length-1-i,2019);
    modlist[i] %= 2019;
  }
  qsort(modlist, length, sizeof(long), cmpnum);
  long answer = 0;
  long count = 1;
  for (long i = 1; i < length; i++) {
    if (modlist[i] == modlist[i-1]) {
      count++;
    } else {
      if (modlist[i-1] == 0) {
        count++;
      }
      answer += count*(count-1)/2;
      count = 1;
    }
  }
  if (modlist[length-1] == 0) {
    count++;
  }
  answer += count*(count-1)/2;
  printf("%ld\n", answer);

  return 0;
}