"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = (arg[0].split(" ")[0]);
    const N = S.length;
    
    let answer = 0;
    let cnt = [...Array(2020)].fill(0);
    cnt[0] = 1;
    
    let total = 0;
    let p = 1;
    
    for(let i=N-1; i>=0; i--) {
        total = (total + parseInt(S[i]) * p) % 2019;
        
        // console.log("total:" + total);
        // console.log("S[i]:" + S[i]);
        
        answer += cnt[total];
        
        p = (p * 10) % 2019;
        // console.log("p:" + p);
        // console.log("------")
        cnt[total]++;
    }
    
    // console.log(cnt);
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));