#include <stdio.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define MAX(x,y) (x > y ? x : y)
#define MIN(x,y) (x < y ? x : y)
#define INF (long long int)(9223372036854775807)
#define IINF (int)(2147483647)

int a[200000], b[200000], q[200000], n = 0;
lld f = 0;

int main(void) {
  char c;
  while (1) {
    c = getchar();
    if (c == '\n') {
      break;
    }
    a[n] = c - '0';
    q[n] = c - '0';
    n++;
  }

  for (int i = 1; i < n; i++) {
    if (i % 2) {
      for (int j = 0; j < n - i; j++) {
        b[j] = (q[j + i] + a[j] * 10) % 2019;
        if (b[j] == 0) {
          f++;
        }
      }
    } else {
      for (int j = 0; j < n - i; j++) {
        a[j] = (q[j + i] + b[j] * 10) % 2019;
        if (a[j] == 0) {
          f++;
        }
      }
    }
  }

  printf("%lld\n", f);
}