let S = readLine()!

var r = 0
for i in 0..<S.count {
    let m = min(i + 19, S.count)
    for j in i..<m {
        let s = S.index(S.startIndex, offsetBy: i)
        let e = S.index(S.startIndex, offsetBy: j)
        if Int(S[s...e])!.isMultiple(of: 2019) {
            r += 1
        }
    }
}
print(r)
