#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    string str;
    cin >> str;
    reverse(str.begin(), str.end());
    int n = str.size();
    vector<int> a(n), s(n+1);
    int pow_10_mod = 1;
    s[0] = 0;
    rep(i, n) {
        a[i] = ((str[i]-'0')*pow_10_mod)%2019;
        s[i+1] = (s[i] + a[i])%2019;
        pow_10_mod = (pow_10_mod*10)%2019;
    }
    vector<int> cnt(2019);
    int ans = 0;
    rep(i,n+1) {
        ans += cnt[s[i]];
        cnt[s[i]]++;
    }
    cout << ans << endl;
}