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


void solve(){
  
}

int main() {
	// your code goes here
    
    string s;
    cin >> s;
    
    int n = s.length();
    int ans = 0;
    
    for(int i=0;i<=n-4;i++){
        
        string temp;
        temp += s[i];
        for(int j=i+1;j<n;j++){
            
            temp += s[j];
            stringstream x(temp);
            
            ll num;
            x >> num;
            
            if(num % 2019 == 0)
                ans++;
        }
    }
    
    cout << ans;
}
