#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
const int N=2019;

int32_t main(){
    IOS;
    string s;
    cin>>s;
    int a[s.size()];
    int x=0;
    int cur=1;
    int cnt[2019]={0};
   	cnt[0]=1;
    for(int i=s.size()-1;i>=0;i--){
    	x=(x+cur*(s[i]-'0'))%N;
    	cur=(cur*10)%N;
    	cnt[x]++;
    }
    int ans=0;
    for(int i=0;i<2019;i++){
    	ans+=(cnt[i]*(cnt[i]-1)/2);
    }
    cout<<ans<<endl;
}
