from heapq import heappush, heappop, heapify

from collections import deque, defaultdict, Counter

import itertools

from itertools import permutations, combinations, accumulate, product

import sys

import bisect

import string

import math

import time





def I(): return int(input())





def S(): return input()





def MI(): return map(int, input().split())





def MS(): return map(str, input().split())





def LI(): return [int(i) for i in input().split()]





def LI_(): return [int(i)-1 for i in input().split()]





def StoI(): return [ord(i)-97 for i in input()]





def ItoS(nn): return chr(nn+97)





def input(): return sys.stdin.readline().rstrip()





def debug(table, *args):

    ret = []

    for name, val in table.items():

        if val in args:

            ret.append('{}: {}'.format(name, val))

    print(' | '.join(ret), file=sys.stderr)





yn = {False: 'No', True: 'Yes'}

YN = {False: 'NO', True: 'YES'}

MOD = 10**9+7

inf = float('inf')

IINF = 10**10

l_alp = string.ascii_lowercase

u_alp = string.ascii_uppercase

ts = time.time()

sys.setrecursionlimit(10**6)

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']



show_flg = False

# show_flg = True



import random



def main():

    s = list(map(int, S()[::-1]))

    N = len(s)

    P = 2019

    ans = 0

    cnts = [0] * P

    cnts[0] = 1

    A = [0] * N

    D = [0] * N



    for i in range(N):

        d = s[i] * pow(10, i, P)

        A[i] = d % P

        if i == 0:

            D[i] = A[i]

        else:

            D[i] = (D[i-1] + A[i]) % P

        # sum_of_d = (sum_of_d + d) % p

        # cnts[sum_of_d] += 1



    for d in D:

        cnts[d] += 1



    for i in cnts:

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



    print(ans)





if __name__ == '__main__':

    main()

from heapq import heappush, heappop, heapify

from collections import deque, defaultdict, Counter

import itertools

from itertools import permutations, combinations, accumulate, product, combinations_with_replacement

import sys

import bisect

import string

import math

import time



def I(): return int(eval(input()))

def S(): return eval(input())

def MI(): return list(map(int, input().split()))

def MS(): return list(map(str, input().split()))

def LI(): return [int(i) for i in input().split()]

def LI_(): return [int(i)-1 for i in input().split()]

def StoI(): return [ord(i)-97 for i in eval(input())]

def ItoS(nn): return chr(nn+97)

def input(): return sys.stdin.readline().rstrip()

def list2d(a, b, c): return [[c] * b for i in range(a)]

def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def print_matrix(mat):

    for i in range(len(mat)):

        print((*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]]))





yn = {False: 'No', True: 'Yes'}

YN = {False: 'NO', True: 'YES'}

MOD = 10**9+7

inf = float('inf')

IINF = 10**19

l_alp = string.ascii_lowercase

u_alp = string.ascii_uppercase

ts = time.time()

sys.setrecursionlimit(10**6)

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']



show_flg = False

# show_flg = True





yn = {False: 'No', True: 'Yes'}

YN = {False: 'NO', True: 'YES'}

MOD = 10**9+7

inf = float('inf')

IINF = 10**19

l_alp = string.ascii_lowercase

u_alp = string.ascii_uppercase

ts = time.time()

sys.setrecursionlimit(10**6)

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']



show_flg = False

# show_flg = True



# https://algo-logic.info/abc158e/

def main():

    s = list(map(int, S()[::-1]))

    N = len(s)

    P = 2019

    cnts = [0] * P

    cnts[0] = 1

    sum_of_digits = 0



    for i in range(N):

        sum_of_digits += s[i] * pow(10, i, P)

        sum_of_digits %= 2019

        cnts[sum_of_digits] += 1



    ans = 0

    for i in range(P):

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

    print(ans)





if __name__ == '__main__':

    main()

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I():
    return int(input())


def S():
    return input()


def MI():
    return map(int, input().split())


def MS():
    return map(str, input().split())


def LI():
    return [int(i) for i in input().split()]


def LI_():
    return [int(i) - 1 for i in input().split()]


def StoI():
    return [ord(i) - 97 for i in input()]


def ItoS(nn):
    return chr(nn + 97)


def input():
    return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append("{}: {}".format(name, val))
    print(" | ".join(ret), file=sys.stderr)


