fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length
    
    val mod = Array(n) { 1 }
    for (i in 1 until n) {
        mod[i] = 10*mod[i-1]%2019
    }

    val t = Array(n+1) { 0 }
    for (i in n-1 downTo 0) {
        val tmp = Integer.parseInt(s[i].toString())
        t[i] = (t[i+1] + mod[n-i-1]*tmp)%2019
    }
    
    val map = mutableMapOf(0 to 0)
    t.forEach { if(map.containsKey(it)) map[it] = map[it]!!+1 else map[it] = 1 }
    
    var res = 0
    for (item in map) {
        val m = item.value
        res += m*(m-1)/2
    }
    
    println(res)
}
