

fun main() {
    val digits = readLine()!!.trim().toCharArray().map{it - '0'}.toIntArray()
    val mod = 2019
    var digit = 1
    for (i in digits.indices.asIterable().reversed().drop(1)) {
        digit = digit * 10 % mod
        digits[i] = (digits[i + 1] + digits[i] * digit) % mod
    }
    val counts= IntArray(mod){0}.also{it[0] = 1}
    for (d in digits) {
        counts[d]++
    }
    println(
        counts.map{(it * (it - 1L)) shr 1}.sum()
    )
}
