import sys

import numba

import numpy as np

S = sys.stdin.buffer.readline().decode('utf-8').rstrip()

S = np.array([int(d) for d in S[::-1]], dtype=np.int32)



@numba.njit(numba.i8(numba.typeof(S)), cache=True)

def solve(S):

	M = 2019

	t = 1

	ans = 0

	c = np.zeros(M, dtype=np.int64)

	c[0] = 1

	r = 0

	for d in S:

		r = (d * t + r) % M

		ans += c[r]

		c[r] += 1

		t = t * 10 % M

	return ans



print((solve(S)))
import sys

import numpy as np



def solve(S):

	M = 2019

	t = 1

	ans = 0

	c = np.zeros(M, dtype=np.int64)

	c[0] = 1

	r = 0

	for d in S:

		r = (d * t + r) % M

		ans += c[r]

		c[r] += 1

		t = t * 10 % M

	return ans







def cc_export():

	from numba.pycc import CC

	cc = CC('my_module')

	cc.export('solve', 'i8(i4[:])')(solve)

	cc.compile()



if __name__ == '__main__':

	import sys

	if sys.argv[-1] == 'ONLINE_JUDGE':

		cc_export()

		exit(0)

	from my_module import solve

	S = sys.stdin.buffer.readline().decode('utf-8').rstrip()

	S = np.array([int(d) for d in S[::-1]], dtype=np.int32)

	print((solve(S)))

import sys
import numba
import numpy as np

S = sys.stdin.buffer.readline().decode("utf-8").rstrip()
S = np.array([int(d) for d in S[::-1]], dtype=np.int32)


@numba.njit(numba.i8(numba.typeof(S)), cache=True)
def solve(S):
    M = 2019
    t = 1
    ans = 0
    c = np.zeros(M, dtype=np.int64)
    c[0] = 1
    r = 0
    for d in S:
        r = (d * t + r) % M
        ans += c[r]
        c[r] += 1
        t = t * 10 % M
    return ans


print((solve(S)))

import sys
import numpy as np


def solve(S):
    M = 2019
    t = 1
    ans = 0
    c = np.zeros(M, dtype=np.int64)
    c[0] = 1
    r = 0
    for d in S:
        r = (d * t + r) % M
        ans += c[r]
        c[r] += 1
        t = t * 10 % M
    return ans


def cc_export():
    from numba.pycc import CC

    cc = CC("my_module")
    cc.export("solve", "i8(i4[:])")(solve)
    cc.compile()


if __name__ == "__main__":
    import sys

    if sys.argv[-1] == "ONLINE_JUDGE":
        cc_export()
        exit(0)
    from my_module import solve

    S = sys.stdin.buffer.readline().decode("utf-8").rstrip()
    S = np.array([int(d) for d in S[::-1]], dtype=np.int32)
    print((solve(S)))

-import numba -S = sys.stdin.buffer.readline().decode("utf-8").rstrip() -S = np.array([int(d) for d in S[::-1]], dtype=np.int32) - -@numba.njit(numba.i8(numba.typeof(S)), cache=True) -print((solve(S))) +def cc_export(): +    from numba.pycc import CC + +    cc = CC("my_module") +    cc.export("solve", "i8(i4[:])")(solve) +    cc.compile() + + +if __name__ == "__main__": +    import sys + +    if sys.argv[-1] == "ONLINE_JUDGE": +        cc_export() +        exit(0) +    from my_module import solve + +    S = sys.stdin.buffer.readline().decode("utf-8").rstrip() +    S = np.array([int(d) for d in S[::-1]], dtype=np.int32) +    print((solve(S)))