#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int mod(string num, int a)
{
    // Initialize result
    int res = 0;

    // One by one process all digits of 'num'
    for (int i = 0; i < num.length(); i++)
         res = (res*10 + (int)num[i] - '0') %a;

    return res;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    int n = S.length();
    string N;
    map<int, int> m;
    int ans = 0;
    for(int i = n-1; i >= 0; i--) {
        string A;
        A += S[i];
        N.insert(0, A);
        int md = mod(N, 2019);
        if (md == 0 || m[md]) ans++;
        m[md]++;
    }
    cout << ans;
    return 0;
}
