#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define DIGITS_MAX 200000
#define BUF_SIZE (DIGITS_MAX+50)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

#define DIVISOR 2019

int main(void) {
    static char nstr[BUF_SIZE];
    get_str(nstr, BUF_SIZE);
    int len = strlen(nstr) - 1;
    static int map[DIGITS_MAX+2]; // 1-indexed

    static int power10[DIGITS_MAX+1];
    power10[0] = 1;
    int i;
    for(i = 1; i <= len; i++) {
        power10[i] = (power10[i-1] * 10)%DIVISOR;
    }

    for(i = len; i >= 1; i--) {
        int cur = len-i+1;
        int cur_digit = nstr[i-1] - '0';
        map[i] = (map[i+1] + power10[cur-1]*cur_digit)%DIVISOR;
    }

    static int cnt_map[DIVISOR];
    cnt_map[0]++;
    uint64_t res = 0;
    for(i = len; i >= 1; i--) {
        int mod = map[i];
#ifdef DEBUG
        printf("digit #%d: %d\n", len-i+1, mod);
#endif
        res += cnt_map[mod];
        cnt_map[mod]++;
    }
    printf("%llu\n", res);
    return 0;
}