import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
    auto S = readln.split[0];
    long ans;
    
    int[] power_mods = [1];
    foreach (i; 1 .. S.length+10) {
        power_mods ~= power_mods[$-1] * 10 % 673;
    }
    
    int[] sums;
    int sum_tmp;
    int[] mods; mods.length = S.length;
    int mod_tmp;
    //uint[short] mod_nums;
    foreach (i; 0 .. S.length) {
        mod_tmp = ( 10 * mod_tmp + (S[i] - '0') ) % 673;
        sum_tmp += S[i] - '0';
        sums ~= sum_tmp;
        mods[i] = mod_tmp;
    }
    
    
    foreach (j; 3 .. S.length) {
        if (mods[j] == 0) ans++;
        foreach (i; 1 .. j-1) {
            //writeln(j, " ", i, " ", j-i+1);
            if ( (sums[j] - sums[i-1]) % 3 == 0 && mods[j] == power_mods[j-i+1] * mods[i-1] % 673) ans++;
        }
    }
    
    writeln(ans);
    
}