#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    string s;
    cin >> s;
    int N = s.size();
    reverse(all(s));
    map<ll, ll> ma;
    ll MOD = 2019;
    vector<ll> sum(N + 1, 0);
    string str = "";
    rep(i, N) {
        str = s[i] + str;
        sum[i + 1] = stol(str);
    }

    rep(i, N + 1) {
        sum[i] %= MOD;
        ma[sum[i]]++;
    }

    ll res = 0;
    for (auto p : ma) {
        res += p.second * (p.second - 1) / 2;
    }

    cout << res << endl;
}