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

using ll = long long int;

constexpr int M = 2019;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0, cnt[M]{};
    cnt[0] = 1;
    for(int i=n-1,r=0,d=1;i>=0;i--,d=d*10%M){
        r += (s[i]-'0')*d;
        r %= M;
        ans += cnt[r];
        cnt[r]++;
    }
    cout << ans << endl;
    return 0;
}