#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;


int main(){
    string S;
    cin >> S;
    int size = S.size();
    ll cnt = 0;
    string substr;
    rep(i, size-4){
        for(int j = i+4; j <= size; j++){
            substr = "";
            if (abs(i - j ) < 3 || abs(i - j) > size) continue; 
            for (int k= i; k < j; k++){
                substr += S.at(k);
            }
            ll sl = stoll(substr);
            if (sl%2019 == 0){
                cnt ++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}