import Foundation

let str = readLine()!
var left = 0

var result = 0
if str.count <= 1 {
  print(0)
} else {
	for i in 0..<str.count-1 {
  		for j in i+1..<str.count {
  			let current = Int(str.substring(with: NSRange(location: i, length: j - i + 1)))!
  			if current % 2019 == 0 {
              result += 1
  			}
        }
    }
	print(result)
}