process.stdin.resume();
process.stdin.setEncoding('utf8');
var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
reader.on('line', (line) => {
    lines.push(line);
});
reader.on('close', () => {
    const str = lines[0].split("");
    let ans = 0;
    for(let i = 0; i <= str.length - 1; i++){
        for(let j = i + 4; j <= str.length; j++){
            const num = parseInt(str.slice(i, j).join(""));
            if (num % 2019 === 0){
                ans++;
            }
        }
    }
    console.log(ans);
});