#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define max 200001
int main(){
 char s[max];long long i,j;
 scanf("%s",s);
 long long len=strlen(s);
  
  long long a[len],x,mod[len+1],y,b=1,cnt[2019]={0};
 mod[len]=0;cnt[0]++;
 for(x=len-1;x>=0;x--){
  a[x]=s[x]-'0';
  mod[x]=(a[x]*b)%2019;
  mod[x]=(mod[x]+mod[x+1])%2019;
  b=(b*10)%2019;
  printf("%2lld %lld \n",x+1,mod[x]);
  cnt[mod[x]]++; 
 }
 mod[len]=0;cnt[0]++;
 long long ans=0;
 for(x=0;x<2019;x++)
  ans+=(cnt[x]-1)*cnt[x]/2;
 printf("%lld\n",ans);

return 0;} 