let s = readLine()!
let mod = 2019

func pow(_ a: Int, _ n: Int, _ mod: Int? = nil) -> Int {
  var a = a
  var n = n
  var result: Int = 1
  if let unwrappedMod = mod {
    while n > 0 {
      if n & 1 == 1 { result = result * a % unwrappedMod }
      n >>= 1
      a = a * a % unwrappedMod
    }
    return result
  } else {
    while n > 0 {
      if n & 1 == 1 { result *= a }
      n >>= 1
      a *= a
    }
    return result
  }
}

var tmp = 0
var remainders: [Int: Int] = [0: 1]
for (i, char) in s.reversed().enumerated() {
  let num = Int(String(char))!
  tmp += num * pow(10, i, mod)
  tmp %= mod
  if tmp < 0 { tmp += mod }
  if let v = remainders[tmp] {
    remainders[tmp] = v + 1
  } else {
    remainders[tmp] = 1
  }
}

var result = 0
for v in remainders.values {
  result += v * (v - 1) / 2
}

print(result)
