import java.io.PrintWriter

fun main() {
    val pw = PrintWriter(System.out)

    val mod = 2019
    val modDiv = 673

    val s = readInputLine().toCharArray()

    val cnt = LongArray(mod * 2)

    var ans = 0L

    repeat(s.size) {
        val digit = (s[it] - '0')

        for (i in 0 until modDiv) {
            cnt[(it % 2) * mod + i] = 0L
            cnt[(it % 2) * mod + modDiv + i] = 0L
            cnt[(it % 2) * mod + modDiv * 2 + i] = 0L
        }

        for (i in 0 until modDiv) {
            val locIndex = ((i * 10 + digit) % modDiv)
            cnt[(it % 2) * mod + (digit % 3) * modDiv + locIndex] = cnt[((it + 1) % 2) * mod + i]
            cnt[(it % 2) * mod + ((digit + 1) % 3) * modDiv + locIndex] = cnt[((it + 1) % 2) * mod + modDiv + i]
            cnt[(it % 2) * mod + ((digit + 2) % 3) * modDiv + locIndex] = cnt[((it + 1) % 2) * mod + modDiv * 2 + i]
        }

        ans += cnt[(it % 2) * mod]

        cnt[(it % 2) * mod + (digit % 3) * modDiv + digit]++
    }

    pw.println(ans)

    pw.flush()
}

fun readInputLine(): String {
    return readLine()!!
}
