const val mod = 2019

fun main() {
	val t = readLine()!!
	val a = IntArray(mod) {0}
	a[0] = 1

	var m = 0
	var d = 1

	var r = 0L

	for(c in t.reversed().map {it-'0'}) {
		m = (m+c*d)%mod
		r += a[m]++
		d = d*10%mod
	}
	println(r)
}
