#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll modpow(ll a,ll b){
    if(b==0)return 1;
    else if(b%2==0){
        ll d=modpow(a,b/2);
        return d*d%2019;
    }
    else return modpow(a,b-1)*a%2019;
}
int main(){
    string s=stin();
    ll n=(int)s.size();
    vecll a(n);
    rep(i,n)a[i]=s[i]-'0';
    vecll dp(n+1);
    dp[n]=0;
    dp[n-1]=a[n-1];
    rep3(i,n-2,0)dp[i]=(dp[i+1]+a[i]*modpow(10,n-i-1))%2019;
    vec num(2019,0);
    rep(i,n+1)num[dp[i]]++;
    int ans=0;
    rep(i,2019) ans+=num[i]*(num[i]-1)/2;
    cout<<ans<<endl;
}