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

int main(int argc, char const *argv[])
{
    int i, j, k, len, count;
    char s[200001], tmp[200001];

    scanf("%s", s);
    len = strlen(s);
    count = 0;
    for(i = len-1; i >= 0; i--) {
        for(j = len-1; j > i+3; j--) {
            for(k = 0; k < j-i+1; k++) {
                tmp[k] = s[i+k];
            }
            tmp[k] = '\0';
            if(!(atoi(tmp) % 2019)) count++;
        }
    }
    printf("%d\n", count);
    return 0;
}
