//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

int main (){
    string s;
    cin >> s;
    int ans = 0;
    int n = s.size();
    REP(i,n-1){
        int num = s[i] - '0';
        // cout << num << endl;
        for(int j=i+1; j<n;j++){
            int d = s[j] - '0';
            num = num*10 + d;
            // cout << num << endl;
            if (num % 2019 ==0){
                ans++;
                num = 0;
            }
        }
    }
    cout << ans;
}