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

int main()
{
    string s;
    cin >> s;
    int64_t cnt = 0;
    for(int i = 0; i < s.size() - 3; i++){
        
        int64_t tmp;
        int64_t rest = 0;

        for(int j = 0; j < s.size() - i - 3; j++){
            if(j == 0) tmp = stoi(s.substr(i, 4));
            else tmp = s[j + i + 3] - '0';

            // cout << tmp << endl;

            rest = (rest * 10 + tmp) % 2019;

            // cout << "rest" << j << ": " << rest << endl;

            if(rest == 0) cnt++;
        }
    }

    cout << cnt << endl;
}