# https://atcoder.jp/contests/abc164/tasks/abc164_d



from operator import mul

from functools import reduce

from collections import defaultdict



def combination(n, r):

    if not 0 <= r <= n: return 0

    r = min(r, n - r)

    numer = reduce(mul, list(range(n, n - r, -1)), 1)

    denom = reduce(mul, list(range(1, r + 1)), 1)

    return numer // denom



S = eval(input())



res = 0



T = [0]

x = 0

L = len(S)

for i, s in zip(list(range(L)),reversed(S)):

    """ 累積和 """

    x = (int(s)*pow(10,i,2019) + x)%2019

    T.append(x)



reminder = [0]*2019

for i in range(L+1):

    reminder[T[i]%2019] += 1



for c in reminder:

    res += combination(c,2)



print(res)
# https://atcoder.jp/contests/abc164/tasks/abc164_d



import sys

input = sys.stdin.readline





S = input().rstrip()



res = 0



T = [0]

x = 0

p = 1

L = len(S)

MOD = 2019

for i, s in zip(list(range(L)),reversed(S)):

    """ 累積和 """

    x = (int(s)*p + x)%MOD

    p = p*10%MOD

    T.append(x)



reminder = [0]*2019

for i in range(L+1):

    reminder[T[i]%MOD] += 1



for c in reminder:

    res += c*(c-1)//2



print(res)
# https://atcoder.jp/contests/abc164/tasks/abc164_d
from operator import mul
from functools import reduce
from collections import defaultdict


def combination(n, r):
    if not 0 <= r <= n:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, list(range(n, n - r, -1)), 1)
    denom = reduce(mul, list(range(1, r + 1)), 1)
    return numer // denom


S = eval(input())
res = 0
T = [0]
x = 0
L = len(S)
for i, s in zip(list(range(L)), reversed(S)):
    """累積和"""
    x = (int(s) * pow(10, i, 2019) + x) % 2019
    T.append(x)
reminder = [0] * 2019
for i in range(L + 1):
    reminder[T[i] % 2019] += 1
for c in reminder:
    res += combination(c, 2)
print(res)

# https://atcoder.jp/contests/abc164/tasks/abc164_d
import sys

input = sys.stdin.readline
S = input().rstrip()
res = 0
T = [0]
x = 0
p = 1
L = len(S)
MOD = 2019
for i, s in zip(list(range(L)), reversed(S)):
    """累積和"""
    x = (int(s) * p + x) % MOD
    p = p * 10 % MOD
    T.append(x)
reminder = [0] * 2019
for i in range(L + 1):
    reminder[T[i] % MOD] += 1
for c in reminder:
    res += c * (c - 1) // 2
print(res)

-from operator import mul -from functools import reduce -from collections import defaultdict +import sys - -def combination(n, r): -    if not 0 <= r <= n: -        return 0 -    r = min(r, n - r) -    numer = reduce(mul, list(range(n, n - r, -1)), 1) -    denom = reduce(mul, list(range(1, r + 1)), 1) -    return numer // denom - - -S = eval(input()) +input = sys.stdin.readline +S = input().rstrip() +p = 1 +MOD = 2019 -    x = (int(s) * pow(10, i, 2019) + x) % 2019 +    x = (int(s) * p + x) % MOD +    p = p * 10 % MOD -    reminder[T[i] % 2019] += 1 +    reminder[T[i] % MOD] += 1 -    res += combination(c, 2) +    res += c * (c - 1) // 2