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

import scala.collection.mutable

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').reverse
    val MOD = 2019

    val remainders = s.scanLeft((0, 1)) {
      case ((acc, base), c) =>
        ((acc + base * c) % MOD, base * 10 % MOD)
    }.map(_._1)

    val remainderMap = remainders.foldLeft(mutable.HashMap.empty[Int, Long]) {
      case (acc, remainder) =>
        acc.update(remainder, acc.getOrElse(remainder, 0L) + 1L)
        acc
    }

    out.println(
      remainderMap.foldLeft(0L) {
        case (acc, (_, count)) =>
          acc + count * (count - 1) / 2
      }
    )

    out.flush()
  }
}
