

#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <stdio.h>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) > 0 ? (a) : (-1 * (a)))
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define rep2(i, s, e) for ((i) = (s); (i) < (e); (i)++)
#define LIM (2019)

void step(int n, int g, int s);

char s[200010];
int a[200010];
//int m[200010];

int main(void)
{
    int i, j, l, cnt = 0, tmp;
    scanf("%s", &s);
    rep(i, 200010)
    {
        if (s[i] == '\0')
            break;
        a[i] = s[i] - '0';
    }
    l = i;
    /*m[0] = 1;
    rep(i, l)
        m[i + 1] = (m[i] * 10) % LIM;
    */
    rep(i, l)
    {
        tmp = a[i];
        if (tmp == 0)
            cnt++;
        rep2(j, i + 1, l)
        {
            tmp = (tmp * 10 + a[j]) % LIM;
            if (tmp == 0)
                cnt++;
        }
    }
    printf("%d", cnt);
    return 0;
}
