a,*d=[0]*2020

for i in map(int,eval(input())):

  p=[0]*2019

  for j in range(2019):p[(j*10+i)%2019]+=d[j]

  d=p

  d[i]+=1

  a+=d[0]

print(a)
from numba import njit

from numpy import int32,zeros,arange

@njit('i4(i4[:])')

def solve(s):

    a=0

    d=zeros(2019,int32)

    for i in s:

        p=zeros(2019,int32)

        for j in range(2019):p[(j*10+i)%2019]+=d[j]

        d=p

        d[i]+=1

        a+=d[0]

    return a

print((solve(int32([*eval(input())]))))
a, *d = [0] * 2020
for i in map(int, eval(input())):
    p = [0] * 2019
    for j in range(2019):
        p[(j * 10 + i) % 2019] += d[j]
    d = p
    d[i] += 1
    a += d[0]
print(a)

from numba import njit
from numpy import int32, zeros, arange


@njit("i4(i4[:])")
def solve(s):
    a = 0
    d = zeros(2019, int32)
    for i in s:
        p = zeros(2019, int32)
        for j in range(2019):
            p[(j * 10 + i) % 2019] += d[j]
        d = p
        d[i] += 1
        a += d[0]
    return a


print((solve(int32([*eval(input())]))))

-a, *d = [0] * 2020 -for i in map(int, eval(input())): -    p = [0] * 2019 -    for j in range(2019): -        p[(j * 10 + i) % 2019] += d[j] -    d = p -    d[i] += 1 -    a += d[0] -print(a) +from numba import njit +from numpy import int32, zeros, arange + + +@njit("i4(i4[:])") +def solve(s): +    a = 0 +    d = zeros(2019, int32) +    for i in s: +        p = zeros(2019, int32) +        for j in range(2019): +            p[(j * 10 + i) % 2019] += d[j] +        d = p +        d[i] += 1 +        a += d[0] +    return a + + +print((solve(int32([*eval(input())]))))