import collections

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)





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

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)

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 - -    dp = ndp[::] +    dp = ndp