fun pow10mod2019List():List<Int> {
    val result = (1..200000).map { 0 }.toMutableList() 
    result[0] = 1
    for(i in 1 until 200000) {
        result[i] = (result[i-1] * 10) % 2019
    }
    return result
}

fun solve(input: String, memo_list: List<Int>): Long {
    val _input = input.reversed()
    val len = input.length
    
    val mod_list = (1..len).map { 0 }.toMutableList()
    mod_list[0] = (_input[0] - '0').toInt()
    val mod_map: MutableMap<Int,Long> = mutableMapOf()
    mod_map[0] = 1L
    mod_map[mod_list[0]] = mod_map.getOrDefault(mod_list[0], 0L) + 1L
    for(i in 1 until len) {
        mod_list[i] = (mod_list[i - 1] + (memo_list[i] * (_input[i] - '0').toInt()) % 2019) % 2019
        mod_map[mod_list[i]] = mod_map.getOrDefault(mod_list[i], 0L) + 1L
    }
    // mod_map.forEach { i, v -> 
    //     println("${i} -> ${v}")
    // }
    return mod_map.values.map {it -> it * (it-1)/2}.fold(0L) {a,b -> a+b}
}
fun main(args: Array<String>) {
    val S = readLine()!!
    val memo_list = pow10mod2019List()
    solve(S, memo_list).run(::println)
}