#include <iostream>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <cstdio>
#include <math.h>
#include <map>
#include <algorithm>
#include <deque>
#include <stack>
#include<set>
//#include <bits/stdc++.h>
#define lson l,mid,rt<<1

#define rson mid+1,r,rt<<1|1

//const int N=1e5+100;
using namespace std;

typedef long long ll;
int mod=2019;
int vis[2050];
int main()
{
    vis[0]++;
    string s;cin>>s;
    int base=1;
    ll sum=0;
    ll ans=0;
    for(int i=s.size()-1;i>=0;i--){
        sum=(sum+(s[i]-'0')*base)%mod;
        ans+=vis[sum];
        vis[sum]++;
        base=base*10%mod;
    }
    cout<<ans<<endl;
    return 0;
}
