import java.util.Scanner
import scala.util.control.Breaks._

object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val strLong: Long  = sc.nextLong
    val str = strLong.toString
    var strLen = str.length

    var numOfMultiple: Long = 0L
    for (i <- 0 to strLen; j <- 0 to strLen){
        var res = str.drop(i).dropRight(strLen - j)
        if(res.length > 4)  {
            if(res.toLong % 2019L == 0L){
            numOfMultiple = numOfMultiple + 1
            }
        }
    } 
    
    println(numOfMultiple)
    
  }
}