#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define int long long
#define fi first
#define se second
#define double long double
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

constexpr int N = 2e5+5;
constexpr int M = 1e9+7;

// #define DEBUG 1  //调试开关
struct IO {
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;

    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }

    inline char gc() {
        if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
        return p1 == p2 ? ' ' : *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    template <class T>
    inline void read(T &x) {
    double tmp = 1;
    bool sign = 0;
    x = 0;
    char ch = gc();
    for (; !isdigit(ch); ch = gc())
        if (ch == '-') sign = 1;
    for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
        for (ch = gc(); isdigit(ch); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
    }
    inline void read(char *s) {
    char ch = gc();
    for (; blank(ch); ch = gc())
        ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
    }
    inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
        ;
    }
    inline void push(const char &c) {
    #if DEBUG  //调试，可显示字符
    putchar(c);
    #else
    if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
    *pp++ = c;
    #endif
    }
    template <class T>
    inline void write(T x) {
    if (x < 0) x = -x, push('-');  // 负数输出
    static T sta[35];
    T top = 0;
    do {
        sta[top++] = x % 10, x /= 10;
    } while (x);
    while (top) push(sta[--top] + '0');
    }
    template <class T>
    inline void write(T x, char lastChar) {
    write(x), push(lastChar);
    }
} io;



namespace Factor {
    template <class T> T qpow(T a, T b, T m) {
        T c = 1 % m;
        while (b) {
            if (b & 1) c = c * a % m;
            a = a * a % m;
            b >>= 1;
        }
        return c;
    }

    template <class T> T inline inv(T x, T m) { return qpow(x, m-2, m); }

    template <int N> struct Mu {
        signed mu[N];
        signed flg[N];
        signed tot;
        signed p[N];
        Mu() {
            mu[1] = 1;
            for (int i = 2; i < N; ++i) {
                if (!flg[i]) p[++tot] = i, mu[i] = -1;
                for (int j = 1; j <= tot && i * p[j] < N; ++j) {
                    flg[i * p[j]] = 1;
                    if (i % p[j] == 0) {
                        mu[i * p[j]] = 0;
                        break;
                    }
                    mu[i * p[j]] = -mu[i];
                }
            }
        }
    };

    template <int N> struct Prime {
        bool prime[N];
        vector<signed> primes;
        Prime() {
            memset(prime, 1, sizeof(prime));
            prime[0] = prime[1] = 0;
            for (int i = 2; i < N; i++) {
                if (!prime[i]) continue;
                primes.push_back(i);
                for (int j = i * i; j < N; j += i)
                    prime[j] = 0;
            }
        }

        // f(n) = \sum_{d|n} g(d)
        // g(n) = \sum_{d|n} mu(d) * f(n/d)
        signed mu(signed x) {
            int cnt = 0;
            for (int p: primes) {
                if (p * p > x) break;
                if (x % p) continue;
                cnt++;
                int now = 0;
                while (x % p == 0) x /= p, now++;
                if (now > 1) return 0;
            }
            if (x != 1) cnt++;
            return cnt % 2 ? -1 : 1;
        }
    };
}

string s;
int mod673;
int m673[673][3];
int iv[N];
int po[N];

signed main() {
    fastio;
    cin >> s;
    m673[0][0] = 1;
    int ans = 0;
    po[0] = 1, iv[0] = 1;
    for (int i = 1; i < N; i++) {
        po[i] = po[i-1] * 10 % 673;
        iv[i] = Factor::inv(po[i], 673ll);
    }
    int sum = 0;
    for (int i = 0; i < s.size(); i++) {
        sum += s[i]-'0';
        mod673 = (mod673 * 10 + s[i]-'0') % 673;
        ans += m673[mod673 * iv[i] % 673][sum%3];
        m673[mod673 * iv[i] % 673][sum%3]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6868