fun main() {
    val s = readLn()

    val mod673 = mutableListOf<Int>()
    val mod3 = mutableListOf<Int>()
    val mod = 673


    val mul = mutableListOf<Int>()
    mul.add(1)
    for (i in s.length - 1 downTo 0) {
        val num = (s[i] - '0')
        mod673.add(((if (mod673.isNotEmpty()) mod673.last() else 0) + mul[s.length - i - 1] * num) % mod)
        mod3.add((num + if (mod3.isNotEmpty()) mod3.last() else 0) % 3)
        mul.add((mul.last() * 10) % mod)
    }

    val occurs = mutableMapOf<Pair<Int, Int>, Int>()
    occurs[Pair(0, 0)] = 1

    mod673.forEachIndexed { index, it ->
        val key = Pair(it, mod3[index])
        occurs[key] = occurs[key]?.plus(1) ?: 1
    }
    var ans = 0L
    occurs.forEach { (_, occ) -> ans += (occ.toLong() * (occ - 1)) / 2 }
    println(ans)
}

// Input Reader
private fun readLn() = readLine()!!
