#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 1e5 + 5;
 
int pow(int a, int b, int m)
{
    int ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%m;
        b/=2;
        a=(a*a)%m;
    }
    return ans;
}
 
int n;
int m[2050];
string s;
 
int32_t main()
{
    IOS;
   //  freopen("inputf.in", "r", stdin);
    cin >> s;
    n = s.size();
    int cur = 0, ans = 0, pref = 0;
    for(int i = 0; i < n; i++)
    {
        int rem = 0, pref = 0;
        memset(m, 0, sizeof(m));
        for(int j = i; j < n; j++)
        {
            rem = (rem * 10 + s[j] - '0') % 2019;
            if(rem == 0)
                ans++;
        }
       
    }
    cout << ans;
    return 0;
}