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

#define MODSIZE 2019

int cnt[2026];

int main(){
  char s[200005];
  int n,i,j;
  char t;
  int x = 1;
  int tot = 0;
  long long ans = 0;

  scanf("%s", s);
  n = strlen(s);

  for(i = 0;i <= 2020;i++) cnt[i] = 0;

  for(i = 0,j = n - 1;i < n/2;i++,j--){
    t = s[i]; s[i] = s[j]; s[j] = t;
  }

  for(i = 0;i < n;i++){
    cnt[tot]++;
    tot += (s[i] - '0')*x;
    tot %= MODSIZE;
    ans += cnt[tot];
    x = x*10 % MODSIZE;
  }

  printf("%lld\n", ans);

  return 0;
}
