const S = require("fs").readFileSync("/dev/stdin", "utf8")
const mod = 2019
const map = Array(2020).fill(0)
map[0] = 1
let c = 0
let p = 1
let m = 0

for (let i = S.length - 1; i >= 0; i--) {
    m = (m + S[i] * p) % mod
    c += map[m]
    map[m]++
    p = p * 10 % mod
}

console.log(c)
