s = list(map(int,input()))

dp = [0] * 2019

count = 0

for j in range(len(s)):

    ndp = [0] * 2019

    ndp[s[j]] += 1

    for k in range(len(dp)):ndp[(10*k + s[j]) % 2019] += dp[k]

    count += ndp[0]

    dp = ndp



print(count)





import collections

h = collections.Counter([0])

cumul,m,ans = 0,2019,0

pt = 1

for j,u in enumerate(map(int,list(input()))[::-1]):

	cumul += u * pt

	cumul %= m

	pt *= 10

	pt %= m

	ans += h[cumul]

	h[cumul]+=1

print(ans)



s = list(map(int, input()))
dp = [0] * 2019
count = 0
for j in range(len(s)):
    ndp = [0] * 2019
    ndp[s[j]] += 1
    for k in range(len(dp)):
        ndp[(10 * k + s[j]) % 2019] += dp[k]
    count += ndp[0]
    dp = ndp
print(count)

import collections

h = collections.Counter([0])
cumul, m, ans = 0, 2019, 0
pt = 1
for j, u in enumerate(map(int, list(input()))[::-1]):
    cumul += u * pt
    cumul %= m
    pt *= 10
    pt %= m
    ans += h[cumul]
    h[cumul] += 1
print(ans)

-s = list(map(int, input())) -dp = [0] * 2019 -count = 0 -for j in range(len(s)): -    ndp = [0] * 2019 -    ndp[s[j]] += 1 -    for k in range(len(dp)): -        ndp[(10 * k + s[j]) % 2019] += dp[k] -    count += ndp[0] -    dp = ndp -print(count) +import collections + +h = collections.Counter([0]) +cumul, m, ans = 0, 2019, 0 +pt = 1 +for j, u in enumerate(map(int, list(input()))[::-1]): +    cumul += u * pt +    cumul %= m +    pt *= 10 +    pt %= m +    ans += h[cumul] +    h[cumul] += 1 +print(ans)