#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>

// #include <string>
using namespace std;

using ll = long long; // int64
const int mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int cnt[2020] = {0};
    cnt[0] = 1; // 2019で割り切れる数ならば それ自体が答えになる.
    int d = 1;
    int ans = 0;
    int acc = 0;
    int m = 0;

    for (int i = n-1; i >= 0; i--) {
        m = s[i] - '0';
        acc = (d*m + acc) % 2019;
        ans += cnt[acc];
        cnt[acc]++;
        d = (d * 10) % 2019;
    }

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