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

long long N;
string S;

long long solve()
{
    vector<long long> val(2019, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i)
    {
        cur = (cur + (S[N - i - 1] - '0') * tenfactor) % 2019;
        tenfactor = (tenfactor * 10) % 2019;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < 2019; ++p)
        res += val[p] * (val[p] - 1) / 2;
    return res;
}

int main()
{
    cin >> S;
    N = S.size();
    cout << solve() << endl;
}