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)
from collections import deque

s = deque(eval(input()))

n = len(s)



temp = [0]*2019

t = 1

num = 0

for i in range(n):

    num += int(s.pop())*t 

    temp[num % 2019] += 1

    t = t*10 % 2019 



ans = temp[0]

for t in temp:

    if t > 1:

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



print((int(ans)))
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)

from collections import deque

s = deque(eval(input()))
n = len(s)
temp = [0] * 2019
t = 1
num = 0
for i in range(n):
    num += int(s.pop()) * t
    temp[num % 2019] += 1
    t = t * 10 % 2019
ans = temp[0]
for t in temp:
    if t > 1:
        ans += t * (t - 1) / 2
print((int(ans)))

-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) +from collections import deque + +s = deque(eval(input())) +n = len(s) +temp = [0] * 2019 +t = 1 +num = 0 +for i in range(n): +    num += int(s.pop()) * t +    temp[num % 2019] += 1 +    t = t * 10 % 2019 +ans = temp[0] +for t in temp: +    if t > 1: +        ans += t * (t - 1) / 2 +print((int(ans)))