#include <stdio.h>
#include <string.h>
#define MIN(x, y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))

char s[200001];
int t[2020] = {1};
int main()
{
  scanf("%s", s);
  long long sum = 0;
  int n = strlen(s);
  int rem = 0;
  int y = 1;
  for (int i = n - 1; i >= 0; i--) {
    rem = (rem + (s[i] - '0') * y) % 2019;
    t[rem]++;
    y = y * 10 % 2019;
  }
  for (int i = 0; i < 2019; i++) {
    sum += (long long) t[i] * (t[i] - 1);
  }
  printf("%lld", sum / 2);
  return 0;
}