#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<string> g;


int main() {
    
    
    string s;
    cin >> s;
    
    vector<vector<ll>> dp(s.size(), vector<ll>(2019));
    
    ll ret = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        ll num = s[i] - '0';
        if (i == 0)
        {
            dp[0][num] = 1;
            continue;
        }
        dp[i][num]++;
        for (int j = 0; j < 2019; ++j)
        {
            dp[i][(j * 10 + num) % 2019] += dp[i - 1][j];
        }
        ret += dp[i][0];
    }

    cout << ret << endl;
    
    return 0;
}