//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

vecl cnt(2019,0);

int main() {
    string S;
    cin >> S;
    ll ans = 0;
    int ex = 1;
    int num = 0;
    for(int i = S.size()-1; i >= 0; i--) {
            num = (num + ex * (S[i] - '0')) % 2019;
            ex = (ex * 10) % 2019;

            cnt[num]++;
    }
    for(auto x:cnt) ans += x*(x-1)/2;
    ans += cnt[0];
    cout << ans << endl;
}