import sys



input = sys.stdin.readline

P = 2019





def main():

    S = input().rstrip()



    N = len(S)

    count = [0] * P

    count[0] += 1

    T = 0

    for i in range(N):

        T = (T + int(S[(N - 1) - i]) * pow(10, i, mod=P)) % P

        count[T] += 1



    ans = 0

    for k in count:

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

    print(ans)





if __name__ == "__main__":

    main()

import sys



input = sys.stdin.readline

P = 2019





def main():

    S = input().rstrip()



    count = [0] * P

    count[0] += 1

    T = 0

    d = 1

    for s in reversed(S):

        T = (T + int(s) * d) % P

        count[T] += 1

        d = (d * 10) % P



    ans = 0

    for k in count:

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

    print(ans)





if __name__ == "__main__":

    main()

import sys

input = sys.stdin.readline
P = 2019


def main():
    S = input().rstrip()
    N = len(S)
    count = [0] * P
    count[0] += 1
    T = 0
    for i in range(N):
        T = (T + int(S[(N - 1) - i]) * pow(10, i, mod=P)) % P
        count[T] += 1
    ans = 0
    for k in count:
        ans = ans + k * (k - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
P = 2019


def main():
    S = input().rstrip()
    count = [0] * P
    count[0] += 1
    T = 0
    d = 1
    for s in reversed(S):
        T = (T + int(s) * d) % P
        count[T] += 1
        d = (d * 10) % P
    ans = 0
    for k in count:
        ans += k * (k - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

-    N = len(S) -    for i in range(N): -        T = (T + int(S[(N - 1) - i]) * pow(10, i, mod=P)) % P +    d = 1 +    for s in reversed(S): +        T = (T + int(s) * d) % P +        d = (d * 10) % P -        ans = ans + k * (k - 1) // 2 +        ans += k * (k - 1) // 2