f=[0]*22209

def main():

    a=list(map(int,eval(input())))

    n=len(a)

    ans=0

    d=[0]*2019

    d2=[0]*2019

    d2[a[0]]+=1

    for i in range(11):

        for j in range(2019):

            f[2019*i+j]=j

    for i in range(1,n):

        d[a[i]]+=1

        for j in range(2019):

            d[f[10*j+a[i]]]+=d2[j]

        ans+=d[0]

        for j in range(2019):

            d2[j]=d[j]

            d[j]=0

    print(ans)

main()
"""

s=1817181712114 なら

4

10

100

2000

10000

700000

1000000

80000000

100000000

7000000000

10000000000

800000000000

1000000000000

の数列とみて, 各々%2019を取ってzero sum range

"""

from collections import Counter

def make_modlist(Len,mod):

    modlist=[0]*Len

    modlist[0]=1

    for i in range(1,Len):

        modlist[i]=10*modlist[i-1]%mod

    return modlist

a=list(map(int,eval(input())))

a.reverse()

n=len(a)

d=make_modlist(n,2019)

b=[0]*(n+1)

for i in range(n):

    b[i+1]=a[i]*d[i]%2019

for i in range(1,n+1):

    b[i]+=b[i-1]

    b[i]%=2019

ans=0

for i in list(Counter(b).values()):

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

print(ans)
f = [0] * 22209


def main():
    a = list(map(int, eval(input())))
    n = len(a)
    ans = 0
    d = [0] * 2019
    d2 = [0] * 2019
    d2[a[0]] += 1
    for i in range(11):
        for j in range(2019):
            f[2019 * i + j] = j
    for i in range(1, n):
        d[a[i]] += 1
        for j in range(2019):
            d[f[10 * j + a[i]]] += d2[j]
        ans += d[0]
        for j in range(2019):
            d2[j] = d[j]
            d[j] = 0
    print(ans)


main()

"""
s=1817181712114 なら
4
10
100
2000
10000
700000
1000000
80000000
100000000
7000000000
10000000000
800000000000
1000000000000
の数列とみて, 各々%2019を取ってzero sum range
"""
from collections import Counter


def make_modlist(Len, mod):
    modlist = [0] * Len
    modlist[0] = 1
    for i in range(1, Len):
        modlist[i] = 10 * modlist[i - 1] % mod
    return modlist


a = list(map(int, eval(input())))
a.reverse()
n = len(a)
d = make_modlist(n, 2019)
b = [0] * (n + 1)
for i in range(n):
    b[i + 1] = a[i] * d[i] % 2019
for i in range(1, n + 1):
    b[i] += b[i - 1]
    b[i] %= 2019
ans = 0
for i in list(Counter(b).values()):
    ans += i * (i - 1) // 2
print(ans)

-f = [0] * 22209 +""" +s=1817181712114 なら +4 +10 +100 +2000 +10000 +700000 +1000000 +80000000 +100000000 +7000000000 +10000000000 +800000000000 +1000000000000 +の数列とみて, 各々%2019を取ってzero sum range +""" +from collections import Counter -def main(): -    a = list(map(int, eval(input()))) -    n = len(a) -    ans = 0 -    d = [0] * 2019 -    d2 = [0] * 2019 -    d2[a[0]] += 1 -    for i in range(11): -        for j in range(2019): -            f[2019 * i + j] = j -    for i in range(1, n): -        d[a[i]] += 1 -        for j in range(2019): -            d[f[10 * j + a[i]]] += d2[j] -        ans += d[0] -        for j in range(2019): -            d2[j] = d[j] -            d[j] = 0 -    print(ans) +def make_modlist(Len, mod): +    modlist = [0] * Len +    modlist[0] = 1 +    for i in range(1, Len): +        modlist[i] = 10 * modlist[i - 1] % mod +    return modlist -main() +a = list(map(int, eval(input()))) +a.reverse() +n = len(a) +d = make_modlist(n, 2019) +b = [0] * (n + 1) +for i in range(n): +    b[i + 1] = a[i] * d[i] % 2019 +for i in range(1, n + 1): +    b[i] += b[i - 1] +    b[i] %= 2019 +ans = 0 +for i in list(Counter(b).values()): +    ans += i * (i - 1) // 2 +print(ans)