#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define all(x) (x).begin(), (x).end()

/**ABC 164*/
int main(){
    string s; cin>>s;
    int cnt=0;
    string aux;
    int j = 4;
    for(int i=0; i<s.size()-4;){
		aux = s.substr(i, j);
		ll x = stoll(aux);
		if((aux[i]-'0') <= (aux[j-1]-'0') && x%2019 == 0 && j<=s.size()){
			cnt++;
		}
		if((aux[i]-'0') > (aux[j-1]-'0') || aux.size()>=18 || j==s.size()){
			i++;
			j = i+3;
			
		}
		j++;
		aux.clear();
    }
    cout<<cnt<<endl;
}
