#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin >> str;
    int a[200001];

    int length = str.length();

    int count = 0;

    for (int i = 0; i < length - 2; i++)
    {
        int add = (int)(str[i] - '0') + (int)(str[i + 1] - '0') + (int)(str[i + 2] - '0');
        

        for (int j = i + 3; j < length; j++)
        {
            //cout << "(" << i << "," << j << ") " << str.substr(i, j - i + 1) << endl;

            add += (int)(str[j] - '0');
            //cout << "(" << i << "," << j << ") end " << endl;

            unsigned long int num = 0;
            int fin = i;

            if(add % 3 == 0){
                for (int k = fin; k <= j; k++)
                {
                    num = num * 10 + (int)(str[k] - '0');
                }
                fin = j;

                if(num % 673 == 0) count++;
                
                //cout << "(" << i << "," << j << ") " << num << endl;
            }
            //cout << "(" << i << "," << j << ") end2 " << endl;
        }
        
    }
    
    cout << count << endl;

    return 0;
}