#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n,T,cas=0;
    string s;
    cin>>s;
    map<int, int> mp;
    mp[0]=1;
    int r=0, pow10=1;
    ll res=0;
    for(int i=s.size()-1;~i;--i) {
        r = (r + (s[i]-'0')*pow10)%2019;
        res += mp[r];
        mp[r]++;
        pow10 = (pow10*10)%2019;
    }
    cout<<res<<endl;
    return 0;
}