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

int main(){
    int N = 200001;
    int mod = 2019;
    char *s = (char*)malloc(sizeof(char)*N);
    if (fgets(s, N, stdin) == NULL){
        return 0;
    }

    int len = (int)strlen(s) - 1;
    long int dp[len][mod];

    for (int l = 0; l < len; l++){
        for (int m = 0; m < mod; m++){
            dp[l][m] = 0;
        }
    }

    for (int l = 0; l < len-1; l++){
        dp[l][*(s+l) - '0'] += 1;
        for (int m = 0; m < mod; m++){
            if (dp[l][m] != 0){
                int num = *(s+l+1) - '0';
                dp[l+1][(10*m+num)%mod] += dp[l][m];
            }
        }
    }

    long int cnt = 0;
    for (int l = 0; l < len; l++){
        if (dp[l][0] != 0){
            cnt += dp[l][0];
        }
    }

    printf("%ld\n", cnt);

    return 0;
}