import kotlin.math.*
import java.util.*

const val y = 2019

fun main(args: Array<String>) {
  val s = readLine()!!.reversed()
  if (s.length < 4) {
    println(0)
    return
  }
  val t = IntArray(s.length + 1)
  t[0] = s[0] - '0'
  var d = 10
  for (i in 1 until s.length) {
    t[i] = (t[i - 1] + (s[i] - '0') * d) % y
    d = (10 * d) % y
  }
  val u = IntArray(y)
  t.forEach { u[it]++ }
  println(u.map { it * (it - 1) / 2 }.sum())
}
