#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;

    int n = s.size();
    vector<int> d(n);
    int ten = 1;
    for(int i=n-1;i>=0;i--){
        int a = (s[i] - '0') * ten % 2019;
        d[i] = (d[i+1] + a) % 2019;
        ten *= 10;
        ten %= 2019;
    }

    vector<int> cnt(2019);
    int ans = 0;
    cnt[0]++;
    for(int i=0;i<n;i++){
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    
    cout << ans << endl;
}