s,l = (eval(input()),2019)

m,a,r = ([1]+[0]*l,0,0)

for i,e in enumerate(s[::-1]):

    a += int(e)*pow(10,i,l)

    r += m[a%l]

    m[a%l] += 1

print(r)

s = list(map(int,list(eval(input()))))[::-1]

n = len(s)

chk = [0]*2019

chk[0] = 1

t,m,ans = 1,0,0

for i in s:

    m = (m+t*i)%2019

    ans += chk[m]

    chk[m] += 1

    t = t*10%2019

print(ans)

s, l = (eval(input()), 2019)
m, a, r = ([1] + [0] * l, 0, 0)
for i, e in enumerate(s[::-1]):
    a += int(e) * pow(10, i, l)
    r += m[a % l]
    m[a % l] += 1
print(r)

s = list(map(int, list(eval(input()))))[::-1]
n = len(s)
chk = [0] * 2019
chk[0] = 1
t, m, ans = 1, 0, 0
for i in s:
    m = (m + t * i) % 2019
    ans += chk[m]
    chk[m] += 1
    t = t * 10 % 2019
print(ans)

-s, l = (eval(input()), 2019) -m, a, r = ([1] + [0] * l, 0, 0) -for i, e in enumerate(s[::-1]): -    a += int(e) * pow(10, i, l) -    r += m[a % l] -    m[a % l] += 1 -print(r) +s = list(map(int, list(eval(input()))))[::-1] +n = len(s) +chk = [0] * 2019 +chk[0] = 1 +t, m, ans = 1, 0, 0 +for i in s: +    m = (m + t * i) % 2019 +    ans += chk[m] +    chk[m] += 1 +    t = t * 10 % 2019 +print(ans)