M=2019

a=i=0

d=[0]*M

p=1

for j in'0'+input()[::-1]:i=(i+int(j)*p)%M;p=p*10%M;a+=d[i];d[i]+=1

print(a)
M=2019

a=i=0

d=[0]*M

p=1

for j in input()[::-1]:d[i%M]+=1;i-=int(j)*p;a+=d[i%M];p=p*10%M

print(a)
M = 2019
a = i = 0
d = [0] * M
p = 1
for j in "0" + input()[::-1]:
    i = (i + int(j) * p) % M
    p = p * 10 % M
    a += d[i]
    d[i] += 1
print(a)

M = 2019
a = i = 0
d = [0] * M
p = 1
for j in input()[::-1]:
    d[i % M] += 1
    i -= int(j) * p
    a += d[i % M]
    p = p * 10 % M
print(a)

-for j in "0" + input()[::-1]: -    i = (i + int(j) * p) % M +for j in input()[::-1]: +    d[i % M] += 1 +    i -= int(j) * p +    a += d[i % M] -    a += d[i] -    d[i] += 1