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+1) {
        power_mods ~= power_mods[$-1] * 10 % 2019;
    }
    
    int[] mods; mods.length = S.length;
    int mod_tmp;
    foreach (i; 0 .. S.length) {
        mod_tmp = ( 10 * mod_tmp + (S[i] - '0') ) % 2019;
        mods[i] = mod_tmp;
    }
    
    
    foreach (i; 0 .. S.length) foreach (j; i .. S.length) {
        if (mods[j] == 0) ans++;
        
        mods[j] = (mods[j] - (S[i]-'0')*power_mods[j-i] + 2019 * 20) % 2019;
    }
    
    writeln(ans);
}

uint keta(uint n) {
    uint r = 1;
    while (n >= 10) { n /= 10; r++; }
    return r;
}