#include <bits/stdc++.h>

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 200005;
const int MOD = 2019;

int ten[N], t[N], cnt[MOD];

int main() {

    FAST;

    string a;
    cin >> a;
    ten[0] = 1;
    int n = a.length();
    a = ' ' + a;
    for (int i = 1; i <= n; i ++) {
        ten[i] = (ten[i - 1] * 10) % MOD;
    }
    t[n] = 0;
    for (int i = n - 1; i >= 0; i --) {
        t[i] = (t[i + 1] + (ten[n - i - 1]) * (int(a[i + 1]) - '0')) % MOD;
    }
    for (int i = 0; i <= n; i ++) {
        cnt[t[i]] ++;
    }
    int ans = 0;
    for (int i = 0; i < MOD; i ++) {
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << ans << '\n';
    return 0;
}
