#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    string S;
    cin >> S;
    int N = S.size();

    int ans = 0;
    map<int, int> mp{};
    int num = 0, kai = 1;
    mp[0]++;
    int P = 2019;
    for(int i=N-1;i>=0;i--){
        num += (S[i]-'0') * kai;
        num %= P;
        mp[num]++;
        kai = (kai * 10) % P;
    }
    for(auto p : mp){
        int n = p.second;
        ans += n * (n-1) / 2;
    }


    cout << ans << endl;
}