yn = {False: "No", True: "Yes"}
YN = {False: "NO", True: "YES"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = False
# show_flg = True
import random


def main():
    s = list(map(int, S()[::-1]))
    N = len(s)
    P = 2019
    ans = 0
    cnts = [0] * P
    cnts[0] = 1
    A = [0] * N
    D = [0] * N
    for i in range(N):
        d = s[i] * pow(10, i, P)
        A[i] = d % P
        if i == 0:
            D[i] = A[i]
        else:
            D[i] = (D[i - 1] + A[i]) % P
        # sum_of_d = (sum_of_d + d) % p
        # cnts[sum_of_d] += 1
    for d in D:
        cnts[d] += 1
    for i in cnts:
        ans += i * (i - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import (
    permutations,
    combinations,
    accumulate,
    product,
    combinations_with_replacement,
)
import sys
import bisect
import string
import math
import time


def I():
    return int(eval(input()))


def S():
    return eval(input())


def MI():
    return list(map(int, input().split()))


def MS():
    return list(map(str, input().split()))


def LI():
    return [int(i) for i in input().split()]


def LI_():
    return [int(i) - 1 for i in input().split()]


def StoI():
    return [ord(i) - 97 for i in eval(input())]


def ItoS(nn):
    return chr(nn + 97)


def input():
    return sys.stdin.readline().rstrip()


def list2d(a, b, c):
    return [[c] * b for i in range(a)]


def list3d(a, b, c, d):
    return [[[d] * c for j in range(b)] for i in range(a)]


def list4d(a, b, c, d, e):
    return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]


def print_matrix(mat):
    for i in range(len(mat)):
        print((*["IINF" if v == IINF else "{:0=4}".format(v) for v in mat[i]]))


yn = {False: "No", True: "Yes"}
YN = {False: "NO", True: "YES"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = False
# show_flg = True
yn = {False: "No", True: "Yes"}
YN = {False: "NO", True: "YES"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = False
# show_flg = True
# https://algo-logic.info/abc158e/
def main():
    s = list(map(int, S()[::-1]))
    N = len(s)
    P = 2019
    cnts = [0] * P
    cnts[0] = 1
    sum_of_digits = 0
    for i in range(N):
        sum_of_digits += s[i] * pow(10, i, P)
        sum_of_digits %= 2019
        cnts[sum_of_digits] += 1
    ans = 0
    for i in range(P):
        ans += cnts[i] * (cnts[i] - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

-from itertools import permutations, combinations, accumulate, product +from itertools import ( +    permutations, +    combinations, +    accumulate, +    product, +    combinations_with_replacement, +) -    return int(input()) +    return int(eval(input())) -    return input() +    return eval(input()) -    return map(int, input().split()) +    return list(map(int, input().split())) -    return map(str, input().split()) +    return list(map(str, input().split())) -    return [ord(i) - 97 for i in input()] +    return [ord(i) - 97 for i in eval(input())] -def debug(table, *args): -    ret = [] -    for name, val in table.items(): -        if val in args: -            ret.append("{}: {}".format(name, val)) -    print(" | ".join(ret), file=sys.stderr) +def list2d(a, b, c): +    return [[c] * b for i in range(a)] + + +def list3d(a, b, c, d): +    return [[[d] * c for j in range(b)] for i in range(a)] + + +def list4d(a, b, c, d, e): +    return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] + + +def print_matrix(mat): +    for i in range(len(mat)): +        print((*["IINF" if v == IINF else "{:0=4}".format(v) for v in mat[i]])) -IINF = 10**10 +IINF = 10**19 -import random - - +yn = {False: "No", True: "Yes"} +YN = {False: "NO", True: "YES"} +MOD = 10**9 + 7 +inf = float("inf") +IINF = 10**19 +l_alp = string.ascii_lowercase +u_alp = string.ascii_uppercase +ts = time.time() +sys.setrecursionlimit(10**6) +nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] +show_flg = False +# show_flg = True +# https://algo-logic.info/abc158e/ -    ans = 0 -    A = [0] * N -    D = [0] * N +    sum_of_digits = 0 -        d = s[i] * pow(10, i, P) -        A[i] = d % P -        if i == 0: -            D[i] = A[i] -        else: -            D[i] = (D[i - 1] + A[i]) % P -        # sum_of_d = (sum_of_d + d) % p -        # cnts[sum_of_d] += 1 -    for d in D: -        cnts[d] += 1 -    for i in cnts: -        ans += i * (i - 1) // 2 +        sum_of_digits += s[i] * pow(10, i, P) +        sum_of_digits %= 2019 +        cnts[sum_of_digits] += 1 +    ans = 0 +    for i in range(P): +        ans += cnts[i] * (cnts[i] - 1) // 2