S=eval(input())

a=0

b=[0]*2019

No=[None]*2019

for i in S:

    l=No.copy()

    k=int(i)

    for j in range(2019):

        l[(j*10+k)%2019]=b[j]

    l[k]+=1

    a+=l[0]

    b=l

print(a)

def main():

    S=eval(input())

    a=0 

    b=[0]*2019

    No=[0]*2019

    for i in S:

        l=No.copy()

        k=int(i)

        for j in range(2019):

            l[(j*10+k)%2019]=b[j]

        l[k]+=1

        a+=l[0]

        b=l

    print(a)

main()
S = eval(input())
a = 0
b = [0] * 2019
No = [None] * 2019
for i in S:
    l = No.copy()
    k = int(i)
    for j in range(2019):
        l[(j * 10 + k) % 2019] = b[j]
    l[k] += 1
    a += l[0]
    b = l
print(a)

def main():
    S = eval(input())
    a = 0
    b = [0] * 2019
    No = [0] * 2019
    for i in S:
        l = No.copy()
        k = int(i)
        for j in range(2019):
            l[(j * 10 + k) % 2019] = b[j]
        l[k] += 1
        a += l[0]
        b = l
    print(a)


main()

-S = eval(input()) -a = 0 -b = [0] * 2019 -No = [None] * 2019 -for i in S: -    l = No.copy() -    k = int(i) -    for j in range(2019): -        l[(j * 10 + k) % 2019] = b[j] -    l[k] += 1 -    a += l[0] -    b = l -print(a) +def main(): +    S = eval(input()) +    a = 0 +    b = [0] * 2019 +    No = [0] * 2019 +    for i in S: +        l = No.copy() +        k = int(i) +        for j in range(2019): +            l[(j * 10 + k) % 2019] = b[j] +        l[k] += 1 +        a += l[0] +        b = l +    print(a) + + +main()