#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int p = 2019;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    vector<int> d(n+1);
    int ten = 1;
    for(int i = n-1; i >= 0; i--){
        int a = (s[i] - '0') * ten % p;
        d[i] = (d[i+1]+a) % p;
        ten *= 10;
        ten %= p;
    }
    vector<int> cnt(p);
    ll ans = 0;
    for(int i = n; i >= 0; i--){
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;
    return 0;
}
