#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
template <int MOD> struct intmod
{  // modified from http://drken1215.hatenablog.com/entry/2020/02/09/225000
    long long val;
    constexpr intmod(long long v = 0) noexcept : val(v % MOD)
    {
        if (val < 0)
            val += MOD;
    }
    constexpr int getmod()
    {
        return MOD;
    }
    constexpr intmod operator-() const noexcept
    {
        return val ? MOD - val : 0;
    }
    constexpr intmod operator+(const intmod &r) const noexcept
    {
        return intmod(*this) += r;
    }
    constexpr intmod operator-(const intmod &r) const noexcept
    {
        return intmod(*this) -= r;
    }
    constexpr intmod operator*(const intmod &r) const noexcept
    {
        return intmod(*this) *= r;
    }
    constexpr intmod operator/(const intmod &r) const noexcept
    {
        return intmod(*this) /= r;
    }
    constexpr intmod &operator+=(const intmod &r) noexcept
    {
        val += r.val;
        if (val >= MOD)
            val -= MOD;
        return *this;
    }
    constexpr intmod &operator-=(const intmod &r) noexcept
    {
        val -= r.val;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr intmod &operator*=(const intmod &r) noexcept
    {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr intmod &operator/=(const intmod &r) noexcept
    {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr bool operator==(const intmod &r) const noexcept
    {
        return this->val == r.val;
    }
    constexpr bool operator!=(const intmod &r) const noexcept
    {
        return this->val != r.val;
    }
    friend constexpr ostream &operator<<(ostream &os, const intmod<MOD> &x) noexcept
    {
        return os << x.val;
    }
    friend constexpr intmod<MOD> modpow(const intmod<MOD> &a, long long n) noexcept
    {
        if (n == 0)
            return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1)
            t = t * a;
        return t;
    }
};
const int mod = 2019;
typedef intmod<mod> mint;
// 左から k+1 文字目以降を整数とみなしたときの値 mod 2019
mint dp[2 * pow10(5)];

void solve()
{
    string S;
    cin >> S;
    S += '0';
    int N = S.length();
    dp[N - 1] = mint(S[N - 1] - '0');
    map<int, int> modcnt;
    modcnt[dp[N - 1].val]++;
    RREP0(i, N - 1)
    {
        dp[i] = dp[i + 1] + modpow(mint(10), N - i - 1) * mint(S[i] - '0');
        modcnt[dp[i].val]++;
    }
    LL ans = 0;
    for (auto p : modcnt)
    {
        int n = p.second;
        ans += n * (n - 1) / 2;
    }
    std::cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 5316