import java.util.Scanner


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val s = sc.next

    val len = s.length

    var cnt = 0

    (4 to len).map { b =>
      (0 to len - b).map { i =>
        if (BigInt(s.substring(i, b + i)) % 2019 == 0) cnt += 1
      }
    }

    println(cnt)

  }
}
