import numpy as np

s = eval(input())

y = 2019

dp = np.zeros(y, dtype="int64")

tmp = np.zeros(y, dtype="int64")

k = 1

r = 0

for c in s[::-1]:

    i = int(c)*k%y

    tmp[i:] = dp[:y-i]

    tmp[:i] = dp[y-i:]

    tmp[i] += 1

    dp, tmp = tmp, dp

    r += dp[0]

    k *= 10

    k %= y

print(r)
y=2019

a=[0]*y

k=1

r=p=0

for c in input()[::-1]:

    a[p]+=1

    p-=int(c)*k

    p%=y

    r+=a[p]

    k*=10

    k%=y

print(r)



import numpy as np

s = eval(input())
y = 2019
dp = np.zeros(y, dtype="int64")
tmp = np.zeros(y, dtype="int64")
k = 1
r = 0
for c in s[::-1]:
    i = int(c) * k % y
    tmp[i:] = dp[: y - i]
    tmp[:i] = dp[y - i :]
    tmp[i] += 1
    dp, tmp = tmp, dp
    r += dp[0]
    k *= 10
    k %= y
print(r)

y = 2019
a = [0] * y
k = 1
r = p = 0
for c in input()[::-1]:
    a[p] += 1
    p -= int(c) * k
    p %= y
    r += a[p]
    k *= 10
    k %= y
print(r)

-import numpy as np - -s = eval(input()) -dp = np.zeros(y, dtype="int64") -tmp = np.zeros(y, dtype="int64") +a = [0] * y -r = 0 -for c in s[::-1]: -    i = int(c) * k % y -    tmp[i:] = dp[: y - i] -    tmp[:i] = dp[y - i :] -    tmp[i] += 1 -    dp, tmp = tmp, dp -    r += dp[0] +r = p = 0 +for c in input()[::-1]: +    a[p] += 1 +    p -= int(c) * k +    p %= y +    r += a[p]