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

int main(){
    string S;
    cin >>S;
    int n = S.size();
    int count = 0;
    for(int i=4;i<=n;i++){
        for(int j=0;j<n-i+1;j++){
            string m = S.substr(j,i);
            istringstream ss;
            ss = istringstream(m);
          	int M;
          	ss >> M;
            if(M%2019 == 0) count ++;
        }
    }
    cout <<count<<endl;
}