import sys, math

from pprint import pprint

input = sys.stdin.readline

rs = lambda: input().strip()

ri = lambda: int(eval(input()))

rl = lambda: list(map(int, input().split()))

mod = 10**9 + 7



S = rs()



mods = []

n = 0

e = 1

for i in reversed(list(range(len(S)))):

	n += int(S[i]) * e

	e = (e*10) % 2019

	n = n % 2019

	mods.append(n)

mods.append(0)

import collections

cnt = collections.Counter(mods)

ans = 0

for k, c in list(cnt.items()):

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

print(ans)

import sys, math

from pprint import pprint

input = sys.stdin.readline

rs = lambda: input().strip()

ri = lambda: int(eval(input()))

rl = lambda: list(map(int, input().split()))

mod = 10**9 + 7



S = rs()

#S = '1'*200000



mods = []

n = 0

e = 0

for i in reversed(list(range(len(S)))):

	n += int(S[i]) * pow(10,e,2019)

	#e = (e*10) % 2019

	e += 1

	#n = n % 2019

	mods.append(n % 2019)

mods.append(0)

import collections

cnt = collections.Counter(mods)

ans = 0

for k, c in list(cnt.items()):

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

print(ans)

import sys, math
from pprint import pprint

input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
S = rs()
mods = []
n = 0
e = 1
for i in reversed(list(range(len(S)))):
    n += int(S[i]) * e
    e = (e * 10) % 2019
    n = n % 2019
    mods.append(n)
mods.append(0)
import collections

cnt = collections.Counter(mods)
ans = 0
for k, c in list(cnt.items()):
    ans += c * (c - 1) // 2
print(ans)

import sys, math
from pprint import pprint

input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(eval(input()))
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7
S = rs()
# S = '1'*200000
mods = []
n = 0
e = 0
for i in reversed(list(range(len(S)))):
    n += int(S[i]) * pow(10, e, 2019)
    # e = (e*10) % 2019
    e += 1
    # n = n % 2019
    mods.append(n % 2019)
mods.append(0)
import collections

cnt = collections.Counter(mods)
ans = 0
for k, c in list(cnt.items()):
    ans += c * (c - 1) // 2
print(ans)

+# S = '1'*200000 -e = 1 +e = 0 -    n += int(S[i]) * e -    e = (e * 10) % 2019 -    n = n % 2019 -    mods.append(n) +    n += int(S[i]) * pow(10, e, 2019) +    # e = (e*10) % 2019 +    e += 1 +    # n = n % 2019 +    mods.append(n % 2019)