#include <stdio.h>

#define NUM (2019)
#define SIZE (200000)

int count[NUM];

main()
{
        int n;
        int c;
        int buf[SIZE];
        int md[SIZE + 1];
        int tmp;
        int tens;
        int i, j;
        int res;

        n = 0;
        while((c = getchar()) != EOF) {
                buf[n] = c - '0';
                ++n;
        }

        tmp = 0;
        tens = 1;
        for(i = n - 1; i >= 0; --i) {
                tmp = (buf[i] * tens + tmp) % NUM;
                md[i] = tmp;
                tens = (tens * 10) % NUM;
        }
        md[n] = 0;

        for(i = 0; i <= n; ++i) {
                count[md[i]] = count[md[i]] + 1;
        }
        res = 0;
#if 0
        for(i = 0; i < NUM; ++i) {
                if(count[i] > 0) {
                        res += count[i] * (count[i] - 1) / 2;
                }
        }
#endif
        printf("%d", res);
}
