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

int main(void){
    char S[200000];
    scanf("%s",S);
    int num = 0, N = strlen(S), kind = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+3; j < N; j++){
            num = 0;
            for(int k = i; k <= j; k++){
                num += ((int)S[k] - 48);
                num = num*10;
            }
            if(num % 2019 == 0){
                kind++;
            }
        }
    }
    printf("%d\n",kind);
    return 0;
}