s = eval(input())

l = len(s)

t = [0] * l

t[l - 1] = int(s[l - 1])

m = [0] * 2019

m[0] = 1

m[int(s[l - 1])] = 1

ten = 10

ans = 0



for i in range(l - 1, 0, -1):

    t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019

    ten = ten * 10 % 2019

    m[t[i - 1]] += 1



for i in m:

    ans += i * (i - 1) // 2



print(ans)
s = input()[::-1]

l = len(s)

c = [0] * 2019

c[0] = 1

ten = 1

mod = 0

ans = 0



for i in range(l):

    mod = (mod + int(s[i]) * ten) % 2019

    ten = ten * 10 % 2019

    c[mod] += 1



for i in c:

    ans += i * (i - 1) // 2



print(ans)
s = eval(input())
l = len(s)
t = [0] * l
t[l - 1] = int(s[l - 1])
m = [0] * 2019
m[0] = 1
m[int(s[l - 1])] = 1
ten = 10
ans = 0
for i in range(l - 1, 0, -1):
    t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019
    ten = ten * 10 % 2019
    m[t[i - 1]] += 1
for i in m:
    ans += i * (i - 1) // 2
print(ans)

s = input()[::-1]
l = len(s)
c = [0] * 2019
c[0] = 1
ten = 1
mod = 0
ans = 0
for i in range(l):
    mod = (mod + int(s[i]) * ten) % 2019
    ten = ten * 10 % 2019
    c[mod] += 1
for i in c:
    ans += i * (i - 1) // 2
print(ans)

-s = eval(input()) +s = input()[::-1] -t = [0] * l -t[l - 1] = int(s[l - 1]) -m = [0] * 2019 -m[0] = 1 -m[int(s[l - 1])] = 1 -ten = 10 +c = [0] * 2019 +c[0] = 1 +ten = 1 +mod = 0 -for i in range(l - 1, 0, -1): -    t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019 +for i in range(l): +    mod = (mod + int(s[i]) * ten) % 2019 -    m[t[i - 1]] += 1 -for i in m: +    c[mod] += 1 +for i in c: