let S = readLine()!

var r = 0
for i in S.indices {
    var s = S[i...]
    
    let sum = s.reduce(0) { $0 + $1.wholeNumberValue! }
    if !sum.isMultiple(of: 3) {
        continue
    }
    
    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))
    }
    
    if s != "0" && Int(s)!.isMultiple(of: 2019) {
        r += 1
    }
}

print(r)
