S = eval(input())

mod = [0]

for d, c in enumerate(S[::-1]):

    mod.append((int(c) * pow(10, d, 2019) + mod[-1]) % 2019)

from collections import *

print((sum(v * (v - 1) // 2 for v in list(Counter(mod).values()))))

mod = [0]

pw = 1

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

    mod.append((int(c) * pw + mod[-1]) % 2019)

    pw = pw * 10 % 2019

from collections import *

print((sum(v * (v - 1) // 2 for v in list(Counter(mod).values()))))

S = eval(input())
mod = [0]
for d, c in enumerate(S[::-1]):
    mod.append((int(c) * pow(10, d, 2019) + mod[-1]) % 2019)
from collections import *

print((sum(v * (v - 1) // 2 for v in list(Counter(mod).values()))))

mod = [0]
pw = 1
for c in input()[::-1]:
    mod.append((int(c) * pw + mod[-1]) % 2019)
    pw = pw * 10 % 2019
from collections import *

print((sum(v * (v - 1) // 2 for v in list(Counter(mod).values()))))

-S = eval(input()) -for d, c in enumerate(S[::-1]): -    mod.append((int(c) * pow(10, d, 2019) + mod[-1]) % 2019) +pw = 1 +for c in input()[::-1]: +    mod.append((int(c) * pw + mod[-1]) % 2019) +    pw = pw * 10 % 2019