const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(S => {
    const mod = 2019n
    const m = []

    for (let i = 0; i <= S.length; i++) {
        m[i] = BigInt(S.substring(i)) % mod
    }

    const dp = []
    let c = 0

    for (let i = 0; i < m.length; i++) {
        if (dp[m[i]] !== undefined) {
            dp[m[i]]++
            c++
        } else {
            dp[m[i]] = 0
        }
    }
    
    console.log(c)

})(input)
