#include <bits/stdc++.h>
using namespace std;

int main() {
    int64_t S;
    cin >> S;

    int64_t T = S;
    int count = 0;
    while (T > 0) {
        T = T / 10;
        count++;
    }

    T = S;
    int64_t U = T;
    int64_t X = 1;
    for (int i = 0; i < count - 1; i++) {
        X = X*10;
    }

    int ans;

    for (int i = 0; i < count; i++) {
        if (T == 0) {
            break;
        }
        for (int j = i; j < count; j++) {
            if (U == 0) {
                break;
            }
            if (U % 2019 == 0) {
            ans++;
            }
            U = U / 10;
        }
        T = T % X;
        U = T;
        X = X / 10;
    }
    
    cout << ans << endl;
}