#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    cin >> s;
    vector<vector<int>> dp(s.size(), vector<int>(2019, 0));
    int now;
    dp[0][s[0]-'0']++;
    REP(i, s.size()-1){
        now = s[i] - '0';
        dp[i][now]++;
        rep(j, 2019){
            dp[i][(j*10+now) % 2019] += dp[i-1][j];
        }
    }
    int ans = 0;
    rep(i, s.size())ans += dp[i][0];
    cout << ans << endl;
}
