#include<stdio.h>
#include<string.h>
#include<math.h>
#define N_MAX 200001
#define ll long long
#define MOD 2019



int main(){
  int g=1,len;
  ll ans=0;
  char a[N_MAX];
  scanf("%s",a);
  len=strlen(a);
  int T[len+1];
  T[len]=0;
  int counter[MOD+1]={};
  counter[0]=1;
  for(int k=len-1;k>=0;k--){
    T[k]=(T[k+1]+g*(a[k]-'0'))%MOD;
    counter[T[k]]++;
          g*10;
          g%2019;
  };
  for(int b=0;b<=MOD;b++){
    ans+=counter[b]*(counter[b]-1)/2;
    ans%=MOD;
  };
  printf("%d",ans);
};
