#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int sum[200200];

int main(){
    string s;
    cin >> s;
    map<int, int> m;
    int fac = 1;
    m[0]++;
    rep(i, s.length()){
        sum[i+1] = sum[i] + fac*(s[s.length()-i-1] - '0');
        sum[i+1] = sum[i+1] % 2019;
        m[sum[i+1]]++;
        fac = (fac*10) % 2019;
    }
    ll ans = 0;
    for(auto p: m){
        auto a = p.second;
        ans += a*(a-1)/2;
    }
    cout << ans << endl;
    return 0;
}