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

int main (void) {
    char s[200001];
    scanf("%s", s);

    long long ans = 0;
    int s_len = strlen(s);
    long long digits, tmp, num;

    for ( int i=0; i<s_len; i++ ) {
        for ( int j=i+3; j<s_len; j++ ) {
            digits = j - i + 1; /* 桁数 */
            num = 0;
            tmp = 1;
            for ( int k=digits-1; k>=0; k-- ) {
                num += tmp * (s[i+k] - '0');
                tmp *= 10;
            }
            if ( num % 2019 == 0 )
                ans++;
        }
    }

    printf("%lld\n", ans);
    return EXIT_SUCCESS;
}
