# D - Multiple of 2019



s = eval(input())



# pow[k] = 10 ** k % 2019

pow = [1]

while len(pow) <= 1 or pow[-1] > 1:

    pow.append(pow[-1] * 10 % 2019)

n = len(pow) - 1  # 10 ** n == 1 mod 2019



# memo[i % n][m] = (int(s[:i+1]) % 2019 == mであるiの個数)

memo = [[0] * 2019 for i in range(n)]

memo[n - 1][0] = 1  # memo[-1][0] = 1



count = 0  # int(s[i:j+1]) == 0 mod 2019 である(i,j)の個数

mod = 0

for j, c in enumerate(s):

    mod = (mod * 10 + int(c)) % 2019  # mod = int(s[:j+1]) % 2019

    for i in range(1, n + 1):

        m = mod * pow[n - i] % 2019  # m == mod * 10 ** (-i) mod 2019

        count += memo[(j - i + n) % n][m]

    memo[j % n][mod] += 1



print(count)

# D - Multiple of 2019



from collections import Counter



s = eval(input())



count = 0

counter = Counter([0])



suffix = [0] * (len(s) + 1)

pow = 1

for i in range(len(s) - 1, -1, -1):

    suffix[i] = (int(s[i]) * pow + suffix[i + 1]) % 2019

    pow = pow * 10 % 2019

    count += counter[suffix[i]]

    counter[suffix[i]] += 1



print(count)

# D - Multiple of 2019
s = eval(input())
# pow[k] = 10 ** k % 2019
pow = [1]
while len(pow) <= 1 or pow[-1] > 1:
    pow.append(pow[-1] * 10 % 2019)
n = len(pow) - 1  # 10 ** n == 1 mod 2019
# memo[i % n][m] = (int(s[:i+1]) % 2019 == mであるiの個数)
memo = [[0] * 2019 for i in range(n)]
memo[n - 1][0] = 1  # memo[-1][0] = 1
count = 0  # int(s[i:j+1]) == 0 mod 2019 である(i,j)の個数
mod = 0
for j, c in enumerate(s):
    mod = (mod * 10 + int(c)) % 2019  # mod = int(s[:j+1]) % 2019
    for i in range(1, n + 1):
        m = mod * pow[n - i] % 2019  # m == mod * 10 ** (-i) mod 2019
        count += memo[(j - i + n) % n][m]
    memo[j % n][mod] += 1
print(count)

# D - Multiple of 2019
from collections import Counter

s = eval(input())
count = 0
counter = Counter([0])
suffix = [0] * (len(s) + 1)
pow = 1
for i in range(len(s) - 1, -1, -1):
    suffix[i] = (int(s[i]) * pow + suffix[i + 1]) % 2019
    pow = pow * 10 % 2019
    count += counter[suffix[i]]
    counter[suffix[i]] += 1
print(count)

+from collections import Counter + -# pow[k] = 10 ** k % 2019 -pow = [1] -while len(pow) <= 1 or pow[-1] > 1: -    pow.append(pow[-1] * 10 % 2019) -n = len(pow) - 1  # 10 ** n == 1 mod 2019 -# memo[i % n][m] = (int(s[:i+1]) % 2019 == mであるiの個数) -memo = [[0] * 2019 for i in range(n)] -memo[n - 1][0] = 1  # memo[-1][0] = 1 -count = 0  # int(s[i:j+1]) == 0 mod 2019 である(i,j)の個数 -mod = 0 -for j, c in enumerate(s): -    mod = (mod * 10 + int(c)) % 2019  # mod = int(s[:j+1]) % 2019 -    for i in range(1, n + 1): -        m = mod * pow[n - i] % 2019  # m == mod * 10 ** (-i) mod 2019 -        count += memo[(j - i + n) % n][m] -    memo[j % n][mod] += 1 +count = 0 +counter = Counter([0]) +suffix = [0] * (len(s) + 1) +pow = 1 +for i in range(len(s) - 1, -1, -1): +    suffix[i] = (int(s[i]) * pow + suffix[i + 1]) % 2019 +    pow = pow * 10 % 2019 +    count += counter[suffix[i]] +    counter[suffix[i]] += 1