#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    string s;
    cin >> s;
    ll l = s.length();
    ll *dp = new ll[l+1];
    dp[l] = 0;
    ll p = 1;
    for (int i = l-1; i >= 0; i--) {
        dp[i] = dp[i+1] + (s[i]-'0')*p;
        dp[i] %= 2019;
        p*=10;
        p%=2019;
    }

    map<ll, ll> m;
    for (int i = 0; i <= l; i++)
        m[dp[i]]++;

    ll ans = 0;
    for (auto ite = m.begin(); ite != m.end(); ite++)
        ans += (*ite).second * ((*ite).second-1) / 2;

    cout << ans << endl;

    return 0;
}