S = eval(input())

N = len(S)

rS = S[::-1]



cum = [0] * (N+1)

for i in range(N):

    cum[i+1] = (cum[i] + (int(rS[i]) * pow(10,i,2019)) % 2019) % 2019



ans = 0

from collections import Counter

from math import factorial

c = Counter(cum)

for v in list(c.values()):

    if v >= 2:

        ans += factorial(v) // (factorial(v-2)*2)



print(ans)
S = eval(input())

N = len(S)

rS = S[::-1]



ans = 0

tot = 0

from collections import defaultdict

dic = defaultdict(int)

for i in range(N):

    dic[tot] += 1

    tot += int(rS[i]) * pow(10,i,2019)

    tot %= 2019

    ans += dic[tot]



print(ans)
S = eval(input())
N = len(S)
rS = S[::-1]
cum = [0] * (N + 1)
for i in range(N):
    cum[i + 1] = (cum[i] + (int(rS[i]) * pow(10, i, 2019)) % 2019) % 2019
ans = 0
from collections import Counter
from math import factorial

c = Counter(cum)
for v in list(c.values()):
    if v >= 2:
        ans += factorial(v) // (factorial(v - 2) * 2)
print(ans)

S = eval(input())
N = len(S)
rS = S[::-1]
ans = 0
tot = 0
from collections import defaultdict

dic = defaultdict(int)
for i in range(N):
    dic[tot] += 1
    tot += int(rS[i]) * pow(10, i, 2019)
    tot %= 2019
    ans += dic[tot]
print(ans)

-cum = [0] * (N + 1) +ans = 0 +tot = 0 +from collections import defaultdict + +dic = defaultdict(int) -    cum[i + 1] = (cum[i] + (int(rS[i]) * pow(10, i, 2019)) % 2019) % 2019 -ans = 0 -from collections import Counter -from math import factorial - -c = Counter(cum) -for v in list(c.values()): -    if v >= 2: -        ans += factorial(v) // (factorial(v - 2) * 2) +    dic[tot] += 1 +    tot += int(rS[i]) * pow(10, i, 2019) +    tot %= 2019 +    ans += dic[tot]