import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val S = sc.nextLine()
  val a = BigInt(0) +: Array.tabulate(S.length)(x => BigInt(S.takeRight(x + 1)).mod(BigInt(2019)))
  val b = a.groupBy(_.toInt).view.mapValues(_.length).values.map(x => x * (x - 1) / 2).sum
  println(b)
}
