import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val S = in.next()
  val N = S.length
  // val a = new Array[Int](N)
  val h = 2019
  val dp = Array.ofDim[Long](N+1, h)

  for (i <- 1 to N) {
    val now = S(i-1).toString.toInt

    dp(i)(now) += 1
    for (k <- 0 until h) {
      //dp(i)(k) += dp(i-1)(k)
      val n = (k * 10 + now) % h
      // if (n == 0)
      //   println(k)
      dp(i)(n) += dp(i-1)(k) // 
    }
  }

  var ans = 0L
  for (i <- 1 to N) 
    ans += dp(i)(0)
  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
