'use strict'

function Main(input) {
    const S = input.trim().split('').join('');
    // console.log(S);

    let result = 0;
    for (let i = 0; i < S.length - 3; i++) {
        for (let j = i + 3; j < S.length; j++) {
            const tmp = Number(S.slice(i, j + 1));
            if (tmp % 2019 === 0) {
                // console.log(tmp);
                result += 1;
            }
        }
    }

    console.log(result);
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

