#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int D = 2019;
int dp[2019];

void solve() {
    string S;
    cin >> S;
    int L = S.size();
    reverse(S.begin(), S.end());
    dp[0] = 1;
    int m = 0;
    int ten = 1;
    for (int i = 0; i < L; ++i) {
        m = m + (S[i] - '0') * ten;
        m %= D;
        dp[m]++;
        ten *= 10;
        ten %= D;
    }
    int ans = 0;
    for (int i = 0; i < 2019; ++i) {
        int x = dp[i];
        ans += x * (x - 1) / 2;
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}
