def modpow(d, b, p, mod=2019):

    ret = 1

    while p > 0:

        if p % 2 == 1:

            ret = ret * b % mod

        b = b * b % mod

        p //= 2

    return (d * ret) % mod





S = eval(input())

C = [0]

for i in range(len(S)):

    C.append((C[-1] + modpow(int(S[-(i + 1)]), 10, i)) % 2019)

Cd = {}

for c in C[1:]:

    Cd[c] = Cd.get(c, 0) + 1

print((Cd.get(0, 0) + sum([v * (v - 1) // 2 for v in list(Cd.values())])))

S = eval(input())

mS, m10, mSd = [0], 1, {}

for i in range(len(S)):

    mS.append((mS[-1] + int(S[-(i + 1)]) * m10) % 2019)

    m10 = (m10 * 10) % 2019

for s in mS[1:]:

    mSd[s] = mSd.get(s, 0) + 1

print((mSd.get(0, 0) + sum([v * (v - 1) // 2 for v in list(mSd.values())])))

def modpow(d, b, p, mod=2019):
    ret = 1
    while p > 0:
        if p % 2 == 1:
            ret = ret * b % mod
        b = b * b % mod
        p //= 2
    return (d * ret) % mod


S = eval(input())
C = [0]
for i in range(len(S)):
    C.append((C[-1] + modpow(int(S[-(i + 1)]), 10, i)) % 2019)
Cd = {}
for c in C[1:]:
    Cd[c] = Cd.get(c, 0) + 1
print((Cd.get(0, 0) + sum([v * (v - 1) // 2 for v in list(Cd.values())])))

S = eval(input())
mS, m10, mSd = [0], 1, {}
for i in range(len(S)):
    mS.append((mS[-1] + int(S[-(i + 1)]) * m10) % 2019)
    m10 = (m10 * 10) % 2019
for s in mS[1:]:
    mSd[s] = mSd.get(s, 0) + 1
print((mSd.get(0, 0) + sum([v * (v - 1) // 2 for v in list(mSd.values())])))

-def modpow(d, b, p, mod=2019): -    ret = 1 -    while p > 0: -        if p % 2 == 1: -            ret = ret * b % mod -        b = b * b % mod -        p //= 2 -    return (d * ret) % mod - - -C = [0] +mS, m10, mSd = [0], 1, {} -    C.append((C[-1] + modpow(int(S[-(i + 1)]), 10, i)) % 2019) -Cd = {} -for c in C[1:]: -    Cd[c] = Cd.get(c, 0) + 1 -print((Cd.get(0, 0) + sum([v * (v - 1) // 2 for v in list(Cd.values())]))) +    mS.append((mS[-1] + int(S[-(i + 1)]) * m10) % 2019) +    m10 = (m10 * 10) % 2019 +for s in mS[1:]: +    mSd[s] = mSd.get(s, 0) + 1 +print((mSd.get(0, 0) + sum([v * (v - 1) // 2 for v in list(mSd.values())])))