from collections import Counter

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines



def main():

    S = readline().strip()[::-1]

    N = len(S)



    a = [0]

    s = 0

    for i in range(N):

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

        a.append(s % 2019)

    

    t = Counter(a)



    ans = 0

    for _, v in list(t.items()):

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

    

    print(ans)

    



if __name__ == "__main__":

    main()

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines



def main():

    S = [int(i) for i in readline().strip()[::-1]]



    a = {}

    a[0] = 1

    t = 0

    x = 1

    for s in S:

        t += s * x

        t %= 2019

        

        if t in a:

            a[t] += 1

        else:

            a[t] = 1



        x *= 10

        x %= 2019

    

    ans = 0

    for v in list(a.values()):

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

    

    print(ans)

    



if __name__ == "__main__":

    main()

from collections import Counter
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    S = readline().strip()[::-1]
    N = len(S)
    a = [0]
    s = 0
    for i in range(N):
        s += int(S[i]) * pow(10, i, 2019)
        a.append(s % 2019)
    t = Counter(a)
    ans = 0
    for _, v in list(t.items()):
        ans += v * (v - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    S = [int(i) for i in readline().strip()[::-1]]
    a = {}
    a[0] = 1
    t = 0
    x = 1
    for s in S:
        t += s * x
        t %= 2019
        if t in a:
            a[t] += 1
        else:
            a[t] = 1
        x *= 10
        x %= 2019
    ans = 0
    for v in list(a.values()):
        ans += v * (v - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

-from collections import Counter -    S = readline().strip()[::-1] -    N = len(S) -    a = [0] -    s = 0 -    for i in range(N): -        s += int(S[i]) * pow(10, i, 2019) -        a.append(s % 2019) -    t = Counter(a) +    S = [int(i) for i in readline().strip()[::-1]] +    a = {} +    a[0] = 1 +    t = 0 +    x = 1 +    for s in S: +        t += s * x +        t %= 2019 +        if t in a: +            a[t] += 1 +        else: +            a[t] = 1 +        x *= 10 +        x %= 2019 -    for _, v in list(t.items()): +    for v in list(a.values()):