from collections import Counter





def f(mod):

    ret = [0]

    power = 1

    num = 0

    for i, e in enumerate(s, 1):

        num *= 10

        num += int(e)

        num %= mod



        power *= 10

        power %= mod

        inv = pow(power, mod - 2, mod)



        ret.append(num * inv % mod)



    return ret





s = eval(input())



mod3 = f(3)

mod673 = f(673)



li = [10 * e673 + e3 for e3, e673 in zip(mod3, mod673)]



c = Counter(li)

ans = 0

for v in list(c.values()):

    ans += v * (v - 1) // 2

print(ans)

from collections import Counter



s = eval(input())

mod = 2019



li = [0]

num = 0

power = 1

for e in s[::-1]:

    num += int(e) * power

    num %= mod

    li.append(num)



    power *= 10

    power %= mod



c = Counter(li)

ans = 0

for v in list(c.values()):

    ans += v * (v - 1) // 2

print(ans)

from collections import Counter


def f(mod):
    ret = [0]
    power = 1
    num = 0
    for i, e in enumerate(s, 1):
        num *= 10
        num += int(e)
        num %= mod
        power *= 10
        power %= mod
        inv = pow(power, mod - 2, mod)
        ret.append(num * inv % mod)
    return ret


s = eval(input())
mod3 = f(3)
mod673 = f(673)
li = [10 * e673 + e3 for e3, e673 in zip(mod3, mod673)]
c = Counter(li)
ans = 0
for v in list(c.values()):
    ans += v * (v - 1) // 2
print(ans)

from collections import Counter

s = eval(input())
mod = 2019
li = [0]
num = 0
power = 1
for e in s[::-1]:
    num += int(e) * power
    num %= mod
    li.append(num)
    power *= 10
    power %= mod
c = Counter(li)
ans = 0
for v in list(c.values()):
    ans += v * (v - 1) // 2
print(ans)

- -def f(mod): -    ret = [0] -    power = 1 -    num = 0 -    for i, e in enumerate(s, 1): -        num *= 10 -        num += int(e) -        num %= mod -        power *= 10 -        power %= mod -        inv = pow(power, mod - 2, mod) -        ret.append(num * inv % mod) -    return ret - - -mod3 = f(3) -mod673 = f(673) -li = [10 * e673 + e3 for e3, e673 in zip(mod3, mod673)] +mod = 2019 +li = [0] +num = 0 +power = 1 +for e in s[::-1]: +    num += int(e) * power +    num %= mod +    li.append(num) +    power *= 10 +    power %= mod