import Foundation

let input_line: String = readLine()!
let text = input_line

let count = text.count

var ans = 0

for i in 0...count {
    for k in 0...count {
        
        if i >= k { continue }
        if i - 1 < 0 { continue }
        if k - 1 < 0 { continue }


        let text1 = text[text.index(text.startIndex, offsetBy: i - 1)...text.index(text.startIndex, offsetBy: k - 1)]

        let a = Int(text1)!
        
        if a % 2019 == 0 {
            ans += 1
        }
        
    }
}


print(ans)