#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
    string S;
    ll ans=0;
    cin >> S;

    for (int i = 4; i <= S.size(); i++) {
        ll sum=0;
        for (int j = 0; j < S.size()-4; j++) {           
            string str;
            str = S.substr(j,i);
            if(str.size()!=i) continue;
            ll a = stoll(str);
            if(a%2019==0){
                sum++;
                cout << a << endl;
            }
        }
        ans+=sum;
        //if(sum==0) break;
    }

    cout << ans << endl;
}