# include <iostream>
# include <string>
# include <sstream>
typedef long long ll;
using namespace std;

int main () {
    string s;
    cin >> s;
    ll ans(0);
    ll dp[2019];
    memset(dp, 0, sizeof(dp));
    dp[s[0] - '0'] = 1;
    for (int i = 1; i < s.size(); i++) {
        int d = s[i] - '0';
        ll tdp[2019];
        memset(tdp, 0, sizeof(tdp));
        tdp[d] = 1;
        for (int j = 0; j < 2019; j++) {
            if (dp[j] > 0) {
                ll rem = (10 * j + d) % 2019;
                if (rem == 0) ans += dp[j];
                tdp[rem] += dp[j];
            }
        }
        for (int i = 0; i < 2019; i++) {
            dp[i] = tdp[i];
        }
    }
    cout << ans << "\n";

    return 0;
}