extension Int {
    func pow(_ x: Int) -> Int {
        if x < 1 { fatalError() }
        var base = 1
        for _ in 1...x {
            base *= self
        }
        return base
    }
}

extension Collection where Element == Int {
    func createN() -> Int {
        self.reversed()
            .enumerated()
            .reduce(0) { $0 + $1.element.pow($1.offset) }
    }
}

let S = readLine()!.map { $0.wholeNumberValue! }

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 = s.createN()
        let b = a % 2019
        if b == 0 { r += 1 }
        s.replaceSubrange(i..<j, with: String(b).map { $0.wholeNumberValue! })
    }
    
    if s != [0] && s.createN().isMultiple(of: 2019) {
        r += 1
    }
}

print(r)
