#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 tmp, num;

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

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