#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    reverse(all(s));
    int n = s.size();
    vector<int> a(n);
    rep(i, n) a[i] = s[i] - '0';
    vector<int> b(n + 1);
    int num = 1;
    rep(i, n)
    {
        b[i + 1] = (num * a[i] + b[i]) % 2019;
        num *= 10;
    }
    vector<int> cnt(2019);
    rep(i, n + 1) cnt[b[i]]++;
    int ans = 0;
    //rep(i, n + 1) cout << b[i] << endl;
    rep(i, 2019) ans += (cnt[i] * (cnt[i] - 1)) / 2;
    cout << ans << endl;
}
