#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    string s; cin >> s; // |S| <= 2*1e5
    int ans = 0;
    for (int l = 0; l < s.length(); ++l)
    {
        int value = 0;
        for (int i = l; i < s.length(); ++i)
        {
            value *= 10;
            value += static_cast<int>(s[i] - '0');
            value %= 2019;
            if (value == 0)
            {
                ++ans;
                l = i - 1;
                break;
            }
        }
    }
    cout << ans << endl;
}
