                    // parameter "input" gets all data
                    function Main(input) {
                    	// the first line is assigned to input[0], the second line is assigned to input[1] similarly.
                    	input = input.split("\n");
                    	text = input[0].split(" ");
                    	
                     
                      	let powOfTen = 1;
                	let map = new Map();
                	let mod = 2019;
                	let ans = 0;
                	let suf = 0;
                	map.set(0, 1);
                      if (text.length <= 4) {
		ans = (parseInt(text, 10) % mod) === 0 ? 1 : 0; 
	} else {
    	for (let i = text.length -1; i>=0; i--) {
                		suf = (suf + parseInt(text[i], 10) * powOfTen) % mod;
                		powOfTen = 10 * powOfTen % mod;
                		let mapTmp = map.get(suf);
                		ans += (typeof mapTmp !== 'undefined') ? mapTmp : 0;
                		
                		if (typeof mapTmp !== 'undefined') {
                			map.set(suf, mapTmp++);
                		} else {
                			map.set(suf, 1);
                		}
                	}
    }
                  
                	
                 
                      
                    	//output
                    	console.log('%d',ans);
                    }
                    // Don't edit this line!
                    Main(require("fs").readFileSync("/dev/stdin", "utf8"));