#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>;

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