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

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
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
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 +# import sys - -def input(): -    return sys.stdin.readline()[:-1] - - +# def input(): +#    return sys.stdin.readline()[:-1]