#import sys

from collections import deque

#def input():

#    return sys.stdin.readline()[:-1]



S = deque(list(map(int, list(eval(input())))))

num = 0

dict = {}

dict[0] = 1

ans = 0



for i in range(len(S)):

    num += S.pop() * pow(10,i,2019)

    cand = num % 2019

    if cand in list(dict.keys()):

        dict[cand] += 1

    else:

        dict[cand] = 1



for key in list(dict.keys()):

    ans += dict[key] * (dict[key] - 1) // 2

print(ans)

import sys

def input():

    return sys.stdin.readline()[:-1]



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

num = 0

dict = {}

dict[0] = 1

ans = 0



for i , n in enumerate(S[::-1]):

    num += n * pow(10,i,2019)

    cand = num % 2019

    if cand in list(dict.keys()):

        dict[cand] += 1

    else:

        dict[cand] = 1



for key in list(dict.keys()):

    ans += dict[key] * (dict[key] - 1) // 2

print(ans)

# import sys
from collections import deque

# def input():
#    return sys.stdin.readline()[:-1]
S = deque(list(map(int, list(eval(input())))))
num = 0
dict = {}
dict[0] = 1
ans = 0
for i in range(len(S)):
    num += S.pop() * pow(10, i, 2019)
    cand = num % 2019
    if cand in list(dict.keys()):
        dict[cand] += 1
    else:
        dict[cand] = 1
for key in list(dict.keys()):
    ans += dict[key] * (dict[key] - 1) // 2
print(ans)

import sys


def input():
    return sys.stdin.readline()[:-1]


S = list(map(int, list(eval(input()))))
num = 0
dict = {}
dict[0] = 1
ans = 0
for i, n in enumerate(S[::-1]):
    num += n * pow(10, i, 2019)
    cand = num % 2019
    if cand in list(dict.keys()):
        dict[cand] += 1
    else:
        dict[cand] = 1
for key in list(dict.keys()):
    ans += dict[key] * (dict[key] - 1) // 2
print(ans)

-# import sys -from collections import deque +import sys -# def input(): -#    return sys.stdin.readline()[:-1] -S = deque(list(map(int, list(eval(input()))))) + +def input(): +    return sys.stdin.readline()[:-1] + + +S = list(map(int, list(eval(input())))) -for i in range(len(S)): -    num += S.pop() * pow(10, i, 2019) +for i, n in enumerate(S[::-1]): +    num += n * pow(10, i, 2019)