fun main() {
    var s = readLine()!!
    var mod = IntArray(2019, { 0 })
    var ans = 0
    for (i in 0 until s.length) {
        var tmp = IntArray(2019, { 0 })
        for (j in 0 until 2019) {
            if (mod[j] == 0) continue
            var nxt = (j * 10 + (s[i] - '0')) % 2019
            if (nxt == 0) ans += mod[j]
            tmp[nxt] = mod[j]
        }
        tmp[s[i] - '0']++
        mod = tmp
    }
    print(ans)
}