// https://atcoder.jp/contests/abc164/tasks/abc164_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

unordered_set<string> st;
bool judge(string s) {
    int cnt = 0;
    string str = s;
    reverse(ALL(str));

    REP(i, (str.length() + 1) / 4) {
        string t = str.substr(i, i + 4);
        reverse(ALL(t));
        if (st.count(t) > 0) {
            cnt++;
        }
    }
    return (cnt > 0);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    int n = 0;
    while (n <= 100000000) {
        n += 2019;
        string s = to_string(n);
        if (s.find('0') == string::npos) {
            st.insert(s);
        }
    }

    int len = S.length();
    int ans = 0;
    REP(i, len) {
        for (int j = 4; i + j <= len; j++) {
            string y = S.substr(i, j);
            if (judge(y)) {
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}
