(S => {
    const mod = 2019
    const map = Array(2019).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
    }

    c = 0
    console.log(c)

})(require("fs").readFileSync("/dev/stdin", "utf8"))
