import Foundation

func readInt() -> [Int] {
    return readLine()!.split(separator: " ").map { c in Int(c)! }
}

func main() {
    let S = readLine()!

    var x = 0
    var pow10 = 1
    var counts = Array(repeating: 0, count:2019)
    counts[0] = 1
    for c in S.reversed() {
        x += Int(String(c))! * pow10
        pow10 *= 10
        x %= 2019
        pow10 %= 2019
        counts[x] += 1
    }
    let ans = counts.reduce(0) {$0 + $1 * ($1 - 1) / 2}

    print(ans)
}


main()