// 三整除那道题
#include <iostream>
#include <vector>
#include <string>
using namespace std;

bool judge(string &str) {
    int res = 0;
    for(auto c : str)
        res += (c - '0');
    return (res % 3 == 0);
}

int fun(const string &str) {
    if(str.empty())
        return 0;
    int len = str.size();
    vector<vector<int>> dp(len + 1, vector<int>(len + 1, 0));
    for(int i = 1; i <= len; ++i) {
        for(int j = 1; j <= len - i + 1; ++j) {
            for(int k = 1; k < i; ++k) {
                dp[j][j + i - 1] =
                max(dp[j][j + i - 1], dp[j][j + k - 1] + dp[j + k][j + i - 1]);
            }
            string tmp = str.substr(j - 1, i);
            if(judge(tmp))
                dp[j][j + i - 1] = max(1, dp[j][j + i - 1]);
        }
    }
    return dp[1][len];
}

int main()
{
    string str;
    cin >> str;
    cout << fun(str) << endl;
    return 0;
}