// 桁dpでmod2019を状態として管理する？
// abc159のeみたいな感じ
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 200010;
const long long mod = 2019;
long long C[MAX_N];

int main() {
    string S;
    cin >> S;
    int N = S.size();
    reverse(S.begin(),S.end());
    long long base = 1;
    map<long long, long long> Map;
    for(int i = 1; i <= N; ++i) {
        C[i] = (long long)(S[i-1] - '0')*base%mod;
        base *= 10LL;
        base %= mod;
    }
    for(int i = 1; i <= N; ++i) {
        C[i] += C[i-1];
        C[i] %= mod;
    }
    for(int i = 0; i <= N; ++i) {
        ++Map[C[i]];
    }
    long long res = 0LL;
    for(auto &p : Map) {
        long long num = p.second;
        res += num*(num-1)/2;
    }
    cout << res << endl;
    return 0;
}