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

int main() {
    string s;
    cin >> s;
    vector<int> v(2019, 0);
    v[0] = 1;
    int n = s.size();
    int dp = 0;
    for(int i = 0; i < n; ++i) {
        int tmp = s[n-i-1]-'0';
        for(int j = 0; j < i; ++j) {
            tmp *= 10;
            tmp %= 2019;
        }
        tmp += dp;
        tmp %= 2019;
        v[tmp]++;
        dp = tmp;
    }

    /*
    for(int i = 0; i < 2019; ++i) {
        if(v[i] > 0) cout << "i:" << i << "v[i]:" << v[i] << endl;
    }
    */

    long long sum = 0;
    for(int i = 0; i < 2019; ++i) {
        sum += (v[i]*v[i]-1)/2;
    }
    cout << sum << endl;
    return 0;
}