#include <stdio.h>

int power(int n){
    int x = 1;
    for (int i = 0; i < n;i++){
        x = x * 10;
    }
    return x;
}

int main(){
    char S[200000];
    scanf("%s", S);

    int len = 0;
    while(S[len]){
        len++;
    }
    int count = 0;
    for (int i = 0; i < len;i++){
        for (int j = i+4; j < len;j++){
            int tmp = 0;
            for (int k = i; k <= j;k++){
                tmp =tmp+ (S[k]-'0') * power(j-k);
            }
            if(tmp%2019==0){
                count++;
            }
        }
    }
    printf("%d", count);
    return 0;
}