from operator import mul

from functools import reduce

import numpy as np

#def ConZ(i):

    #z_num = i+int(i*(i-1)/2)

    #return z_num

#def ConN(i):

    #n_num = int(i*(i-1)/2)

    #return n_num



def cmb(n):

    over = reduce(mul, list(range(n, n - 2, -1)))

    under = reduce(mul, list(range(1,2 + 1)))

    return over // under





S = input()[::-1]

keta = 1

A_num = 0

x = 0

mod = np.array([0]*2019)

mod[0] += 1

for i in range(len(S)):

    A_num += int(S[i:i+1])*keta

    if A_num >= 2019:

        A_num = A_num%2019

    mod[A_num] +=1

    #keta*=10

    keta = keta * 10 % 2019

#print(mod)

#x += ConZ(mod[0])

#del mod[0]



#for j in range(len(mod)):

    #x+=cmb(mod[j])

#print(x)

print((int(np.sum(mod* (mod - 1) /2))))

from operator import mul

from functools import reduce

import numpy as np

def ConZ(i):

    z_num = i+int(i*(i-1)/2)

    return z_num

#def ConN(i):

    #n_num = int(i*(i-1)/2)

    #return n_num

def cmb(n):

    over = reduce(mul, list(range(n, n - 2, -1)))

    under = reduce(mul, list(range(1,2 + 1)))

    return over // under





S = input()[::-1]

keta = 1

A_num = 0

x = 0

mod = np.array([0]*2019)

for i in range(len(S)):

    A_num += int(S[i:i+1])*keta

    if A_num >= 2019:

        A_num = A_num%2019

    mod[A_num] +=1

    #keta*=10

    keta = keta * 10 % 2019

#print(mod)

x += ConZ(mod[0])

#del mod[0]



for j in range(1,len(mod)):

    x+=cmb(mod[j])

print(x)

#print(int(np.sum(mod* (mod - 1) /2)))

from operator import mul
from functools import reduce
import numpy as np

# def ConZ(i):
# z_num = i+int(i*(i-1)/2)
# return z_num
# def ConN(i):
# n_num = int(i*(i-1)/2)
# return n_num
def cmb(n):
    over = reduce(mul, list(range(n, n - 2, -1)))
    under = reduce(mul, list(range(1, 2 + 1)))
    return over // under


S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = np.array([0] * 2019)
mod[0] += 1
for i in range(len(S)):
    A_num += int(S[i : i + 1]) * keta
    if A_num >= 2019:
        A_num = A_num % 2019
    mod[A_num] += 1
    # keta*=10
    keta = keta * 10 % 2019
# print(mod)
# x += ConZ(mod[0])
# del mod[0]
# for j in range(len(mod)):
# x+=cmb(mod[j])
# print(x)
print((int(np.sum(mod * (mod - 1) / 2))))

from operator import mul
from functools import reduce
import numpy as np


def ConZ(i):
    z_num = i + int(i * (i - 1) / 2)
    return z_num


# def ConN(i):
# n_num = int(i*(i-1)/2)
# return n_num
def cmb(n):
    over = reduce(mul, list(range(n, n - 2, -1)))
    under = reduce(mul, list(range(1, 2 + 1)))
    return over // under


S = input()[::-1]
keta = 1
A_num = 0
x = 0
mod = np.array([0] * 2019)
for i in range(len(S)):
    A_num += int(S[i : i + 1]) * keta
    if A_num >= 2019:
        A_num = A_num % 2019
    mod[A_num] += 1
    # keta*=10
    keta = keta * 10 % 2019
# print(mod)
x += ConZ(mod[0])
# del mod[0]
for j in range(1, len(mod)):
    x += cmb(mod[j])
print(x)
# print(int(np.sum(mod* (mod - 1) /2)))

-# def ConZ(i): -# z_num = i+int(i*(i-1)/2) -# return z_num + +def ConZ(i): +    z_num = i + int(i * (i - 1) / 2) +    return z_num + + -mod[0] += 1 -# x += ConZ(mod[0]) +x += ConZ(mod[0]) -# for j in range(len(mod)): -# x+=cmb(mod[j]) -# print(x) -print((int(np.sum(mod * (mod - 1) / 2)))) +for j in range(1, len(mod)): +    x += cmb(mod[j]) +print(x) +# print(int(np.sum(mod* (mod - 1) /2)))