let S = readLine()!

var r = 0
for i in S.indices {
    var s = S[i...]
    while let j = s.index(i, offsetBy: 5, limitedBy: s.endIndex) {
        let a = Int(s[i..<j])!
        let b = a % 2019
        if b == 0 { r += 1 }
        s.replaceSubrange(i..<j, with: String(b))
    }
    
    
    for i in s.indices {
        let m = s.index(i, offsetBy: 10, limitedBy: S.endIndex) ?? S.endIndex
        for j in s[i..<m].indices {
            if Int(s[i...j])!.isMultiple(of: 2019) {
                r += 1
            }
        }
    }
}

print(r)
