fun main(args: Array<String>) {
    var s = readLine()!!.toList().map{Character.getNumericValue(it)}
    var remainders = Array(2019){0}
    var remainder = 0
    var ten = 1
    var ans = 0L
    for ((i, si) in s.reversed().withIndex()) {
        remainder = (ten * si + remainder)%2019
        remainders[remainder] += 1
        ten *= 10
        ten %= 2019
    }
    for (r in remainders) {
        if (r>1) {
            ans += r*(r-1)/2L  
        }
    }
    ans += remainders[0]
    println(ans)
}

