import java.util

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt
import java.util.Scanner
import java.util.ArrayList

object Main extends App {
  val sc = new Scanner(System.in)
  val s = sc.next().reverse
//  println(s.size)
  var dp = new Array[Int](s.size+1)
  var cnt = new Array[Int](2019)
  var p = 1
  for(i <- 0 to s.size-1){
//    println(i)
    dp(i+1) = dp(i) + p*(s(i) - '0')
    dp(i+1) %= 2019
    p *= 10
    p %= 2019
  }
  for(i <- 0 to s.size)cnt(dp(i)) += 1
  var ans = 0l
  for(i <- 0 to 2018)ans += cnt(i)*(cnt(i)-1)/2
  println(ans)





}