#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

int a[10];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < 10; i++)
        a[i] = 1;
    vector<ll> vc(s.length()), sum(s.length());
    sum[0] = 0;
    for (int i = 0; i < s.length() - 4; i++)
    {
        bool flag = false;
        if (a[s[i] - '0'])
        {
            for (int j = i + 4; j < s.length(); j++)
            {
                string d = s.substr(i, j - i + 1);
                int num = 0;
                for (int k = 0; k < d.length(); k++)
                {
                    num *= 10;
                    num += d[k] - '0';
                }
                //    cout << num << endl;
                if (num % 2019 == 0)
                {
                    flag = true;
                    cnt++;
                }
            }
        }
        if (flag)
        {
            s[s[i] - '0'] = 0;
        }
    }
    cout << cnt << endl;
}