# D - Multiple of 2019



from collections import Counter



s = eval(input())



count = 0

counter = Counter([0])



suffix = 0

pow = 1

for i in range(len(s) - 1, -1, -1):

    suffix = (int(s[i]) * pow + suffix) % 2019

    pow = pow * 10 % 2019

    count += counter[suffix]

    counter[suffix] += 1



print(count)

# D - Multiple of 2019



from collections import Counter



s = eval(input())



r = [0]

for d in map(int, s):

    r.append((r[-1] * 10 + d) % 2019)



e = 1

for i in range(len(r) - 1, -1, -1):

    r[i] = r[i] * e % 2019

    e = e * 10 % 2019



def choose2(x):

    return x * (x - 1) // 2



counter = Counter(r)

print((sum(choose2(counter[i]) for i in counter)))
# D - Multiple of 2019
from collections import Counter

s = eval(input())
count = 0
counter = Counter([0])
suffix = 0
pow = 1
for i in range(len(s) - 1, -1, -1):
    suffix = (int(s[i]) * pow + suffix) % 2019
    pow = pow * 10 % 2019
    count += counter[suffix]
    counter[suffix] += 1
print(count)

# D - Multiple of 2019
from collections import Counter

s = eval(input())
r = [0]
for d in map(int, s):
    r.append((r[-1] * 10 + d) % 2019)
e = 1
for i in range(len(r) - 1, -1, -1):
    r[i] = r[i] * e % 2019
    e = e * 10 % 2019


def choose2(x):
    return x * (x - 1) // 2


counter = Counter(r)
print((sum(choose2(counter[i]) for i in counter)))

-count = 0 -counter = Counter([0]) -suffix = 0 -pow = 1 -for i in range(len(s) - 1, -1, -1): -    suffix = (int(s[i]) * pow + suffix) % 2019 -    pow = pow * 10 % 2019 -    count += counter[suffix] -    counter[suffix] += 1 -print(count) +r = [0] +for d in map(int, s): +    r.append((r[-1] * 10 + d) % 2019) +e = 1 +for i in range(len(r) - 1, -1, -1): +    r[i] = r[i] * e % 2019 +    e = e * 10 % 2019 + + +def choose2(x): +    return x * (x - 1) // 2 + + +counter = Counter(r) +print((sum(choose2(counter[i]) for i in counter)))