#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;
#define mod 2019

vector<ll> cnt(2019);

int main() {
    string S; cin >> S;
    int N = S.length();
    
    cnt[0] = 1;
    ll p = 1;
    ll now = 0;
    for (int i = N - 1; i >= 0; i--) {
        now = (now + (S[i] - '0') * p) % mod;
        cnt[now]++;
        p = (p * 10) % mod;
    }
    
    ll ans = 0;
    for (int i = 0; i < 2019; i++) {
        ll n = cnt[i];
        ans += n * (n - 1) / 2;
    }

    cout << ans << endl;
    return 0;
}