fun main(args: Array<String>) = abc164d()

@OptIn(ExperimentalStdlibApi::class)
fun abc164d() {
    val s = readLine()!!.reversed().map { Character.getNumericValue(it) }.toIntArray()
    val mod = 2019
    
    val modded = IntArray(s.size)
    var digit = 1
    for (i in s.indices) {
        modded[i] = (s[i] * digit) % mod
        digit *= 10
        digit %= mod
    }

    val moddedCSum = modded.scan(0) { acc: Int, i: Int -> (acc + i) % mod }.toIntArray()

    val appeared = mutableMapOf<Int, Int>().withDefault { 0 }
    var answer = 0L

    for (mcs in moddedCSum) {
        val app = appeared.getValue(mcs)
        answer += app
        appeared[mcs] = app + 1
    }

    println(answer)
}
