/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int power(int x, int y, int p)
{
    int res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

int main(){
    int p = 2019;
    string s;
    getline(cin, s);
    int n = s.length();
    vector <int> rem(n+1);
    rem[n] = 0;
    for (int i = n-1; i >= 0; i--){
        rem[i] = (((s[i]-'0')%p)*power(10, n-1-i, 2019) + rem[i+1])%p;
    }
    map <int, int> m;
    set <int> q;
    for (int i = 0; i < n; i++){
        m[rem[i]]++;
        //cout << m[rem[i]] << endl;
        q.insert(rem[i]);
    }
    ll ans = 0;
    for (auto i = q.begin(); i != q.end(); i++){
        if (*i == 0){
            ans += (m[*i]*(m[*i]+1))/2;
        }
        ans += (m[*i]*(m[*i]-1))/2;
    }
    cout << ans;
    return 0;
}


