#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;
    int rem = 0;
    int p = 1;
    for (int i = n - 1; i >= 0; i--) {
        rem = (rem + (p * (s[i] - '0'))) % mod;
        cnt[rem]++;
        p = (10 * p) % mod;
    }
    ll ans = 0;
    for (auto m : cnt) {
        ans += m * (m - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}