#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

int dp[200000];

class Solution {
private:
public:
    int solve(string& s) {
        int n = s.size(), ret = 0;
        memset(dp, 0, sizeof(dp));
        for(int i = 0; i < n; ++i) {
            int cur = s[i] - '0';
            dp[i] = cur;
            for(int j = i - 1; j >= 0; --j) {
                dp[j] = (dp[j] * 10 + cur) % 2019;
                if(dp[j] == 0) ++ret;
            }
        }
        return ret;
    }
};

int main() {
    string s;
    cin >> s;
    Solution sol;
    auto ret = sol.solve(s);
    cout << ret << endl;
    
}