fun main() {
    val digits = readLine()!!.map { it.toString().toInt() }

    var ans = 0
    var map = IntArray(2019)
    for (i in 0..digits.size - 1) {
        val d = digits[i]

        // map * 10 + d
        var cpy = IntArray(2019)
        for ((i, cnt) in map.withIndex()) {
            cpy[(10 * i + d) % 2019] = cnt
        }
        ans += cpy[0]
        cpy[d]++
        map = cpy
    }

    print(ans)
}
