import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val s = in.readLine().toList.map(_.toInt - '0')

    @tailrec
    def count(c: Long, remainder: Long, s: List[Int]): Long = {
      s match {
        case head :: rest =>
          val v = remainder * 10L + head
          val new_remainder = v % 2019
          if (new_remainder == 0) {
            count(c + 1, 0L, rest)
          } else {
            count(c, new_remainder, rest)
          }
        case Nil =>
          c
      }
    }

    var c = 0L
    for (i <- s.indices) {
      c += count(0L, 0L, s.slice(i, s.length))
    }
    out.println(c)

    out.flush()
  }
}
