import sys

input = lambda : sys.stdin.readline().rstrip()



import collections

s = [int(c) for c in eval(input())]

tmp = 1

mod = 0

count = collections.defaultdict(int)

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

    mod = (tmp * num + mod) % 2019

    count[mod] += 1

    tmp *= 10

    tmp %= 2019

count[0] += 1

print((sum((item*(item-1)//2 for item in list(count.values())))))
import sys

input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(max(1000, 10**9))

write = lambda x: sys.stdout.write(x+"\n")





s = eval(input())

n = len(s)

a = [None]*n

c = 0

v = 1

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

    c = (c + v*int(s[i])) % 2019

    a[i] = c

    v *= 10

    v %= 2019

from collections import Counter

cc = Counter(a)

ans = 0

for k,v in list(cc.items()):

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

ans += cc[0]

print(ans)
import sys

input = lambda: sys.stdin.readline().rstrip()
import collections

s = [int(c) for c in eval(input())]
tmp = 1
mod = 0
count = collections.defaultdict(int)
for i, num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
    tmp %= 2019
count[0] += 1
print((sum((item * (item - 1) // 2 for item in list(count.values())))))

import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
s = eval(input())
n = len(s)
a = [None] * n
c = 0
v = 1
for i in range(n - 1, -1, -1):
    c = (c + v * int(s[i])) % 2019
    a[i] = c
    v *= 10
    v %= 2019
from collections import Counter

cc = Counter(a)
ans = 0
for k, v in list(cc.items()):
    ans += v * (v - 1) // 2
ans += cc[0]
print(ans)

-import collections +sys.setrecursionlimit(max(1000, 10**9)) +write = lambda x: sys.stdout.write(x + "\n") +s = eval(input()) +n = len(s) +a = [None] * n +c = 0 +v = 1 +for i in range(n - 1, -1, -1): +    c = (c + v * int(s[i])) % 2019 +    a[i] = c +    v *= 10 +    v %= 2019 +from collections import Counter -s = [int(c) for c in eval(input())] -tmp = 1 -mod = 0 -count = collections.defaultdict(int) -for i, num in enumerate(s[::-1]): -    mod = (tmp * num + mod) % 2019 -    count[mod] += 1 -    tmp *= 10 -    tmp %= 2019 -count[0] += 1 -print((sum((item * (item - 1) // 2 for item in list(count.values()))))) +cc = Counter(a) +ans = 0 +for k, v in list(cc.items()): +    ans += v * (v - 1) // 2 +ans += cc[0] +print(ans)