# D - Multiple of 2019



from collections import Counter



s = eval(input())



count = 0

counter = Counter([0])



suffix = [0] * (len(s) + 1)

pow = 1

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

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

    pow = pow * 10 % 2019

    count += counter[suffix[i]]

    counter[suffix[i]] += 1



print(count)

# 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())
count = 0
counter = Counter([0])
suffix = [0] * (len(s) + 1)
pow = 1
for i in range(len(s) - 1, -1, -1):
    suffix[i] = (int(s[i]) * pow + suffix[i + 1]) % 2019
    pow = pow * 10 % 2019
    count += counter[suffix[i]]
    counter[suffix[i]] += 1
print(count)

# 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)

-suffix = [0] * (len(s) + 1) +suffix = 0 -    suffix[i] = (int(s[i]) * pow + suffix[i + 1]) % 2019 +    suffix = (int(s[i]) * pow + suffix) % 2019 -    count += counter[suffix[i]] -    counter[suffix[i]] += 1 +    count += counter[suffix] +    counter[suffix] += 1