#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    string S;
    cin >> S;
    int l = S.size();

    reverse(ALL(S));
    map<int, int> mp;
    mp[0]++;
    vi dp(l+1, 0);
    int t = 1;
    rep(i, l) {
        dp[i+1] = (dp[i]+int(S[i]-'0')*t)%2019;
        mp[dp[i+1]]++;
        t = (t*10)%2019;
    }


    int res = 0;
    for(auto &p : mp) {
        //cout << p.fi << " " << p.se  << endl;
        res += p.se*(p.se-1)/2;
    }

    cout << res << endl;

    return 0;
}