S=eval(input())

N=len(S)

M=2019



remainder=[0]*M

val=0

for i in range(N):

  val=(int(S[N-1-i])*pow(10,i,M)+val)%M

  remainder[val]+=1



ans=remainder[0]

for i in range(2019):

  ans+=remainder[i]*(remainder[i]-1)//2

print(ans)

def solve():

    s = eval(input())

    n = len(s)

    mod = 2019



    reminder = [0]*mod

    pre_rem = 0



    for i in range(n):

        pre_rem = (int(s[n-i-1])*pow(10, i, mod) + pre_rem) % mod

        reminder[pre_rem] += 1



    ans = reminder[0]

    for rem_num in reminder:

        if rem_num >= 2:

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

    print(ans)

    

solve()
S = eval(input())
N = len(S)
M = 2019
remainder = [0] * M
val = 0
for i in range(N):
    val = (int(S[N - 1 - i]) * pow(10, i, M) + val) % M
    remainder[val] += 1
ans = remainder[0]
for i in range(2019):
    ans += remainder[i] * (remainder[i] - 1) // 2
print(ans)

def solve():
    s = eval(input())
    n = len(s)
    mod = 2019
    reminder = [0] * mod
    pre_rem = 0
    for i in range(n):
        pre_rem = (int(s[n - i - 1]) * pow(10, i, mod) + pre_rem) % mod
        reminder[pre_rem] += 1
    ans = reminder[0]
    for rem_num in reminder:
        if rem_num >= 2:
            ans += (rem_num * (rem_num - 1)) // 2
    print(ans)


solve()

-S = eval(input()) -N = len(S) -M = 2019 -remainder = [0] * M -val = 0 -for i in range(N): -    val = (int(S[N - 1 - i]) * pow(10, i, M) + val) % M -    remainder[val] += 1 -ans = remainder[0] -for i in range(2019): -    ans += remainder[i] * (remainder[i] - 1) // 2 -print(ans) +def solve(): +    s = eval(input()) +    n = len(s) +    mod = 2019 +    reminder = [0] * mod +    pre_rem = 0 +    for i in range(n): +        pre_rem = (int(s[n - i - 1]) * pow(10, i, mod) + pre_rem) % mod +        reminder[pre_rem] += 1 +    ans = reminder[0] +    for rem_num in reminder: +        if rem_num >= 2: +            ans += (rem_num * (rem_num - 1)) // 2 +    print(ans) + + +solve()