let mod = 2019

let S = readLine()!
var place = 1
var remainder = 0
var count = Array(repeating: 0, count: mod)
count[0] = 1
for char in S.reversed() {
    remainder += place * Int(String(char))!
    remainder %= mod
    count[remainder] += 1
    place = place * 10 % mod
}

var ans = 0
count.forEach({m in ans += m * (m - 1) / 2})
print(ans)
