a = [int(c) * pow(10, i, 2019) % 2019 for i, c in enumerate(reversed(eval(input())))]

s = [0]

for x in a:

  s += [(s[-1] + x) % 2019]

cnt, ans = [0] * 2019, 0

for x in s:

  ans += cnt[x]

  cnt[x] += 1

print(ans)

# originally submitted at https://atcoder.jp/contests/abc164/submissions/12433818

# authored by catamanyan

S = list(map(int,eval(input())))



counter = 0

amari = [0]*2019



s = 0

for i in range(len(S)):

    if S[len(S)-i-1] == 0:

        continue

    else:

        s += S[len(S)-i-1] * pow(10, i, 2019)

        s = s % 2019

        amari[s] += 1



for i in range(2019):

    counter += amari[i] * (amari[i]-1) / 2



counter += amari[0]



print((int(counter)))

a = [int(c) * pow(10, i, 2019) % 2019 for i, c in enumerate(reversed(eval(input())))]
s = [0]
for x in a:
    s += [(s[-1] + x) % 2019]
cnt, ans = [0] * 2019, 0
for x in s:
    ans += cnt[x]
    cnt[x] += 1
print(ans)

# originally submitted at https://atcoder.jp/contests/abc164/submissions/12433818
# authored by catamanyan
S = list(map(int, eval(input())))
counter = 0
amari = [0] * 2019
s = 0
for i in range(len(S)):
    if S[len(S) - i - 1] == 0:
        continue
    else:
        s += S[len(S) - i - 1] * pow(10, i, 2019)
        s = s % 2019
        amari[s] += 1
for i in range(2019):
    counter += amari[i] * (amari[i] - 1) / 2
counter += amari[0]
print((int(counter)))

-a = [int(c) * pow(10, i, 2019) % 2019 for i, c in enumerate(reversed(eval(input())))] -s = [0] -for x in a: -    s += [(s[-1] + x) % 2019] -cnt, ans = [0] * 2019, 0 -for x in s: -    ans += cnt[x] -    cnt[x] += 1 -print(ans) +# originally submitted at https://atcoder.jp/contests/abc164/submissions/12433818 +# authored by catamanyan +S = list(map(int, eval(input()))) +counter = 0 +amari = [0] * 2019 +s = 0 +for i in range(len(S)): +    if S[len(S) - i - 1] == 0: +        continue +    else: +        s += S[len(S) - i - 1] * pow(10, i, 2019) +        s = s % 2019 +        amari[s] += 1 +for i in range(2019): +    counter += amari[i] * (amari[i] - 1) / 2 +counter += amari[0] +print((int(counter)))