import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun sumList(a: Iterable<Long>): List<Long> {
        val result = mutableListOf(0L)
        var i = 0L
        a.forEach {
            i += it
            i %= 2019
            result.add(i)
        }
        return result
    }

    fun <A> countList(a: List<A>): Map<A, Long> {
        val result = mutableMapOf<A, Long>()
        a.forEach {
            result[it] = (result[it] ?: 0L) + 1L
        }
        return result
    }

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val S = sc.next().map { (it - '0').toLong() }.toLongArray()
        val N = S.count()

        val s = LongArray(N)
        var d = 1
        for (i in 0 until N) {
            s[i] = (S[N - i - 1] * d) % 2019
            d *= 10
            d %= 2019
        }
        val sum = sumList(s.toList())
        var ans = 0L
        countList(sum).forEach {
            ans += (it.value) * (it.value - 1) / 2
        }
        pw.println(ans)
    }
}
